Cheatography
https://cheatography.com
Basic commands for a BASH Linux. Mostly stuff taught in the Google Cybersecurity Certificate.
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Keyboard Shortcuts
Ctrl + A |
Sets cursor at beginning of a command |
Ctrl + C |
Kill process running in the terminal |
Ctrl + E |
Sets cursor at end of a command |
Ctrl + K |
Cut part of the line after the cursor and add to clipboard |
Ctrl + U |
Cut part of the line before the cursor and add to clipboard |
Ctrl + W |
Cut one word before the cursor and add to clipboard |
Ctrl + Y |
Paste from clipboard |
Ctrl + Z |
Stop the current process. Can be resumed in Foreground [fg] or Background [bg] |
echo > OR >> |
> overwrites existing file >> adds your content to the end (echo "time" > permissions.txt) |
| |
‘Piping’ commands together |
!! |
Run the last command again |
Tab |
Provides available suggestions for completing your text |
clear |
Clears the terminal screen |
exit |
Log out of current session |
nano [file_name] |
Open or create a file using the nano text editor |
Files
touch [file_name] |
Creates a new file (touch [directory_name]) |
rm [file_name] |
Removes a file |
mkdir [diectory_name] |
Create a new directory |
rmdir [directory_name] |
Removes a directory |
cat [file_name] |
Show the contents of a file |
head [file_name] |
Show the first ten lines of a file (-n [#] specify how many lines to return) |
tail [file_name] |
Show the last ten lines of a file (-n [#] specify how many lines to return) |
more [file_name] |
Display contents of a file page by page |
less [file_name] |
Show the contents of a file with navigation |
mv [source_file] [destination_file] |
Move or rename files or directories (rename using 2nd argument) |
cp [source_file] [destination_file] |
Copies a file or directory to a new location |
chmod [u/g/o +/- r/w/x] [file_name] |
Changes permissions on files and directories |
Searching
man |
Manual. Displays info on other commands |
apropos |
Searches the manual (use -a to refine) |
whatis |
Displays a description of a command on a single line |
whoami |
See which user you are using |
find [path] |
Find files and directories |
find [directory_name] -name [“search_pattern”] |
case-sensitive (* wildcard for zero or more unknown characters) |
find [directory_name] -iname [“search_pattern”] |
NOT case-sesitive (* wildcard for zero or more unknown characters) |
grep [search_pattern] [file_name] |
Search for a specific pattern in a file |
grep -r [search_pattern] [directory_name] |
Recursively search for a pattern in a directory |
-mtime |
Directories last modified within a certain time frame using days [+1 or -1] |
-mmin |
Directories last modified within a certain time frame using minutes [+60 or -60] |
Note: An asterisk (*) is used as a wildcard to represent zero or more unknown characters.
Note: grep needs [“quotes”] to search for more than one word
Directory Navigation
pwd |
Show the directory you are currently working in |
cd [diectory_name] |
Navigates to that directory |
cd .. |
Move up one directory level |
cd - |
Change to the previous directory |
ls |
List files and directories in the current directory |
ls [diectory_name] |
List files and directories in specific location |
ls -l |
List files and directories in long format (can combine -la) |
ls -a |
Shows hidden files (can combine -la) |
Navigating in less
less [file_name] |
Show the contents of a file with navigation |
Up/Down arrow |
Move up/down one line |
Left/Right arrow |
Move left/right half of page |
Page Up/Down |
Move up/down one page |
g |
Go to the first line |
G |
Go to the last line |
F |
Go to the last line, and display any new lines [similar to tail -F] [Ctrl+C to exit] |
b |
Move back one page |
n |
Repeat a previous search |
N |
Repeat a previous search, but in the opposite direction |
q |
Quit |
?malware |
Search -go to the previous line containing the word ‘malware’ |
/!malware |
Search -go to the next line NOT containing the word ‘malware’ |
/malware |
Search -go to the next line containing the word ‘malware’ |
Users and Groups
sudo useradd [user_name] |
Create new user account |
sudo userdel [user_name] |
Deletes a user account |
sudo groupdel [user_name] |
Deletes a group |
sudo chown [user_name] [file_name] |
Changes ownership of a file or directory (use : to designate a group) |
sudo usermod [prefix] [group_name] [user_name] |
Changes existing user accounts |
-g OR -G |
Adds a user to a primary OR secondary group. (sudo useradd -g security username) |
-a |
Appends the user to an existing group (sudo usermod -a -G marketing username) |
-d |
Changes user’s home directory (sudo usermod -d /home/name_user username) |
-l |
Changes user’s login name |
-L |
Locks the account from user |
|