Linux Commands Cheat Sheet — Essential Reference
A quick, organized reference to the most-used Linux commands for managing your server. Bookmark this page.
Navigation & directories
pwd # print current directory
ls -lah # list all files (long, human sizes)
cd /var/www # change directory
cd .. # up one level
mkdir -p a/b/c # create nested directories
rmdir dir # remove empty directoryFile operations
cp file.txt bak.txt # copy
cp -r dir1 dir2 # copy directory
mv old.txt new.txt # move / rename
rm file.txt # delete file
rm -r dir # delete directory
touch file.txt # create empty file
ln -s target linkname # symbolic linkViewing & editing files
cat file.txt # print contents
less file.txt # scroll (q to quit)
head -n 20 file.txt # first 20 lines
tail -n 20 file.txt # last 20 lines
tail -f app.log # follow a log live
nano file.txt # simple editorPermissions & ownership
chmod 755 script.sh # rwxr-xr-x
chmod +x script.sh # make executable
chown user:group file # change owner:group
chown -R www-data: /var/www # recursive
sudo command # run as rootProcesses & system
ps aux # all processes
top # live process monitor
kill 1234 # terminate by PID
kill -9 1234 # force kill
killall nginx # kill by name
uname -a # kernel / OS info
whoami # current user
uptime # load & uptimeDisk & memory
df -h # disk space per filesystem
du -sh /var/www # size of a directory
free -h # memory usageSearching & text
grep "error" app.log # search text in a file
grep -ri "todo" . # recursive, case-insensitive
find / -name "*.conf" # find files by name
sort file.txt | uniq # sort & de-duplicate
ps aux | grep php # pipe + filterNetworking
ping example.com # test connectivity
curl -I https://site.com # fetch headers
wget https://site/file.zip # download a file
ss -tlnp # listening ports
ssh user@server-ip # remote loginPackage management
# Debian/Ubuntu
sudo apt update && sudo apt upgrade -y
sudo apt install nginx
sudo apt remove nginx
# RHEL/AlmaLinux/CentOS
sudo dnf install nginx
sudo dnf remove nginxUsers
sudo adduser alice # create user
sudo usermod -aG sudo alice # add to sudo group
sudo passwd alice # set password
sudo deluser alice # remove userArchiving & compression
tar -czvf site.tar.gz /var/www # create .tar.gz
tar -xzvf site.tar.gz # extract .tar.gz
zip -r site.zip /var/www # create .zip
unzip site.zip # extract .zipFor managing background services (start, stop, enable at boot), see “How to List and Manage Linux Services with systemctl” in this category.