Linux Commands Cheat Sheet

Get more cheat sheets at UbuntuFree.com

1 Essential Linux Commands

Command Description Syntax Example pwd Show current directory path pwd /home/user ls List directory contents ls [options] ls -la

[directory]

cd Change directory cd [directory] cd /home mkdir Create a new directory mkdir [dir_name] mkdir test rmdir Delete an empty directory rmdir [dir_name] rmdir test touch Create an empty file touch [file_name] touch file.txt rm Delete files rm [file_name] rm file.txt cp Copy files/directories cp [src] [dest] cp a.txt b.txt mv Move/rename files mv [src] [dest] mv a.txt dir/ cat Display file contents cat [file] cat file.txt more View file contents page-wise more [file] more file.txt less View file contents (scroll) less [file] less file.txt head View first lines of file head [file] head -n 10

file.txt

tail View last lines of file tail [file] tail -n 10

file.txt

chmod Change file permissions chmod [mode] chmod 755

[file] script.sh

chown Change file owner chown [owner] chown user

[file] file.txt

chgrp Change file group chgrp [group] chgrp staff

[file] file.txt

ps Show running processes ps aux ps aux | grep

firefox

top Real-time process monitor top top htop Interactive process viewer htop htop kill Terminate process by PID kill [PID] kill 1234 killall Terminate all by name killall [name] killall firefox ping Send ICMP echo requests ping [host] ping google.com netstat Network connections info netstat -tulnp netstat -an ifconfig Configure network inter- ifconfig ifconfig eth0

faces [interface] ip Manage IP addresses ip addr ip route traceroute Trace route to host traceroute [host] traceroute

google.com

wget Download from web wget [url] wget

http://example.com

curl Transfer data from URL curl [url] curl example.com df Disk space usage df -h df -h du Directory size usage du -sh [dir] du -sh /home free Show memory usage free -h free -h uptime System uptime info uptime uptime uname System information uname -a uname -r vmstat System performance info vmstat vmstat 1 lscpu CPU architecture info lscpu lscpu history Show command history history history | grep ssh alias Create command shortcut alias gs=’git gs

status’

whoami Current logged in user whoami whoami who Show users logged in who who man Read command manual man [command] man ls echo Display a line of text echo [text] echo Hello date Show current date date date cal Display calendar cal cal 2025 locate Find files quickly locate [name] locate file.txt find Search files in directories find [path] -name find / -name test

[file]

grep Search inside files grep [pattern] grep "root"

[file] /etc/passwd

diff Compare file differences diff [file1] diff a.txt b.txt

[file2]

tar Archive files tar -cvf [archive] tar -cvf

[files] backup.tar dir/

gzip Compress files gzip [file] gzip file.txt gunzip Decompress .gz files gunzip [file.gz] gunzip file.gz zip Create zip archives zip [archive.zip] zip archive.zip

[files] file.txt

unzip Extract zip archives unzip unzip archive.zip

[archive.zip]

df Show disk usage df -h df -h du Estimate file space usage du -sh * du -sh /var umask Set default permissions umask [mask] umask 022