Linux Commands Reference

Comprehensive reference for common Linux and Unix commands with examples.

Back to all tools on ToolForge

More in Developer Tools

About Linux Commands Reference

This reference provides a comprehensive list of essential Linux and Unix commands for file operations, text processing, system administration, and scripting. Commands work across most distributions including Ubuntu, Debian, CentOS, RHEL, Fedora, and macOS.

Command Syntax Conventions

Syntax Notation:
  command <arg>      - Required argument
  command [arg]      - Optional argument
  command [options]  - Optional flags
  file1|file2        - Either file1 or file2
  ...                - Repeatable argument

Examples:
  ls -la /home       - List with details in /home
  cat file.txt       - Display file contents
  grep "pattern" *   - Search pattern in all files

Essential Commands by Category

File & Directory Operations
CommandDescriptionExample
lsList directory contentsls -la
ls -laList all files with detailsls -la /etc
cd <dir>Change directorycd /var/log
pwdPrint working directorypwd
mkdir <name>Create directorymkdir -p project/src
rm <file>Remove filerm -rf temp/
cp <src> <dest>Copy filescp -r dir1 dir2
mv <src> <dest>Move/rename filesmv old.txt new.txt
touch <file>Create empty file/update timestamptouch file.txt
ln -s <src> <link>Create symbolic linkln -s /path/to/target link
cat <file>Display file contentscat file.txt
head -n N <file>First N lineshead -20 logfile.log
tail -n N <file>Last N linestail -f logfile.log
less <file>View file (scrollable)less largefile.txt
wc -l <file>Count lineswc -l file.txt
Search & Find
CommandDescriptionExample
find <path> -name <pattern>Find files by namefind . -name "*.log"
find . -type fFind all filesfind /var -type f
find . -type dFind all directoriesfind . -type d -name "src"
find . -mtime -NFiles modified N days agofind . -mtime -7
find . -size +N[M|G]Files larger than Nfind . -size +100M
grep <pattern> <file>Search text in filegrep "error" logfile
grep -r <pattern> .Recursive searchgrep -r "TODO" .
grep -i <pattern>Case-insensitive searchgrep -i "error"
grep -v <pattern>Inverse match (exclude)grep -v "^#" config
grep -n <pattern>Show line numbersgrep -n "main" *.c
which <command>Show command pathwhich python3
whereis <command>Find binary/source/manwhereis gcc
locate <name>Find by name (indexed)locate httpd.conf
Permissions & Ownership
CommandDescriptionExample
chmod <mode> <file>Change permissionschmod 755 script.sh
chmod +x <file>Add execute permissionchmod +x install.sh
chown <user>:<group> <file>Change ownershipchown www-data:www-data site/
chgrp <group> <file>Change groupchgrp developers project/
umask <value>Set default permissionsumask 022
ls -laView permissionsls -la file.txt
Process Management
CommandDescriptionExample
ps auxList all processesps aux | grep nginx
topLive process viewtop
htopInteractive process viewerhtop
kill <PID>Terminate processkill 1234
kill -9 <PID>Force killkill -9 1234
killall <name>Kill by namekillall chrome
pkill <pattern>Kill by patternpkill -f python3
pgrep <name>Find PID by namepgrep nginx
nohup <cmd>Run immune to hangupsnohup server.sh &
bgResume job in backgroundbg %1
fgBring job to foregroundfg %1
jobsList background jobsjobs -l
System Information
CommandDescriptionExample
uname -aSystem informationuname -a
hostnameShow/set hostnamehostname -I
uptimeSystem uptimeuptime
whoamiCurrent userwhoami
idUser/group IDsid
wLogged in usersw
lastLogin historylast -10
df -hDisk space (human-readable)df -h
du -sh <dir>Directory sizedu -sh /var/log
free -hMemory usagefree -h
vmstatVirtual memory statsvmstat 1 5
iostatI/O statisticsiostat -x 1
Network Commands
CommandDescriptionExample
ping <host>Test connectivityping -c 4 google.com
curl <url>Transfer datacurl -O https://example.com/file
wget <url>Download filewget -O file.zip URL
ssh <user>@<host>SSH connectionssh [email protected]
scp <src> <dest>Secure copyscp file.txt user@host:/path
rsync -av <src> <dest>Sync filesrsync -av src/ dest/
netstat -tulpnNetwork connectionsnetstat -tulpn | grep :80
ss -tulpnSocket statisticsss -tulpn
ip addrIP addressesip addr show
ip routeRouting tableip route show
dig <domain>DNS lookupdig example.com
nslookup <domain>DNS querynslookup google.com
traceroute <host>Trace routetraceroute google.com
Text Processing
CommandDescriptionExample
sort <file>Sort linessort -n numbers.txt
uniq <file>Remove duplicatessort file | uniq
cut -d : -f 1Extract fieldscut -d: -f1 /etc/passwd
paste <file1> <file2>Merge linespaste file1 file2
tr <set1> <set2>Translate characterstr 'a-z' 'A-Z'
sed 's/old/new/'Stream editorsed -i 's/foo/bar/g' file
awk '{print $1}'Pattern scanningawk '{sum+=$1} END {print sum}'
diff <file1> <file2>Compare filesdiff -u old.txt new.txt
comm <file1> <file2>Compare sorted filescomm -12 file1 file2
Archive & Compression
CommandDescriptionExample
tar -czf <out.tar.gz> <files>Create gzip archivetar -czf backup.tar.gz /data
tar -xzf <file.tar.gz>Extract gzip archivetar -xzf archive.tar.gz
tar -cjf <out.tar.bz2>Create bzip2 archivetar -cjf backup.tar.bz2 /data
gzip <file>Compress filegzip -9 file.txt
gunzip <file.gz>Decompress filegunzip file.gz
zip -r <out.zip> <files>Create ZIP archivezip -r archive.zip folder/
unzip <file.zip>Extract ZIPunzip archive.zip
Package Management
CommandDescriptionExample
apt updateUpdate package list (Debian/Ubuntu)apt update && apt upgrade
apt install <pkg>Install packageapt install nginx
apt remove <pkg>Remove packageapt remove nginx
yum install <pkg>Install package (RHEL/CentOS)yum install httpd
dnf install <pkg>Install package (Fedora)dnf install nginx
brew install <pkg>Install package (macOS/Homebrew)brew install node
pip install <pkg>Install Python packagepip install requests
npm install <pkg>Install Node packagenpm install express
User Management
CommandDescriptionExample
useradd <name>Create useruseradd -m john
userdel <name>Delete useruserdel -r john
passwd <name>Change passwordpasswd john
usermod -aG <grp> <usr>Add user to groupusermod -aG sudo john
groupadd <name>Create groupgroupadd developers
groups <name>Show user groupsgroups john
su - <user>Switch usersu - postgres
sudo <cmd>Execute as rootsudo systemctl restart nginx

Frequently Asked Questions

What is the purpose of the ls command?
The ls command lists directory contents. Common options: -l (long format with permissions), -a (show hidden files starting with .), -la (combine both), -lh (human-readable sizes), -R (recursive), -t (sort by time), -S (sort by size).
How do I find files in Linux?
Use the find command: 'find /path -name filename' searches by name, 'find . -type f' finds all files, 'find . -type d' finds directories, 'find . -mtime -7' finds files modified in last 7 days, 'find . -size +100M' finds files larger than 100MB.
What is the difference between chmod and chown?
chmod changes file permissions (read/write/execute), chown changes file ownership (user/group). Example: 'chmod 755 file' sets rwxr-xr-x permissions, 'chown user:group file' transfers ownership to specified user and group.
How do I view and search file contents?
cat displays entire file, head shows first N lines, tail shows last N lines, less allows scrolling, grep searches for patterns. Example: 'grep -r pattern .' searches recursively, 'tail -f logfile' follows log updates.
What are pipes and redirection?
Pipes (|) pass output from one command to another: 'ls | grep txt'. Redirection: > overwrites output to file, >> appends, 2> redirects errors, < reads from file. Example: 'command > file 2>&1' redirects both stdout and stderr.
How do I manage processes?
ps aux lists processes, top/htop shows live process view, kill PID terminates process, kill -9 PID force kills, pkill name kills by name, bg/fg manage background/foreground jobs, nohup runs commands immune to hangups.