Commands in Linux
This cheat sheet collects the Linux commands you use most often on a server: system information, files, search, disks, users, permissions, archives, packages, networking, the firewall, processes and logs. The examples work on current Ubuntu, Debian, AlmaLinux and Rocky Linux.
Commands that change the system need root rights. Run them as root or add sudo in front.
System Information Command What it does uname -a Shows the kernel version, hostname and architecture uname -r Shows only the kernel version cat /etc/os-release Shows the distribution name and version hostnamectl Shows the hostname, OS and kernel lscpu Shows CPU details: model, cores, threads free -h Shows RAM and swap usage in human-readable units lsblk Lists disks and partitions lspci Lists PCI devices uptime Shows how long the system has been running and the load average date Shows the current date and time timedatectl set-timezone Europe/London Sets the system time zone cal 2026 Shows the calendar for 2026
Shutdown and Reboot Command What it does shutdown -h now Shuts the system down immediately shutdown -h 22:30 Schedules a shutdown at 22:30 shutdown -c Cancels a scheduled shutdown reboot Restarts the system exit Logs out of the current session
Files and Directories Command What it does pwd Shows the current directory ls -la Lists all files, including hidden ones, with permissions and sizes ls -lh Lists files with sizes in KB, MB and GB cd /var/www Goes to the /var/www directory cd .. Goes one level up cd ../.. Goes two levels up cd ~ Goes to your home directory cd - Returns to the previous directory mkdir dir1 Creates a directory mkdir -p /tmp/dir1/dir2 Creates a directory together with any missing parent directories cp file1 file2 Copies file1 to file2 cp -a dir1 dir2 Copies a directory with its contents, permissions and timestamps mv old_name new_name Moves or renames a file or directory rm file1 Deletes a file rm -r dir1 Deletes a directory and everything in it (check the path twice) rmdir dir1 Deletes an empty directory ln -s /path/to/target link_name Creates a symbolic link touch file1 Creates an empty file or updates its modification time tree Shows the directory tree (install the tree package first)
Viewing File Contents For more examples, see our guide on how to display the contents of a file in Linux .
Command What it does cat file1 Prints the whole file less file1 Opens the file page by page with search (press q to exit) head -n 20 file1 Shows the first 20 lines tail -n 50 file1 Shows the last 50 lines tail -f /var/log/syslog Follows a log file in real time tac file1 Prints the file in reverse order, from the last line
Searching for Files and Text Command What it does find / -name file1 Finds files and directories named file1, starting from the root find /home -user user1 Finds files owned by user1 find /var/log -name "*.log" -mtime -7 Finds .log files modified in the last 7 days find /usr/bin -type f -atime +100 Finds files that have not been accessed for more than 100 days grep -R "error" /var/log Searches for the word error in all files under /var/log locate file1 Finds files by name using a database (run updatedb first) which nginx Shows the full path of the nginx command whereis nginx Shows the binary, source and manual page locations
Disks and Mounting Command What it does df -h Shows free and used space on mounted file systems du -sh /var/www Shows the total size of a directory du -sh * | sort -rh | head Shows the 10 largest items in the current directory lsblk -f Lists partitions with file system types and UUIDs mount /dev/sdb1 /mnt/data Mounts a partition to /mnt/data (the directory must exist) umount /mnt/data Unmounts the partition mount -o loop image.iso /mnt/iso Mounts an ISO image mount -t cifs //server/share /mnt/share -o username=user Mounts a Windows (SMB/CIFS) network share mkfs.ext4 /dev/sdb1 Creates an ext4 file system (erases all data on the partition) fsck /dev/sdb1 Checks and repairs a file system (run it on an unmounted partition)
Users and Groups Command What it does whoami Shows the current user id user1 Shows the user ID and groups of user1 useradd -m -s /bin/bash user1 Creates user1 with a home directory and the bash shell passwd user1 Sets or changes the password of user1 usermod -aG sudo user1 Adds user1 to the sudo group (use wheel on AlmaLinux and Rocky Linux) userdel -r user1 Deletes user1 together with the home directory groupadd developers Creates a group groupdel developers Deletes a group chage -E 2026-12-31 user1 Sets the account expiration date who Shows who is logged in last Shows the login history
File Permissions For a detailed explanation, see how to change file and folder permissions .
Command What it does ls -l Shows permissions, owner and group of each file chmod 644 file1 Owner can read and write, everyone else can read chmod 755 dir1 Owner has full access, everyone else can read and enter chmod -R 755 dir1 Applies permissions recursively chmod u+x script.sh Makes a script executable for its owner chown user1:group1 file1 Changes the owner and group of a file chown -R www-data:www-data /var/www/site Changes the owner of a directory recursively find / -perm -u=s -type f Finds files with the SUID bit set chmod +t /home/public Sets the sticky bit: only owners can delete their files chattr +i file1 Makes a file immutable, even for root lsattr file1 Shows file attributes
Archives and Compression Command What it does tar -czvf archive.tar.gz dir1 Creates a gzip-compressed archive of dir1 tar -xzvf archive.tar.gz Extracts a .tar.gz archive tar -xzvf archive.tar.gz -C /tmp Extracts the archive to /tmp tar -cjvf archive.tar.bz2 dir1 Creates a bzip2-compressed archive tar -tf archive.tar.gz Lists the contents of an archive zip -r archive.zip dir1 Creates a zip archive unzip archive.zip Extracts a zip archive gzip file1 Compresses a file to file1.gz gunzip file1.gz Decompresses a .gz file
Packages on Ubuntu and Debian Command What it does apt update Refreshes the package lists apt upgrade Installs available updates apt install nginx Installs a package apt remove nginx Removes a package and keeps its configuration files apt purge nginx Removes a package together with its configuration files apt autoremove Removes dependencies that are no longer needed apt search nginx Searches for packages apt show nginx Shows package details dpkg -i package.deb Installs a local .deb file dpkg -l | grep nginx Checks whether a package is installed dpkg -L nginx Lists the files installed by a package dpkg -S /bin/ping Finds the package that owns a file
Packages on AlmaLinux and Rocky Linux Command What it does dnf check-update Checks for available updates dnf upgrade Installs updates dnf install nginx Installs a package dnf remove nginx Removes a package dnf search nginx Searches for packages dnf info nginx Shows package details rpm -qa Lists all installed packages rpm -qi nginx Shows information about an installed package rpm -ql nginx Lists the files of a package rpm -qf /etc/nginx/nginx.conf Finds the package that owns a file rpm -ivh package.rpm Installs a local .rpm file
Networking Command What it does ip a Shows network interfaces and IP addresses ip route Shows the routing table ip addr add 192.168.1.10/24 dev eth0 Adds an IP address to an interface ip link set eth0 down Disables an interface (use up to enable it) ss -tulpn Shows listening TCP and UDP ports and the processes behind them ping -c 4 example.com Checks whether a host is reachable traceroute example.com Shows the route packets take to a host dig example.com Queries DNS records host example.com Resolves a hostname to an IP address and back curl -I https://example.com Shows the HTTP response headers wget -c https://example.com/file.iso Downloads a file and resumes it if the download is interrupted hostnamectl set-hostname server1 Changes the hostname
Firewall For more rules and examples, see our iptables guide .
Command What it does ufw status Shows UFW status and rules (Ubuntu) ufw allow 22/tcp Opens port 22 in UFW ufw enable Turns on UFW firewall-cmd --list-all Shows firewalld rules (AlmaLinux, Rocky Linux) firewall-cmd --permanent --add-service=http Opens HTTP in firewalld firewall-cmd --reload Applies firewalld changes iptables -L -n -v Shows iptables rules with packet counters
Processes and Services Command What it does top Shows running processes and resource usage in real time htop A more convenient version of top (install the htop package) ps aux Lists all processes ps -ef --forest Shows processes as a tree kill 1234 Asks the process with PID 1234 to stop kill -9 1234 Stops the process immediately, without cleanup pkill nginx Stops processes by name systemctl status nginx Shows the status of a service systemctl restart nginx Restarts a service systemctl enable --now nginx Starts a service and enables it at boot lsof -i :80 Shows which process uses port 80
Logs and Monitoring Command What it does journalctl -u nginx Shows the log of a service journalctl -f Follows the system log in real time journalctl -b Shows the log since the last boot dmesg -T | tail Shows the latest kernel messages with timestamps tail -f /var/log/syslog Follows the system log on Ubuntu and Debian (/var/log/messages on AlmaLinux and Rocky Linux) last reboot Shows the reboot history watch -n 2 free -h Repeats a command every 2 seconds smartctl -a /dev/sda Shows the SMART status of a disk (smartmontools package)
Text Processing Command What it does grep -i "error" file1 Finds lines with error, ignoring case grep -v "^#" file1 Shows lines that do not start with # sed 's/old/new/g' file1 Replaces old with new and prints the result sed -i 's/old/new/g' file1 Replaces text directly in the file sed '/^$/d' file1 Removes empty lines awk '{print $1}' file1 Prints the first column sort file1 | uniq Sorts lines and removes duplicates sort file1 | uniq -c | sort -rn Counts repeated lines, most frequent first wc -l file1 Counts lines cut -d: -f1 /etc/passwd Prints the first field of each line (here, all usernames) diff file1 file2 Shows the differences between two files
Backup and Sync Command What it does rsync -av /var/www/ /backup/www/ Copies a directory and keeps permissions and timestamps rsync -avz --delete /var/www/ [email protected] :/backup/www/ Syncs a directory to another server over SSH scp file1 [email protected] :/tmp/ Copies a file to another server tar -czf - /var/www | ssh [email protected] "cat > /backup/www.tar.gz" Archives a directory straight to another server crontab -e Opens the cron schedule for regular backups
Getting Help Command What it does man ping Opens the manual for a command ping --help Shows a short help for a command apropos network Finds commands related to a keyword whatis ping Shows a one-line description of a command history Shows the command history alias ll='ls -la' Creates a shortcut for a command
Conclusion These commands cover most everyday tasks on a Linux server. To practice them on a real system, you can use a BlueVPS Linux VPS with full root access over SSH.
Blog