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
Play Slideshow
Start Quiz
🔍
1. File Operations
Command Description Example
ls List files and directories ls -la /etc
ls -la Long list with hidden files ls -la ~
cd Change directory cd /var/log
pwd Print current working directory pwd
cp Copy file or directory cp file.txt /tmp/
cp -r Copy directory recursively cp -r dir/ /backup/
mv Move or rename file/directory mv old.txt new.txt
rm Remove file rm file.txt
rm -rf Remove directory recursively (⚠️ dangerous) rm -rf /tmp/junk/
mkdir Create directory mkdir -p /opt/app/logs
touch Create empty file / update timestamp touch newfile.txt
find Search files by name, type, size find / -name "*.conf" 2>/dev/null
locate Fast file search using database locate passwd
ln -s Create symbolic (soft) link ln -s /etc/nginx nginx_conf
du -sh Disk usage of file/directory du -sh /var/log/
df -h Disk free space (all mounts) df -h
stat File metadata (size, inode, timestamps) stat /etc/passwd
file Identify file type file suspicious.bin
2. File Viewing & Text Processing
Command Description Example
cat Display file contents cat /etc/hosts
less Scrollable file viewer less /var/log/syslog
head First N lines of file head -20 access.log
tail Last N lines; -f to follow live tail -f /var/log/auth.log
grep Search text with pattern grep -r "error" /var/log/
grep -i Case-insensitive search grep -i "fail" auth.log
grep -n Show line numbers grep -n "root" /etc/passwd
awk Pattern scanning & text processing awk '{print $1}' access.log
sed Stream editor for text substitution sed 's/foo/bar/g' file.txt
sort Sort lines alphabetically/numerically sort -n numbers.txt
uniq Remove duplicate adjacent lines sort ips.txt | uniq -c
cut Extract columns from text cut -d: -f1 /etc/passwd
wc Word/line/byte count wc -l access.log
diff Compare two files line by line diff file1.txt file2.txt
echo Print text to stdout echo "Hello" >> log.txt
tee Read stdin and write to file + stdout ls | tee output.txt
xargs Build command from stdin find . -name "*.log" | xargs rm
3. Permissions & Ownership
Command Description Example
chmod Change file permissions chmod 755 script.sh
chmod +x Add execute permission chmod +x deploy.sh
chown Change file owner chown www-data:www-data /var/www/
chgrp Change group ownership chgrp devs project/
umask Set default permission mask umask 022
getfacl Get file ACL getfacl /etc/passwd
setfacl Set file ACL setfacl -m u:alice:rwx file
sudo Execute as superuser sudo systemctl restart nginx
su Switch user su - alice
id Show current user UID/GID/groups id
whoami Print current username whoami
groups List groups current user belongs to groups
Copy
# 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
Command Description Example
ps aux List all running processes ps aux | grep nginx
top Interactive process monitor top
htop Enhanced interactive monitor htop
kill Send signal to process by PID kill -9 1234
killall Kill all processes by name killall nginx
pkill Kill process by name pattern pkill -f "python app.py"
jobs List background jobs jobs
bg / fg Background / foreground a job bg %1
nohup Run process immune to hangup nohup ./server &
systemctl Control systemd services sudo systemctl start ssh
service Control SysV services sudo service apache2 restart
crontab -e Edit scheduled cron jobs crontab -e
free -h Memory usage (human-readable) free -h
uptime System uptime and load avg uptime
uname -a Kernel and OS information uname -a
lsof List open files and sockets lsof -i :80
5. Networking
Command Description Example
ip addr Show IP addresses (modern) ip addr show eth0
ifconfig Show/configure interfaces (legacy) ifconfig -a
ping Test host reachability ping -c 4 8.8.8.8
traceroute Trace packet route to host traceroute google.com
netstat -tlnp Listening ports (legacy) netstat -tlnp
ss -tlnp Listening ports (modern) ss -tlnp
dig DNS lookup (detailed) dig +short google.com
nslookup DNS lookup (interactive) nslookup google.com
curl Transfer data from URL curl -I https://example.com
wget Download file from URL wget https://example.com/file.zip
ssh Secure Shell remote login ssh [email protected]
scp Secure copy over SSH scp file.txt user@host:/tmp/
nc Netcat — TCP/UDP connections nc -lvnp 4444
iptables -L List firewall rules sudo iptables -L -n -v
hostname Show or set hostname hostname -I
6. Package Management
Copy
# 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
Copy
# 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
Copy
# 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