- Basics & environment
- Filesystem navigation & file ops
- File viewing & processing
- Permissions & ownership
- Text editing and editors
- Searching (find/grep/locate)
- Compression & archiving
- Package management (apt/yum/dnf/pacman/rpm/dpkg)
- Users & groups
- Processes & job control
- Systemctl & services
- Networking
- Disk, partitions & filesystems
- Logs & journal
- Boot & kernel
- Security: sudo, SELinux, AppArmor
- Bash shell basics & scripting utilities
- Misc tools (curl/wget/rsync/screen/tmux)
- Troubleshooting & debugging
- Handy combos & best practices
Linux basics help you understand the system identity, time, environment variables, and general info.
pwd # Shows the full path of the current working directory
whoami # Prints the logged-in username
hostname # System hostname
uname -a # Kernel name, version, architecture
date # Display system date and time
uptime # Shows uptime + load average (system load)
env # List all environment variables
export VAR=value # Set an environment variable for current session
printenv VAR # Display a specific environment variable
clear # Clear terminal screen
Move around directories, create, modify and delete files/folders.
ls # List directory contents
ls -l # Long listing (permissions, owner, size)
ls -la # Include hidden files (starting with .)
cd /path # Change directory to the given path
cd .. # Go back one directory
mkdir folder # Create a folder
mkdir -p a/b/c # Create nested directories
touch file # Create an empty file or update timestamp
cp src dest # Copy file
cp -r dir1 dir2 # Copy directory recursively
mv old new # Move or rename file/directory
rm file # Delete file
rm -rf folder # Delete directory recursively (force)
ln -s target linkname # Create a symbolic link
file filename # Detect file type (binary/text/script)
Used for reading, paging, slicing, combining or manipulating text.
cat file # Print file contents
tac file # Print file in reverse order
less file # View file with scroll option
head -n 20 file # Show first 20 lines
tail -n 20 file # Show last 20 lines
tail -f file # Follow file changes (logs)
cut -d',' -f2 file # Cut CSV file and show 2nd column
sort file # Sort lines alphabetically
sort -n file # Numeric sort
uniq file # Remove duplicate lines
uniq -c file # Count repeated lines
tr a-z A-Z < file # Convert lowercase → uppercase
wc -l file # Count number of lines
paste file1 file2 # Merge lines side-by-side
tee output.txt # Save AND display output
Linux permissions manage who can read/write/execute a file.
r = read
w = write
x = execute
ls -l # Show permissions (rwxr-xr-x)
chmod 755 file # Owner: rwx, group/others: rx
chmod u+rwx file # Add permissions symbolically
chmod g-w file # Remove write from group
chown user:group file # Change file owner & group
chgrp group file # Change group only
umask 022 # Default file creation mask (removes write for group/others)
getfacl # Show ACL permissions
setfacl -m u:user:rw file # Add custom ACL for a user
Nano (easy editor)
nano file # Open file
# Ctrl+O save, Ctrl+X exit, Ctrl+K cut, Ctrl+U paste
vim file # Open file in Vim
# i → insert mode
# Esc → exit insert mode
# :w → save
# :q → quit
# :wq → save & quit
# yy → copy line
# dd → delete line
# p → paste
grep → search inside files
grep "text" file # Search for text
grep -i "text" file # Case-insensitive
grep -n "text" file # Show line numbers
grep -R "text" . # Search recursively in directory
find /path -name "*.log" # Find log files
find . -type f -size +50M # Files larger than 50MB
find . -mtime -2 # Files modified in last 2 days
find . -name "*.tmp" -exec rm {} \; # Delete matching files
locate filename # Search from DB (very fast)
sudo updatedb # Update file database
tar -cvf archive.tar dir/ # Create tar
tar -xvf archive.tar # Extract tar
tar -czvf archive.tar.gz dir/ # Create gzip tar
tar -xzvf archive.tar.gz # Extract gzip tar
zip -r archive.zip dir/ # Zip folder
unzip archive.zip # Extract zip
gzip file # Compress file
gunzip file.gz # Extract gzip
sudo apt upgrade
sudo apt install package
sudo apt remove package
dpkg -i file.deb
dpkg -l | grep name
sudo yum install package
sudo dnf install package
sudo yum update
rpm -ivh file.rpm
rpm -qa | grep name
sudo pacman -S package
sudo pacman -Syu # full update
useradd username # add user
adduser username # friendlier version (Debian)
passwd username # set password
userdel username # delete user
usermod -aG group user # add user to group
groups username # list groups
sudo visudo # edit sudo permissions safely
su - username # switch user
ps aux # list all processes
ps -ef # alternative view
top # CPU/memory usage
htop # improved top (if installed)
kill PID # stop process
kill -9 PID # force kill
pkill processname # kill by name
command & # run in background
jobs # list background jobs
fg %1 # bring job to foreground
bg %1 # resume job in background
systemctl status service # service status
systemctl start service # start
systemctl stop service # stop
systemctl restart service # restart
systemctl enable service # start at boot
systemctl disable service # disable at boot
systemctl daemon-reload # reload systemd configs
systemctl --failed # list failed units
ip a # show active interfaces
ip route # routing table
ip neigh # ARP table
ss -tulnp # listening ports (modern)
netstat -tulnp # old alternative
ping host # test connectivity
traceroute host # show path
dig domain # DNS lookup
nslookup domain # alternative
ssh user@host # remote login
ssh -i key.pem user@host # login with key
scp file user@host:/path/ # secure copy
rsync -avz src/ dest/ # efficient file sync
du -sh * # folder sizes
lsblk # list block devices
fdisk -l # partition info
mkfs.ext4 /dev/sda1 # create ext4 FS
mount /dev/sda1 /mnt # mount filesystem
umount /mnt # unmount
blkid # show UUIDs
fsck -f /dev/sda1 # filesystem check
resize2fs /dev/sda1 # resize ext FS
xfs_growfs /mountpoint # resize XFS
ournalctl # system logs via journal
journalctl -u sshd # service-specific logs
journalctl -f # follow logs (like tail -f)
journalctl --since "1 hour ago" # time-filtered logs
tail -f /var/log/syslog # Debian/Ubuntu logs
tail -f /var/log/messages # RHEL/CentOS logs
dmesg -T # kernel logs in readable format
uname -r # kernel version
dmesg # kernel ring buffer
systemd-analyze # boot-up performance
systemd-analyze blame # which services slowed boot
update-grub (Debian/Ubuntu) # update bootloader config
grub2-mkconfig -o /boot/grub2/grub.cfg # RHEL/Fedora
reboot # restart system
poweroff # shutdown system
sudo command # run command as root
sudo -i # open root shell
sudo -u user command # run as another user
sudo visudo # safely edit sudoers file
getenforce # check mode (Enforcing/Permissive)
setenforce 0 # set permissive mode temporarily
sestatus # detailed SELinux status
semanage port -l # list allowed ports
semanage port -a -t http_port_t -p tcp 8081 # allow new port
restorecon -Rv /var/www # restore security contexts
audit2why -a # explain access denials
audit2allow -a -M mypol # generate allow policy module
aa-status # show active profiles
aa-complain <prog> # disable blocking, log only
aa-enforce <prog> # enforce security
aa-disable <prog> # disable profile
ip a # show interfaces
ip route # show routing table
ip neigh # ARP table
hostnamectl # hostname info
ping host
traceroute host
tracepath host
ss -tulnp # show listening ports
netstat -tulnp # older tool
tcpdump -i eth0 # capture packets
tcpdump -nn port 80 # capture HTTP traffic
dig domain.com
nslookup domain.com
host domain.com
scp file user@host:/path/
rsync -avz /src/ /dest/
sftp user@host
curl -I https://site.com # headers
curl -O https://site.com/file # download
curl -X POST -d "a=1&b=2" URL
wget -c URL # continue download
wget -r URL # recursive download
ps aux
top
htop
free -h
df -h
vmstat 1
iostat -x 1
mpstat -P ALL 1
dmesg -T
journalctl -xe
journalctl -u sshd
tail -f /var/log/syslog
lsof -i :8080 # who is using port 8080
ss -lptn # listening sockets
strace command # trace syscalls
strace -p <pid> # attach to running program
ltrace command # trace library calls
watch -n 1 'df -h'
inotifywait -m /path
du -sh * # size of files/folders
lsblk # block devices
blkid # filesystem UUIDs
mount /dev/sda1 /mnt
umount /mnt
mount -o loop disk.img /mnt
mkfs.ext4 /dev/sda1
mkfs.xfs /dev/xvdf1
fsck -f /dev/sda1
e2fsck -f /dev/sda1
badblocks -v /dev/sda1
resize2fs /dev/sda1 # EXT
xfs_growfs /mountpoint # XFS
fsfreeze -f /mount
fsfreeze -u /mount