Linux · CLI · System Administration · DevOps

Linux Commands
Cheatsheet

A comprehensive quick reference for essential Linux CLI commands — covering file operations, permissions, processes, networking, text processing, and system info.

OS: Linux / Unix
Shell: bash / sh / zsh
Level: Beginner → Advanced
Sections: 8
GeeksforGeeks Guide

What is the Linux CLI?

The Linux Command Line Interface (CLI) is a text-based interface for interacting with the operating system. Unlike graphical interfaces, the CLI gives you direct control over the system through commands typed in a terminal or shell (typically Bash).

Why use it? The CLI is faster, scriptable, more powerful, and often the only interface available on servers. Remote servers (SSH), containers (Docker), and cloud infrastructure are predominantly managed via CLI.

Real-world use: System administrators, DevOps engineers, security analysts, developers, and penetration testers all rely on Linux CLI daily. It is tested in CompTIA Linux+, RHCSA, and OSCP certifications.

Server administration & DevOps
Security analysis & pentesting
Scripting & automation
Cloud & container management
50+
Commands
8
Categories
bash
Default Shell
POSIX
Standard
🔍

1. File Operations

CommandDescriptionExample
lsList files and directoriesls -la /etc
ls -laLong list with hidden filesls -la ~
cdChange directorycd /var/log
pwdPrint current working directorypwd
cpCopy file or directorycp file.txt /tmp/
cp -rCopy directory recursivelycp -r dir/ /backup/
mvMove or rename file/directorymv old.txt new.txt
rmRemove filerm file.txt
rm -rfRemove directory recursively (⚠️ dangerous)rm -rf /tmp/junk/
mkdirCreate directorymkdir -p /opt/app/logs
touchCreate empty file / update timestamptouch newfile.txt
findSearch files by name, type, sizefind / -name "*.conf" 2>/dev/null
locateFast file search using databaselocate passwd
ln -sCreate symbolic (soft) linkln -s /etc/nginx nginx_conf
du -shDisk usage of file/directorydu -sh /var/log/
df -hDisk free space (all mounts)df -h
statFile metadata (size, inode, timestamps)stat /etc/passwd
fileIdentify file typefile suspicious.bin

2. File Viewing & Text Processing

CommandDescriptionExample
catDisplay file contentscat /etc/hosts
lessScrollable file viewerless /var/log/syslog
headFirst N lines of filehead -20 access.log
tailLast N lines; -f to follow livetail -f /var/log/auth.log
grepSearch text with patterngrep -r "error" /var/log/
grep -iCase-insensitive searchgrep -i "fail" auth.log
grep -nShow line numbersgrep -n "root" /etc/passwd
awkPattern scanning & text processingawk '{print $1}' access.log
sedStream editor for text substitutionsed 's/foo/bar/g' file.txt
sortSort lines alphabetically/numericallysort -n numbers.txt
uniqRemove duplicate adjacent linessort ips.txt | uniq -c
cutExtract columns from textcut -d: -f1 /etc/passwd
wcWord/line/byte countwc -l access.log
diffCompare two files line by linediff file1.txt file2.txt
echoPrint text to stdoutecho "Hello" >> log.txt
teeRead stdin and write to file + stdoutls | tee output.txt
xargsBuild command from stdinfind . -name "*.log" | xargs rm

3. Permissions & Ownership

CommandDescriptionExample
chmodChange file permissionschmod 755 script.sh
chmod +xAdd execute permissionchmod +x deploy.sh
chownChange file ownerchown www-data:www-data /var/www/
chgrpChange group ownershipchgrp devs project/
umaskSet default permission maskumask 022
getfaclGet file ACLgetfacl /etc/passwd
setfaclSet file ACLsetfacl -m u:alice:rwx file
sudoExecute as superusersudo systemctl restart nginx
suSwitch usersu - alice
idShow current user UID/GID/groupsid
whoamiPrint current usernamewhoami
groupsList groups current user belongs togroups
# Permission notation: rwxrwxrwx → owner/group/others
# Octal: r=4, w=2, x=1
chmod 644 file.txt    # rw-r--r-- (owner rw, rest read)
chmod 755 script.sh   # rwxr-xr-x (owner rwx, rest rx)
chmod 600 id_rsa      # rw------- (SSH key must be 600)
chmod 777 public/     # rwxrwxrwx (⚠️ avoid in production)

4. Processes & System

CommandDescriptionExample
ps auxList all running processesps aux | grep nginx
topInteractive process monitortop
htopEnhanced interactive monitorhtop
killSend signal to process by PIDkill -9 1234
killallKill all processes by namekillall nginx
pkillKill process by name patternpkill -f "python app.py"
jobsList background jobsjobs
bg / fgBackground / foreground a jobbg %1
nohupRun process immune to hangupnohup ./server &
systemctlControl systemd servicessudo systemctl start ssh
serviceControl SysV servicessudo service apache2 restart
crontab -eEdit scheduled cron jobscrontab -e
free -hMemory usage (human-readable)free -h
uptimeSystem uptime and load avguptime
uname -aKernel and OS informationuname -a
lsofList open files and socketslsof -i :80

5. Networking

CommandDescriptionExample
ip addrShow IP addresses (modern)ip addr show eth0
ifconfigShow/configure interfaces (legacy)ifconfig -a
pingTest host reachabilityping -c 4 8.8.8.8
tracerouteTrace packet route to hosttraceroute google.com
netstat -tlnpListening ports (legacy)netstat -tlnp
ss -tlnpListening ports (modern)ss -tlnp
digDNS lookup (detailed)dig +short google.com
nslookupDNS lookup (interactive)nslookup google.com
curlTransfer data from URLcurl -I https://example.com
wgetDownload file from URLwget https://example.com/file.zip
sshSecure Shell remote loginssh [email protected]
scpSecure copy over SSHscp file.txt user@host:/tmp/
ncNetcat — TCP/UDP connectionsnc -lvnp 4444
iptables -LList firewall rulessudo iptables -L -n -v
hostnameShow or set hostnamehostname -I

6. Package Management

# Debian / Ubuntu (apt)
sudo apt update                  # refresh package index
sudo apt upgrade                 # upgrade installed packages
sudo apt install nginx           # install package
sudo apt remove nginx            # remove package
sudo apt purge nginx             # remove + config files
sudo apt autoremove              # remove orphaned deps
apt search nginx                 # search for package
dpkg -l | grep nginx             # check if installed

# Red Hat / CentOS (yum / dnf)
sudo dnf install httpd           # install package
sudo yum update                  # update all packages
rpm -qa | grep nginx             # list installed RPMs

7. Archives & Compression

# tar — tape archive
tar -czf archive.tar.gz dir/     # create gzip archive
tar -xzf archive.tar.gz          # extract gzip archive
tar -cjf archive.tar.bz2 dir/   # create bzip2 archive
tar -tf archive.tar.gz           # list contents without extracting
tar -xzf archive.tar.gz -C /tmp/ # extract to specific dir

# zip / unzip
zip -r backup.zip /var/www/      # create zip
unzip backup.zip -d /tmp/        # extract zip

# gzip / gunzip
gzip large_file.txt              # compress single file
gunzip large_file.txt.gz         # decompress

8. Redirects, Pipes & Shortcuts

# I/O Redirection
command > file.txt               # stdout to file (overwrite)
command >> file.txt              # stdout to file (append)
command 2> errors.txt            # stderr to file
command &> all.txt               # stdout + stderr to file
command < input.txt              # stdin from file

# Pipes
cmd1 | cmd2                      # pipe stdout to next command
ps aux | grep nginx | awk '{print $2}'

# Background / job control
command &                        # run in background
Ctrl+Z                           # suspend current job
Ctrl+C                           # interrupt (kill) current job
Ctrl+D                           # EOF / logout

# Useful shortcuts
!!                               # repeat last command
!$                               # last argument of previous cmd
history | tail -20               # recent command history
Ctrl+R                           # reverse search history
alias ll='ls -la'                # create command alias

📚 Further Learning