Commands - Review Flashcards
Search which subdirectories are in a directory that match a word.
Linux
ls -la /locationtosearch | grep wordtomatch
Find files with a specific word.
Linux
grep -rw /home/user/Downloads -e “vacation”
How do you search for a word in multiple files
L
grep study *_notes.txt
grep fruit *.txt (search for fruit in a group of text files)
grep fruit apple.txt banana.txt orange.txt
How do you search for a word in a file. L
grep oranges fruit.txt
To create a new file with default permissions L
touch test_file.txt
How do you create/modify a text file using the popular text editor that can be found on nearly all Linux distributions?
nano my_file
Can create and modify a text file in the command line
To make a text file in Linux with a redirector
cat > (name of file)
ENTER key, then type text, then save file with CTRL + D
Find files with a specific word L
grep -rw /home/user/Downloads -e “vacation”
**having issues with this one, it won’t find my “file” files in a subdirectory
What’s the main way I should use to search for which subdirectories or files match a word? L
ls -la /locationtosearch | grep wordtomatch
L: options available for a command
(command) –help
extra information about commands - manual pages
Linux
man (command)
long list format (something is too long, make it readable and organized with this command, more detail)
Linux
-l
show all files in a directory and hidden files flag
Linux
-a
hide a file or directory
Linux
.(in front of file or directory)
current directory
pwd
change directory 3 ways
cd
cd ..
cd ~
make a new directory
mkdir
copy a file/directory 3 ways
cp filename.ext location
pattern copies: cp *.png ~/Desktop
directory copies (inside contents): cp -r ‘Cat Pictures’ ~/Desktop
moving a file
mv filename.txt locationtomoveto
to make a text file with a redirector and enter text right away
cat > (name of file)
ENTER, type text, save with CTRL +D
view text files 2 ways
l/w
cat
less
-g
-G
-/word_search
-q
more (windows)
flags/parameters that can be used with cat when to view certain lines? 2
-Head Line#
-Tail Line#
modifying text file (create a new one with nano) and enter text right away
nano my_file
how do you search for a word in one file?
linux
grep word filename.ext
how do you search for a word in multiple files? 3 ways
linux
grep word *_filename.extension
grep word *.extension
grep word filename filename filename
How do you filter the standard error output into a linux black hole?
shows just the output, no errors
/dev/null
less /var/log/syslog 2> /dev/null
search which subdirectories are in a directory that match a word
la -la /directorytosearch | grep wordtomatch
command line and shortcut to copy/move files to current directory
mv (path to file to move) .
find files with a specific word
linux
grep -rw /home/user/Downloads -e “vacation”
create a new file with default permissions no typing text
linux
touch filename.txt
how to open a file with nano (or creates a new one)
nano path/to/existing/file or nano filename.txt
run a command that requires root privilege
sudo (command) file/path
sudo su -
then re-do command after getting root powers
view memberships for all groups - who can access run sudo
cat /etc/group
(4 fields separated by colons)
view user information on our local machine
linux
/etc/password
two ways to search for a word in a file (and filename) in a specific directory
linux
grep -rw /file/location -e “word”
ls /file/location | grep word -r
how to get detailed listing directories? w
Get-Help ls
Get-Help ls -Full
how to show hidden files in a directory? w
ls -Force (directory or drive name)
how to show what directory you’re in?
pwd
how to change your directory up one level and up one level to a specific directory?
up one level:
cd ..
a specific directory:
cd ../directoryabove on linux
cd ..\directoryabove on windows
What’s a shortcut to change to the home folder in windows?
cd ~
What’s a shortcut to change to the Desktop? both
~/Desktop
~\Desktop
What does the tilde ~ mean? What about ~\?
tilde ~ means the user’s home directory
~/ means a directory path below the home directory
~\
What are the escaped commands for windows and linux that replace special character such as spaces and brackets?
windows: ` back tick
spaces: single quotes, underscores
Linux: \ backslash
see a list of previously entered commands
how to search through results shortcut?
history
ctrl + r to search through previous commands
whats an alternative to older powershells to search through previous commands lists in history?
+tab to cycle
to copy a file
cp file filedestination
how do you copy multiple files? both
use a wildcard asterisk to select multiple files that match a pattern
cp *.jpg copydestinationpath
how do you copy a directory? windows
cp ‘directoryname’ targetdestination -Recurse -Verbose
how to rename a file?
mv .\filename newfilename
the .\ tells it that you don’t want to move the file in the current directory, just rename it
How to move a file?
mv filename filelocation
How to move multiple files?
wildcard * to select multiple
mv *filename targetlocation
ex:
mv *_document.txt ~\Documents
How do you remove a file
rm or remove
How do you remove a system file and bypass warning?
add the -Force flag at the end
rm importantfilelocation -Force
How do you remove a folder?
use -recursive
rm ~\foldername -recursive
removing a file, folder… whats a shortcut to the file path instead of the absolute?
rm ~\filename
add -recursive flag if removing a folder
how to view contents of a file? 2
linux and windows
cat filename
auto changes to cat .\filename
windows: more largedocument
linux: less largedocument
on windows using cat, what 2 parameters can we use to see only first and last few lines of text?
-Head #oflines
-Tail #oflines
How to view large output text files on Windows in pages and how do you navigate?
more largedocument
ENTER advance by line
SPACE advance by page
Q exit
how to open a text editor program and create a file
windows
start texteditor filename
example: start Notepad++ filename
how do you see what the actual powershell command of a command is?
Get-Alias
what’s the cmd.exe version of Get-Help?
\?
how do you search for words in a file, a type of file, or a directory on the entire computer?
windows
sls or Select-String
Select-String word filename.txt
Select-String word *.txt
how do you search for a pattern within a specific directory?
windows
ls ‘directorypath’ -Recurse -Filter *pattern
ls ‘D:\Program Files' -Recurse -Filter *.exe
how do you change standard output to display in a new or existing file by overwriting?
windows
echo outputcontentforfile > filename.txt
How to change the standard output to add onto an existing file, no overwriting?
windows
> > -Append
echo outputcontentforfile»_space; existingfilename.txt
How to send the output of one command into the input of another?
windows
cat filetosearch | Select-String wordtosearchfilefor
takes output of cat, inputs it to sls to search for the word
pipe
How do you search for a word in one file?
windows
cat filetosearch | Select-String wordtosearchinfile
how to use pipe operator to save standard output of a word search of a file to a new file or overwrite one?
windows
cat filetosearch | Select-String wordtosearchfor > filename
How to redirect standard error stream to a text file?
2>
rm secure_file.txt 2> filenameforerror.txt
How to filter out standard error stream messages?
Windows (redirect error stream to a black hole)
$null
example:
rm securefile.txt 2> $null
How do you get input from a file and not the keyboard?
< less than
example:
cat < fileinput.txt
same as cat fileinput.txt
how do you see a list of users and groups on the computer?
Windows
- Get-LocalUser
- Get-LocalGroup
- Get-LocalGroupMember
What’s the alias for cat?
Get-Content
How do you change your password on Linux?
passwd
How to make the user change their password on next logon linux
sudo passwd -e username
To remove a user on Linux?
sudo userdel username
To add a user on Linux?
sudo useradd username
How do you remove a user on Windows? 2 ways
net user username /del
Remove-LocalUser username
How to create an acct that requires logon password change in same command line windows?
net user username pa5sw0rd /add /logonpasswordchg:yes
How do you add a new user? windows
net user username * /add
net user username ‘some_password’ BUT THIS IS NOT SECURE do not use this
How do you require a next logon password change? windows
net user username /logonpasswordchg:yes
How do you view file permissions in Linux?
ls -l ~/my_file
for me it worked like this:
ls -l dog.txt
How do you see ACL assigned to a file/permissions? Windows
icacls filefolderpath
icacls /? for help
How do you modify a file/folder permission in the CLI? Windows
icacls ‘C:\Vacation Pictures\’ /grant ‘Everyone:(OI)(CI)(R)’
How do you only let non-guest users see a file or folder? w
icacls ‘filepath’ /grant ‘Authenticated Users: (OI)(CI)(R)’
How do you remove file permissions for a group? w
icacls ‘filepath’ /remove Everyone
How do you change permissions in Linux?
- Pick which permission you want to change (owner is u, group is g, other users is o )
- Add/remove permissions with + or - to indicate who it affects
chmod u+x filename
(this example we want to give executable access to the owner)
How do you remove a permission to a file?
chmod u-x filename
How do you add multiple permissions to a file? Read and Exec Linux
chmod u+rx filename
How do you set numerical permissions for 3 permission sets for a file in Linux?
chmod 746 filename
combination of adding up permissions: r,w,x = 4,2,1
How do you change the owner of a file? Linux
sudo chown username filename
How do you change the group a file belongs to? Linux
sudo chgrp groupname filename
To view special permissions for a file in the CLI
w
icacls filelocation
How do we enable files to be run by the permissions of the owner of the file (for other users to access without root priv?) Linux
Do a setuid special permission
sudo chmode 4441 filename
sudo chmode u+s filename
(the first 4 is the setuid)
How do you see user/group permissions for when you would run the passwd command?
ls -l /usr/bin/passwd
What are two ways to implement the setgid Linux permission for a file?
- sudo chmod g+s filename
- sudo chmod 2551 filename
(2 is the setgid)
How would you look at the permissions for the temp directory, and how to make it display just the directory not the contents?
Linux
ls -ld /tmp
How to list permissions for a folder but only show directory info, not contents
Linux
ls -ld /tmp
What are the symbolic and numerical versions of the special permissions for a sticky bit?
Symbolic - t
Numeric - 1
How do you create a file not a folder in PowerShell? 2 ways
start Notepad++ filename.txt
Notepad filename.txt
How do you force PS to bypass warning and delete the directory?
rm filename -Force
What’s the position of Get-Alias in a command line?
Get-Alias commandname
What command do you use to search for a pattern in a specific directory?
ls
example:
ls ‘filename’ -Recurse -Filter *patterntosearch
How do you modify the ACL in PS to allow read access to a single user?
icacls filename /grant ‘Username:(R)’
What’s the difference between chmod and chown?
chmod is for modifying permissions
chown is for modifying owner
What is the name of the privileged file on Linux that stores scrambled passwords?
/etc/shadow
Name 3 ways an Admin can remove users on PS
- net user username /del
- Remove-LocalUser username
- GUI > Local Users and Groups in Computer Management > Right click user > Del
In Windows, when setting basic permissio n “Read” which special permissions are enabled? 3
- Read data
- Read Permissions
- Read attributes
What’s the easiest way to make a document public/accessible to everyone?
Add the desired permission (read) to the “Everyone” group
icacls filename /grant “Everyone:(r)”
How to add a file permission to a specific user windows?
icacls filename /grant “username:(r)(w)(x)”