Show Menu

Command Line and Terminal navigation Cheat Sheet by

Commands and operators to use the Linux/macOS Terminal like a pro, from zero to hero, or however you want to call it. Please note, that not all commands will work in all instances, and this is specified with the environment within parentheses.


cd [path]
change your current directory to the specified one
cd ~
go to your home folder
cd -
go the the folder you were before
list the contents of the directory
ls -lh
list the contents of the directory in a human-­fri­endly format
cp [origin] [desti­nation]
copies the given file wherever you want to
mv [origin] [desti­nation]
moves or renames the given file
get the current directory you're in
mkdir [name]
create a folder
mkdir -p [name]
create a folder and all its parents, if needed
chmod 755 [name]
change a file's permis­sions - Allows the user to read, write and execute, and anyone else to just read and execute
chmod 400 [name]
change a file's permis­sions - Only the owner will be able to read the file
chown user:group [name]
changes the owners of a given file or folder
chown -R user:group [name]
changes the owners of a given file or folder, and all of its contents
touch [name]
creates a file with the given name
file [name]
reports the file type
rm [file]
removes a file
rm -rf [file]
removes a folder and all of its contents
cat [file]
prints a file's contents
tac [file]
prints a file's contents from bottom to top
allows replacing of contents in files with regular expres­sions
grep [pattern] [file]
prints the contents of a given file that match the given pattern
tr -s [pattern]
replaces all concurrent duplicates of a given pattern
tr [pattern] [repla­cement]
replaces the given pattern with the given replac­ement string
tr -d [pattern]
removes the given pattern from a string
head [file]
prints the first lines of a given file
tail [file]
prints the last lines of a given file
cut -f [field] -d [separ­ator]
allows you to print specific fields from an origin that have a given separator
gets the OS kernel's name (Linux, Darwin...)
uname -m
gets the machine's archit­ecture (if not within an emulator)
uname -r
gets the kernel version
uname -a
shows all the details of your UNIX OS
less [file]
prints a file using pagination
more [file]
same as
less [file]
ln -s [source] [desti­nation]
makes a symbolic link of a given source at the given destin­ation
prints a calendar on the terminal
reports the current date and time

Write (or append to) a file without an editor

cat > [file] << EOF
hello world
this is a file's content
blah blah blah

hello again

bye for now
In order to append to a file instead of replacing all of its contents, add two output cones instead of only one (>>).

Command pipeline concat­enation example

curl -s "­htt­ps:­//d­eve­lop­er.a­nd­roi­d.c­om/­stu­dio­#do­wnl­oad­s" | grep ".dm­g" | grep href | head -n1 | cut -f2 -d"=­" | tr -d '"'

This command will:

- download the downlaods page for Android Studio
- find for the lines that contain ".dm­g" within them
- filter again to get only those that contain "­hre­f"
- filter again to get only the first occurrence
- split the result to get only the second field using = as a separator
- remove any double quotation marks on the string

The result should be a link that, when opened, will download the macOS installer for Android Studio.

Please note, if the website changes, this command may not work as is.


Almost all programs on any Unix OS will have what's called a "­man­pag­e". This is an instru­ction manual with details on how to use a program.

In order to read the manual for a specific applic­ation, just type
man [appli­cation]
and you will be able to read how it works. Press "­Q" to close the manual when you're done.

sed examples

command uses a string as parameter to determine what to oeprate, and can receive several more parameters to configure the behavior.

sed -i 's/hel­lo/hi/' file.txt
will replace the first instance of "­hel­lo" that the script can find at each line, and write the result at the same given file. To avoid overwr­iting, you can just remove the

sed -i 's/hel­lo/­hi/g' file.txt
will replace every instance of "­hel­lo" that exist in the file.

To apply the patterns from a file, use the
parameter with a path to a file.

If you want to make a backup of the file, add a suffix for said file after the
parameter. For example:

sed -i".b­kp­" 's/hel­lo/­hi/g' file.txt
will generate a file named
with the original contents.

Regular expres­sions can be applied to the pattern given to sed, as maybe you want to replace something that may not be an exact string, but rather a pattern of it.


Shows a general network brief
ip addr show
Same as
but on Linux
nmap [ip]/32
Scans the ports of the given IP
ping [host]
Send a sequence of ICMP packets to a host
whois [host]
Tells you inform­ation about the domain
dig [domain]
Tells you how a specific domain resolves
nslookup [domain]
The same as
dig [domain]
host [domain]
Reports several types of records for a given domain
wget [url] -O [file]
Downloads the given URL to the specified file
curl [url] -o [file]
Downloads the given URL to the specified file
Allows you to monitor the network throughput (Linux)
netstat -tulpn
Shows which applic­ations are using what ports (Linux)
sudo lsof -i -n -P
Shows which applic­ations are using what ports (macOS)

Pipelines and operators

[command] > [file]
outputs the result of a command to a file
[command] >> [file]
outputs the result of a command to the end of a file
[command] < [file]
gets a file and prints its content as if it were you entering it
[command] << [file]
appends a file's contents into the program
[command1] && [command2]
if command1 succeeds, command2 will be executed
[command1] || [command2]
if command1 fails, command2 will be executed
the process will be run in the background
the last executed command
the last command's exit code
[command1] | [command2]
sends the output of command1 to command2's input
[command] \
allows you to make a line break without executing the command
[command] 2>&1
redirects the command's stderr to stdout
runs the given command, and then runs the result as a command itself

Remote hosts

ssh [server]
connects to a server via SSH
ssh [server] -p [port]
ssh [server] -i [certi­ficate]
scp [user]­@[s­erv­er]­:[path] [local path]
copies a file from a remote server to your machine
telnet [host] [port]
makes a raw tcp connection to a given host and port
reports who's connected at the machine
same as
tells you your username
For SCP, you can upload from your machine to a remote server by changing the order of the commands. You can also use SSH's parameters with SCP (for port, you must use

Enviro­nment variables

the direct­ories where the shell will find for the command binaries
your home directory
the user ID
the user ID running the command
your current shell
your prompt's style
your current directory
random number
the host's name
the shell's language
your current session's TTY

Loops and decision taking

"­For­" loop
for i in {1..10}


    echo $i


"­Whi­le" loop (example of an infinite loop)
while [ true ]


echo hello


"­Unt­il" loop (do while)
until [ $IDX -eq 5 ]


echo $IDX



"­If-else if-els­e" operator
if [ $UID -eq 0 ]


echo You are root

elif [ $UID -eq 1 ]

echo You are user with ID 1


echo You are NOT root


Permission bits

Do nothing
Execute and write
Read and execute
Read and write
Read, write and execute
Here "­r" stand for "­rea­d", "­w" stands for "­wri­te", and "­x" stands for "­exe­cut­e". It may be useless to have permis­sions below 4, as you won't be able to read the file. A 0 permission is useful to fully restrict access to any other user.

Permis­sions are usually repres­ented by three digits, and their meaning is the following: the first one represents the owner user of the file, the second number represents the owner group's permis­sions, and the last one represents everybody else's permis­sions.

Package Managers

Debian, Ubuntu
Amazon Linux, Red Hat
Red Hat, Fedora
Arch Linux
macOS (Homebrew)
Windows (Choco­latey)


find [path] -name [name pattern]
finds anything within a given path with a given pattern on its name
whereis [name]
tells you all the locations for a given binary name
which [name]
tells you the given binary name's path that will be run according to your PATH
locate [name]
tells you the location of any kind of file within your machine

Monitoring the OS

ps aux
prints a snapshot of all system processes
shows the processes running on the machine
shows the processes running on the machine with some graphs for memory usage
df -h
prints the system's storage devices' usage
du -hs [path]
prints a folder or file size
free -m
reports used and free ram and swap
kill [pid]
kills a process with the given pid
kill -9 [pid]
forcefully kills a process with the given pid
kill -l
lists the termin­ation codes available to send the processes
pkill [process name]
kills any processes with the name provided (also works with -9 and other numeric signals)
kills a graphical process (Xorg)
lists the drives, its partit­ions, and space (Linux)
shows the mount details of each volume (Linux)
lists PCI devices
lists USB devices


tar xf [file]
extracts a tar file at the current path
tar cf [filename] [content]
creates a tar file with the given name from the given content
tar zcf [filename] [content]
creates a gzipped tar file with the given name from the given content
unzip [file]
unzips a .zip file
zip [filename] [content]
creates a .zip file with the given name from the given content

ls parameters

detailed list
human-­rea­dable file size, used with -l
list direct­ories themselves
include dotfiles (hidden files)
list using base 1000 instead of 1024
list with commas instead of tabs
sort by newest to oldest

grep parameters

case insens­itive
hide all matches
recursive search
regular expression pattern
match entire line
match entire word
-f [file]
use patterns from file
do not search inside binary files
recursive, even with symlinks

screen parameters

creates a new screen session
screen -ls
lists the existing screen sessions
screen -r [name]
resume a given screen
activates commands for the active screen session
discon­nects from the screen

sort parameters

-k [number]
specific field
case insens­itive
ls -l | sort -n -k5
will list a folder's contents by its size, from the least to the most sized.


Niceness is they way Unix OSes give priority to the applic­ations running on the machine. A niceness of 19 means it's got the least priority, whereas a -20 priority means it's got the most priority.

renice 19 [pid]
will make the process with given PID have the least priority within the CPU. This means that, when the OS is running low on CPU resources, this process will be more ignored than one with a lower niceness number.

renice -20 [pid]
will make this process have the most CPU availa­bility even when resources are scarce.

S3 Commands (aws s3)

ls s3://b­uck­et/file
Lets you know if a file exists or not
cp s3://b­uck­et/file /path/­on/­machine
Downloads a file into your computer
cp --recu­rsive s3://b­uck­et/­folder /path/­on/­machine
Downloads a folder and its content into your computer
rm s3://b­uck­et/file
Removes a remote file
All commands must begin by
aws s3
Paths can be specified in both ways: from local to remote, or from remote to local. They can also work from remote to remote, but will use your device as a bridge.


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          tmux the terminal multiplexer Cheat Sheet
          Xterm Keyboard Shortcuts
          tmux - terminal multiplexer Keyboard Shortcuts