Essential Linux terminal commands for everyday use. File operations, text processing, networking, system administration, and more. Bookmark this page for quick reference.
File & Directory Operations
Command
Description
Example
ls
List directory contents
ls -la /var/log
cd
Change directory
cd /etc/nginx
pwd
Print current working directory
pwd
mkdir
Create a directory
mkdir -p src/components
rmdir
Remove an empty directory
rmdir old_folder
rm
Remove files or directories
rm -rf build/
cp
Copy files or directories
cp -r src/ backup/
mv
Move or rename files
mv old.txt new.txt
touch
Create an empty file or update timestamp
touch index.html
find
Search for files in a directory hierarchy
find . -name "*.log" -mtime -7
locate
Find files by name using a database
locate nginx.conf
tree
Display directory structure as a tree
tree -L 2 src/
File Viewing & Editing
Command
Description
Example
cat
Display file contents
cat /etc/hosts
less
View file with scrolling (forward and backward)
less /var/log/syslog
more
View file page by page (forward only)
more largefile.txt
head
Display first lines of a file
head -n 20 access.log
tail
Display last lines of a file
tail -f /var/log/syslog
nano
Simple terminal text editor
nano config.yaml
vim
Advanced terminal text editor
vim ~/.bashrc
wc
Count lines, words, and bytes
wc -l *.py
diff
Compare two files line by line
diff file1.txt file2.txt
sort
Sort lines of text
sort -n -r numbers.txt
uniq
Remove or report duplicate lines
sort data.txt | uniq -c
File Permissions
Command
Description
Example
chmod
Change file permissions
chmod 755 script.sh
chmod u+x
Add execute permission for owner
chmod u+x deploy.sh
chmod go-w
Remove write permission for group and others
chmod go-w config.ini
chmod 644
Owner read/write, group/others read only
chmod 644 index.html
chmod 700
Owner full access, no access for others
chmod 700 ~/.ssh
chown
Change file owner and group
chown www-data:www-data /var/www
chgrp
Change file group ownership
chgrp developers project/
umask
Set default file creation permissions
umask 022
Text Processing
Command
Description
Example
grep
Search for patterns in text
grep -rn "TODO" src/
grep -i
Case-insensitive pattern search
grep -i "error" log.txt
grep -v
Invert match (exclude pattern)
grep -v "^#" config.ini
sed
Stream editor for text transformation
sed 's/old/new/g' file.txt
sed -i
In-place file editing
sed -i 's/http/https/g' urls.txt
awk
Pattern scanning and processing
awk '{print $1, $3}' data.txt
awk -F
Set field separator
awk -F: '{print $1}' /etc/passwd
cut
Extract sections from lines
cut -d',' -f1,3 data.csv
tr
Translate or delete characters
echo "hello" | tr 'a-z' 'A-Z'
paste
Merge lines of files side by side
paste names.txt emails.txt
tee
Read stdin and write to stdout and files
ls | tee filelist.txt
xargs
Build command lines from standard input
find . -name "*.tmp" | xargs rm
System Information
Command
Description
Example
uname
Print system information
uname -a
hostname
Show or set system hostname
hostname -I
uptime
Show how long the system has been running
uptime
who
Show who is logged in
who -a
whoami
Print the current username
whoami
date
Display or set the system date and time
date "+%Y-%m-%d %H:%M:%S"
cal
Display a calendar
cal 2026
df
Report file system disk space usage
df -h
du
Estimate file and directory space usage
du -sh /var/log/*
free
Display memory usage
free -h
Process Management
Command
Description
Example
ps
Report current processes
ps aux | grep nginx
top
Real-time process monitoring
top -o %MEM
htop
Interactive process viewer (enhanced top)
htop
kill
Send a signal to a process
kill -9 12345
killall
Kill processes by name
killall node
jobs
List background jobs in current shell
jobs -l
bg
Resume a suspended job in the background
bg %1
fg
Bring a background job to the foreground
fg %1
nohup
Run a command immune to hangups
nohup python server.py &
&
Run a command in the background
./build.sh &
Networking
Command
Description
Example
ping
Test network connectivity
ping -c 4 google.com
curl
Transfer data from or to a server
curl -I https://example.com
wget
Download files from the web
wget -O file.zip https://example.com/dl
ssh
Secure shell remote login
ssh user@192.168.1.10
scp
Secure copy files between hosts
scp file.txt user@host:/tmp/
rsync
Fast, versatile remote file sync
rsync -avz src/ user@host:/backup/
netstat
Network statistics (legacy)
netstat -tlnp
ss
Socket statistics (modern netstat)
ss -tlnp | grep :80
ip
Show/manipulate network interfaces
ip addr show
dig
DNS lookup utility
dig example.com A +short
ifconfig
Configure network interfaces (legacy)
ifconfig eth0
Package Management (Debian/Ubuntu)
Command
Description
Example
apt update
Update the package index
sudo apt update
apt upgrade
Upgrade all installed packages
sudo apt upgrade -y
apt install
Install a package
sudo apt install nginx
apt remove
Remove a package (keep config files)
sudo apt remove nginx
apt purge
Remove a package and its config files
sudo apt purge nginx
apt search
Search for a package
apt search nodejs
apt list --installed
List all installed packages
apt list --installed | grep python
snap install
Install a snap package
sudo snap install code --classic
dpkg -i
Install a .deb package file
sudo dpkg -i package.deb
dpkg -l
List installed packages
dpkg -l | grep nginx
Compression & Archiving
Command
Description
Example
tar -czf
Create a gzipped tar archive
tar -czf backup.tar.gz /var/www
tar -xzf
Extract a gzipped tar archive
tar -xzf backup.tar.gz
tar -cjf
Create a bzip2 tar archive
tar -cjf archive.tar.bz2 folder/
tar -xjf
Extract a bzip2 tar archive
tar -xjf archive.tar.bz2
tar -tvf
List contents of a tar archive
tar -tvf archive.tar.gz
gzip
Compress a file with gzip
gzip access.log
gunzip
Decompress a gzip file
gunzip access.log.gz
zip
Create a zip archive
zip -r project.zip src/
unzip
Extract a zip archive
unzip project.zip -d output/
bzip2
Compress a file with bzip2
bzip2 largefile.txt
xz
Compress a file with xz (high compression)
xz -9 database.sql
User Management
Command
Description
Example
useradd
Create a new user account
sudo useradd -m -s /bin/bash john
usermod
Modify a user account
sudo usermod -aG docker john
userdel
Delete a user account
sudo userdel -r john
passwd
Change a user password
sudo passwd john
groups
Show group memberships for a user
groups john
sudo
Execute a command as superuser
sudo systemctl restart nginx
su
Switch to another user account
su - john
System Services (systemd)
Command
Description
Example
systemctl start
Start a service
sudo systemctl start nginx
systemctl stop
Stop a service
sudo systemctl stop nginx
systemctl restart
Restart a service
sudo systemctl restart nginx
systemctl status
Check the status of a service
systemctl status nginx
systemctl enable
Enable a service to start at boot
sudo systemctl enable nginx
systemctl disable
Disable a service from starting at boot
sudo systemctl disable nginx
systemctl list-units
List all active systemd units
systemctl list-units --type=service
journalctl
View systemd logs
journalctl -u nginx --since "1 hour ago"
journalctl -f
Follow system logs in real time
journalctl -fu nginx
Useful Keyboard Shortcuts
Shortcut
Description
Example Usage
Ctrl + C
Kill the current foreground process (SIGINT)
Stop a running command like ping
Ctrl + Z
Suspend the current process (SIGTSTP)
Pause vim, return with fg
Ctrl + D
Send EOF — close shell or end input
Exit a shell session or end cat input
Ctrl + R
Reverse search through command history
Type to find previous commands interactively
Ctrl + L
Clear the terminal screen
Same as typing clear
!!
Repeat the last command
sudo !! to re-run with sudo
!$
Last argument of the previous command
mkdir dir && cd !$
Tab
Auto-complete commands, paths, and filenames
Type sys then Tab for systemctl
Frequently Asked Questions
What is the difference between rm and rmdir in Linux?
rmdir only removes empty directories and will fail if the directory contains any files or subdirectories. rm -r (recursive) removes directories along with all their contents. Use rmdir for safety when you expect a directory to be empty, and rm -r when you intentionally want to delete everything inside. Always double-check before using rm -rf as it will not prompt for confirmation.
How do I find files by name in Linux?
Use the find command: find /path -name "filename". Use -iname for case-insensitive search. For example, find / -name "*.log" finds all .log files on the system. You can combine with other criteria like -type f (files only), -mtime -7 (modified in last 7 days), or -size +100M (larger than 100MB). The locate command is faster but uses a pre-built database that needs updating with sudo updatedb.
What do the chmod numbers like 755 and 644 mean?
Each digit represents permissions for owner, group, and others respectively. The values are sums of: 4 (read), 2 (write), 1 (execute). So 755 means the owner has full access (7=4+2+1), while group and others can read and execute (5=4+1). 644 means the owner can read and write (6=4+2), while group and others can only read (4). Use 755 for scripts and directories, 644 for regular files.
How do I check which process is using a specific port in Linux?
Use ss -tlnp | grep :PORT or netstat -tlnp | grep :PORT to find which process is listening on a specific port. For example, ss -tlnp | grep :80 shows what is using port 80. You can also use lsof -i :PORT. These commands typically require sudo to show full process details including the PID and program name.