Show Menu

Common Commands Cheat Sheet by

Linux Commands


bash filename - Runs script
Shebang - "­#!b­in/­bas­h" - First line of bash script. Tells script what binary to use
./fil­ename - Also runs script
# - Creates a comment
echo ${vari­able} - Prints variable
hello_int = 1 - Treats "­1" as a string
Use UPPER­CASE for constant variables
Use lower­cas­e_w­ith­_un­der­scores for regular variables
echo $(( ${hell­o_int} + 1 )) - Treats hello_int as an integer and prints 2
mktemp - Creates temporary random file
test - Denoted by "[[ condition ]]" tests the condition
bash -x - Prints commands and their arguments
ps -f - Copies the current shell in the fork
exit value - Exits the script with value exit code
-n vari­able - decides if variable is not empty
-z vari­able - Decides if variable is empty
$? - Stands for the previous exit code
$# - Stands for the number of arguments passed
[[ $# -ne 2 ]] - Evaluates to true if the number of arguments is not equal to 2
-f file­name - Determines if file­name is a file
-d dire­cto­ryN­ame - Determines if dire­cto­ryN­ame is a directory
$1, $2, $3 - Refers to the first, second, and third arguments
-eq - means ==
-lt - Means <
-le - Means <=
-gt - Means >
-ge - Means >=
dirname - Prints directory name of of argument
sleep value - Forces the script to wait value seconds
while [[ condition ]]; do stuff; done
if [[ condition ]]; do stuff; fi
until [[ condition ]]; do stuff; done
words=­"­house dogs telephone dog" - Declares words array
for word in ${words} - traverses each element in array
for counter in {1..10} - Loops 10 times
for ((;;)) - Is infinite for loop
break - exits loop body
for ((coun­ter=1; counter -le 10; counte­r++)) - Loops 10 times
${arr­ay[I]} - Indexes array
${arr­ay[]} - References the whole array. Can also use @*
declare -A array - declares associ­ative array
myasso­car­ray­=([­app­le]­="re­d" [banan­a]=­"­yel­low­") - Creates associ­ative array
${mya­sso­car­ray­[ba­nana]} - References bananas value in the array
unset array[I] - Deletes the I index
unset array - Deletes the array
${#ar­ray} - Outputs the length of the array
alias ll = 'ls -l' - Creates the ll command as an alias
home() { do stuff ; } Creates the home function
return - defaults to the previous exit value
local - Creates local variable within function
cut - Cuts away parts of the output


git clone <ur­l> - Clones gitkeeper url
git add <fi­len­ame­> - Adds the file to git
git commit - Commits all files to git
git push - Pushes all git files to host

Package / Networking

dnf upgrade - Updates system packages
dnf install - Installs package
dnf search - Searches for package
dnf remove - Removes package
systemctl start - Starts systemd service
systemctl stop - Stops systemd service
systemctl restart - Restarts systemd service
systemctl reload - Reloads systemd service config­uration files
systemctl enable - Enable systemd service at boot
systemctl disable - Disable systemd service
systemctl status - Displays activity state and some log lines of service
atq - Displays currently scheduled commands
at - Runs command once at certain time/day
atrm - Remove scheduled commands
crontab -e - Create a file for scheduled commands to run
journ­alctl - Shows logs
dmesg - Shows kernel messages, hardware, driver, etc.
history - Shows previous commands
script - Records all input and writes it to a file
route - Configures IP connection
hostname - Sets system host name
netstat -rn - Gives routing table
ifconfig - Outputs network interface
ip addr - Shows different addresses and internet connec­tions
trace­route -I - Gives list of IPs the machine went through
wget - Downloads file from internet
brctl, nmcli - Creates bridging between ports

Other Stuff

Ctrl - U - Deletes command line
Ctrl - C - Aborts command
Ctrl - Z - Suspends command
fg - Resumes command after suspension
Ctrl - T - Fix misspelled command
cal - Prints ASCII calendar

System Inform­ation

free - Displays amount of free and used memory in system
df - Reports file system disk space usage
lsblk - Reports inform­ation about block devices
fdisk - Manipu­lates disk partition table
Uname - Prints system inform­ation
top - Display and update sorted info about processes
uptime - Displays the amount of timed the machine has been running

User/Root Commands

useradd - Creates new user
passwd - Sets password for new user
userdel - Removes user
chsh --shell /bin/sh username - Changes shell
sudo grouped groupante - Creates group
chown - Changes owner
chgrp - Changes group
chmod - Changes permis­sions
chmod ug +x filename - Gives user and group permission to execute file
chmod 1777 filename - Sets all permis­sions and a sticky bit


smbpa­sswd - Sets server password

File and Directory Manipu­lation

ls - Shows all files in current directory
ls -a - Shows all files including hidden files in current directory
pwd - Shows current directory (present working directory)
cd - Changes curent directory
pstree - Shows running processes as a tree
ps - Report a snapshot of current processes
cp - Copies files
cp filename newfil­ename - Creates new file with old file inform­ation
cp filename direct­ory/ - Puts file into directory
mv - Moves files
mv filename direct­ory/ - Moves file into directory
rm - Remove­s\d­eletes files
rm -r - Deletes direct­ories
rm -r direct­ory/ - Removes directory
rm -rf direct­ory/ - Removes directory to oblivion
mkdir - Creates direct­ories
echo - Moves data (e.g. moves text into a file)
echo text >> filename - Moves text into file
cat - Reads file text or concat­enate files and print file text
touch - Creates any kind of file
tail - Outputs last part of files
less - Views files instead of opening them. Lets user scroll through
awk - Selects data and presents rows and columns in output
awk '{print $1,$2,$3}' filename - Prints first, second, third words of each line
sort - Sorts lines of text files
vi filename - Opens text editor for file. Hard to use
file filename - Gives inform­ation on file
more filename - Displays file contents (no scrolling)
grep "­tex­t" filename - Searches for text within file
find - Finds files
whoami - Prints current user
rmdir - Removes direct­ories
du - Displays file space usage
yes - Displays the same line of text until interr­upted


Thanks bro this cheat sheet helped me figure out how to rm -rf my internal demons 10/10 better than an exorcism.

mmorykan mmorykan, 14:23 14 Feb 20

Thanks for the support!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Command Line Cheat Sheet
          Bash/ZSH Shourtcuts Cheat Sheet
          Linux Cheat Sheet