Cheat sheet · Tools

Linux command line cheat sheet

Move around, handle files, read logs, check the system and connect to other machines from the terminal.
Sections
7
Items
39
Area
Tools
Download
PNG, PDF

Cheat sheet

Linux command line

Move around, handle files, read logs, check the system and connect to other machines from the terminal.

/blogs

Move around

pwd
Print the folder you are in
ls -la
List all files with details, including hidden ones
cd <folder>
Go into a folder
cd ..
Go up one folder
cd -
Go back to the previous folder

Files and folders

mkdir -p a/b/c
Create a folder and any missing parents
touch <file>
Create an empty file or update its time
cp -r <from> <to>
Copy a file or a whole folder
mv <from> <to>
Move or rename
rm -r <folder>
Delete a folder and everything in it (no undo)
ln -s <target> <link>
Make a shortcut (symbolic link)

Read and search

cat <file>
Print a whole file
less <file>
Read a long file page by page (q to quit)
head -n 20 <file>
Show the first 20 lines
tail -f <file>
Follow a log file as it grows
grep -rn "text" .
Find text in all files, with line numbers
find . -name "*.log"
Find files by name
wc -l <file>
Count lines

Permissions

chmod +x <file>
Allow a file to run as a program
chmod 755 <file>
Owner: read, write, run. Others: read, run
chown user:group <file>
Change who owns a file
sudo <command>
Run a command as the administrator

Numbers: 4 = read, 2 = write, 1 = run. Add them for each of owner, group, others.

Processes and system

ps aux
List running processes
top
Live view of CPU and memory use
kill <pid>
Ask a process to stop
kill -9 <pid>
Force a process to stop
df -h
Free disk space
du -sh *
Size of each item in this folder
free -h
Memory in use

Network

ping <host>
Check that a machine answers
curl -I <url>
Show only the response headers of a web address
ss -tulpn
Show which program listens on which port
ssh user@host
Open a shell on another machine
scp <file> user@host:<path>
Copy a file to another machine

Pipes and redirects

a | b
Send the output of a into b
a > file
Write output to a file (replaces it)
a >> file
Add output to the end of a file
a 2>&1
Send errors to the same place as normal output
a | xargs b
Run b once for each line a prints

Remember

  • Press Tab to finish a name and the up arrow to bring back an old command.
  • Read a command's help with man <command> or <command> --help.
  • rm has no trash can. Check the path twice before you press Enter.

Learn it properly

A cheat sheet helps you remember. These lessons explain the ideas step by step, with examples.

More cheat sheets

All cheat sheets →