Show Menu
Cheatography

Linux Basic Commands Cheat Sheet (DRAFT) by

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 "­tim­e" > permis­sio­ns.txt)
|
‘Piping’ commands together
!!
Run the last command again
Tab
Provides available sugges­tions 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 [direc­tor­y_n­ame])
rm [file_­name]
Removes a file
mkdir [diect­ory­_name]
Create a new directory
rmdir [direc­tor­y_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 [sourc­e_file] [desti­nat­ion­_file]
Move or rename files or direct­ories (rename using 2nd argument)
cp [sourc­e_file] [desti­nat­ion­_file]
Copies a file or directory to a new location
chmod [u/g/o +/- r/w/x] [file_­name]
Changes permis­sions on files and direct­ories

Searching

man
Manual. Displays info on other commands
apropos
Searches the manual (use -a to refine)
whatis
Displays a descri­ption of a command on a single line
whoami
See which user you are using
find [path]
Find files and direct­ories
find [direc­tor­y_name] -name [“search­_pa­ttern”]
case-s­ens­itive (* wildcard for zero or more unknown charac­ters)
find [direc­tor­y_name] -iname [“search­_pa­ttern”]
NOT case-s­esitive (* wildcard for zero or more unknown charac­ters)
grep [searc­h_p­attern] [file_­name]
Search for a specific pattern in a file
grep -r [searc­h_p­attern] [direc­tor­y_name]
Recurs­ively search for a pattern in a directory
-mtime
Direct­ories last modified within a certain time frame using days [+1 or -1]
-mmin
Direct­ories 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 charac­ters.
Note: grep needs [“quotes”] to search for more than one word

Directory Navigation

pwd
Show the directory you are currently working in
cd [diect­ory­_name]
Navigates to that directory
cd ..
Move up one directory level
cd -
Change to the previous directory
ls
List files and direct­ories in the current directory
ls [diect­ory­_name]
List files and direct­ories in specific location
ls -l
List files and direct­ories 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/­nam­e_user username)
-l
Changes user’s login name
-L
Locks the account from user