Linux Cheatsheet
The shell lets you navigate the filesystem, manage files, and run programs with short commands.
Examples assume a common Bash-style environment. Check your distribution’s package manager if a command name differs slightly.
Full lessons: Linux Tutorials
Navigation
pwd
Print the current working directory—your location in the filesystem tree.
pwd
ls
List directory contents. Common flags: -l long format, -a include hidden, -h human sizes.
ls -lah
ls /var/log
cd
Change directory. ~ is your home; .. is the parent; - returns to the previous directory.
cd ~/projects
cd ..
cd -
Absolute vs relative paths
Paths starting with / are absolute from the root; others are relative to the current directory.
cd /etc
cd ../docs
clear / Ctrl+L
Clear the terminal screen so recent output is easier to read (history remains available).
clear
man
Open the manual page for a command. Quit with q; search inside with /.
man ls
man 5 passwd
Files
mkdir
Create directories. Use -p to create parent folders as needed.
mkdir notes
mkdir -p projects/web/css
touch
Create an empty file or update a file’s timestamp.
touch readme.md
touch notes/{a,b,c}.txt
cp
Copy files or directories. Add -r to copy directories recursively.
cp draft.txt draft.bak
cp -r site/ site-backup/
mv
Move or rename files and directories.
mv old-name.txt new-name.txt
mv report.pdf ~/Documents/
rm
Delete files. Use -r for directories and double-check paths—deletes are usually permanent.
rm temp.log
rm -ri old-folder/
ln -s
Create a symbolic link (shortcut) that points to another path.
ln -s ~/projects/app /var/www/app
Viewing & search
cat / less
cat prints a whole file; less pages through long output interactively.
cat notes.txt
less /var/log/syslog
head / tail
Show the beginning or end of a file. tail -f follows new lines as they are written.
head -n 20 access.log
tail -f app.log
grep
Search for text patterns in files. -i ignores case; -r searches recursively.
grep -i "error" app.log
grep -rn "TODO" src/
find
Locate files by name, type, or other tests under a starting path.
find . -name "*.py"
find /var/log -type f -mtime -1
Pipes & redirection
Pipe (|) sends stdout to another command; > writes a file; >> appends.
ls -1 | wc -l
grep fail app.log > failures.txt
du / df
du estimates directory disk use; df shows filesystem free space.
du -sh ~/Downloads
df -h
Permissions
Permission bits
Read, write, and execute for user, group, and others. Shown by ls -l as rwx triples.
ls -l script.sh
# -rwxr-xr-x owner can rwx; group/others rx
chmod
Change mode bits symbolically or numerically (for example 755 or 644).
chmod u+x deploy.sh
chmod 644 config.ini
chown
Change file owner and optionally group. Often needs elevated privileges.
sudo chown alice:alice report.pdf
sudo chown -R www-data:www-data /var/www/html
whoami / id
Show the current username and numeric user/group IDs.
whoami
id
sudo
Run one command as another user (usually root). Prefer the least privilege that still works.
sudo apt update
sudo -u www-data ls /var/www
Packages & processes
apt update / install
On Debian/Ubuntu, refresh package indexes then install software.
sudo apt update
sudo apt install curl git
apt remove / search
Remove packages or search the package list by keyword.
apt search nginx
sudo apt remove unused-tool
ps / top
List running processes. top (or htop) updates interactively.
ps aux | grep python
top
kill / killall
Send a signal to a process (default TERM). Use the PID from ps carefully.
kill 12345
killall -TERM myapp
jobs / bg / fg
Manage jobs started in the current shell: list, resume in background, or bring to foreground.
jobs
bg %1
fg %1
systemctl (services)
On systemd systems, start, stop, and check service status.
systemctl status ssh
sudo systemctl restart nginx
Networking basics
ping
Send ICMP echo requests to test basic reachability and latency.
ping -c 4 example.com
ip / hostname
Show addresses and hostname. Many systems use ip instead of older ifconfig.
ip a
hostname -I
curl / wget
Download or request URLs from the command line. curl -I shows response headers.
curl -I https://example.com
wget https://example.com/file.zip
ssh
Open a secure shell session to a remote host. Keys are preferred over passwords.
ssh [email protected]
ssh -i ~/.ssh/id_ed25519 [email protected]
ss / netstat
Inspect listening ports and connections. ss is the modern default on many distros.
ss -tulpn
ss -tp | grep ssh
Comments
One comment per signed-in account. Comments are saved with this page’s URL.