Linux Essential
Commands
1. User and Group Management
useradd
Creates a new user account.
Example: sudo useradd john
usermod
Modifies a user account.
Example: sudo usermod -aG sudo john
userdel
Deletes a user account.
Example: sudo userdel john
groupadd
Creates a new user group.
Example: sudo groupadd developers
groupdel
Deletes a group.
Example: sudo groupdel developers
chgrp
Changes the group ownership of a file.
Example: sudo chgrp developers [Link]
passwd
Changes a user's password.
Example: passwd john
who
Displays who is currently logged in.
Example: who
2. File and Directory Management
ls
Lists directory contents.
Example: ls -l /home
cd
Changes the current directory.
Example: cd /var/log
pwd
Prints the current directory.
Example: pwd
mkdir
Creates a directory.
Example: mkdir projects
rmdir
Removes an empty directory.
Example: rmdir old_folder
rm
Removes files or directories.
Example: rm -rf temp/
cp
Copies files or directories.
Example: cp [Link] backup/
mv
Moves or renames files.
Example: mv [Link] [Link]
touch
Creates an empty file or updates timestamp.
Example: touch [Link]
find
Searches for files or directories.
Example: find /home -name "*.log"
locate
Finds files by name using a database.
Example: locate [Link]
3. File Content Management
cat
Displays file contents.
Example: cat [Link]
more
Displays file contents page-by-page.
Example: more [Link]
less
Displays file contents with navigation.
Example: less [Link]
head
Shows the beginning of a file.
Example: head -n 10 [Link]
tail
Shows the end of a file.
Example: tail -n 10 [Link]
nano
Opens a file in the Nano text editor.
Example: nano [Link]
vi
Opens a file in the Vi editor.
Example: vi [Link]
ln
Creates hard or symbolic links.
Example: ln -s /var/log log_link
file
Identifies the file type.
Example: file [Link]
stat
Displays file metadata.
Example: stat [Link]
updatedb
Updates the locate database.
Example: sudo updatedb
xargs
Builds and executes commands from input.
Example: find . -name "*.tmp" | xargs rm
4. File Permissions and Ownership
chmod
Changes file permissions.
Example: chmod 755 [Link]
chown
Changes file ownership.
Example: chown john:admin [Link]
chgrp
Changes group ownership.
Example: chgrp developers [Link]
umask
Sets default permissions for new files.
Example: umask 022
getfacl
Displays file ACLs.
Example: getfacl [Link]
setfacl
Modifies file ACLs.
Example: setfacl -m u:john:rwx [Link]
ls -l
Lists files with permissions.
Example: ls -l /etc/passwd
stat
Displays detailed file info.
Example: stat [Link]
acl
General term referring to ACL management using
getfacl and setfacl.
5. Disk Management
df
Displays available disk space.
Example: df -h
du
Estimates file/directory size.
Example: du -sh /var/log
fdisk
Manages disk partitions.
Example: sudo fdisk /dev/sda
parted
Advanced partition tool.
Example: sudo parted /dev/sdb
lsblk
Lists block devices.
Example: lsblk
blkid
Displays block device attributes.
Example: sudo blkid
mount
Mounts a filesystem.
Example: sudo mount /dev/sdb1 /mnt
umount
Unmounts a filesystem.
Example: sudo umount /mnt
mkfs
Creates a new filesystem.
Example: sudo mkfs.ext4 /dev/sdb1
fsck
Checks and repairs filesystems.
Example: sudo fsck /dev/sda1
tune2fs
Adjusts filesystem parameters.
Example: sudo tune2fs -l /dev/sda1
resize2fs
Resizes a filesystem.
Example: sudo resize2fs /dev/sda1
lvcreate
Creates logical volumes (LVM).
Example: lvcreate -n lv_data -L 10G vg1
vgcreate
Creates volume groups.
Example: vgcreate vg1 /dev/sdb1
pvcreate
Initializes a physical volume for LVM.
Example: pvcreate /dev/sdb1
lsattr
Lists file attributes.
Example: lsattr [Link]
chattr
Changes file attributes.
Example: chattr +i [Link]
6. Process Management
ps
Shows running processes.
Example: ps aux
top
Interactive system process monitor.
Example: top
htop
Advanced interactive process viewer.
Example: htop
kill
Terminates a process by PID.
Example: kill 1234
killall
Kills processes by name.
Example: killall firefox
bg
Resumes suspended job in background.
Example: bg %1
fg
Brings background job to foreground.
Example: fg %1
nice
Starts process with custom priority.
Example: nice -n 10 ./[Link]
renice
Changes running process priority.
Example: renice -n 5 -p 1234
jobs
Lists current jobs.
Example: jobs
pgrep
Finds process IDs by name.
Example: pgrep nginx
pkill
Kills processes by name.
Example: pkill -f [Link]
pstree
Shows processes in tree format.
Example: pstree
lsof
Lists open files by processes.
Example: lsof -i :80
strace
Traces system calls of a process.
Example: strace ls
timeout
Runs a command with time limit.
Example: timeout 5 ping [Link]
watch
Runs a command at intervals.
Example: watch -n 2 date
7. Network Management
ifconfig
Displays or configures network interfaces.
Example: ifconfig eth0
ip a
Shows network interfaces and IPs.
Example: ip a
ip r
Displays routing table.
Example: ip r
ip link set <interface> up/down
Enables/disables network interface.
Example: ip link set eth0 down
ping
Sends ICMP echo request.
Example: ping [Link]
traceroute
Shows network path to host.
Example: traceroute [Link]
netstat -tulnp
Lists ports and services.
Example: netstat -tulnp
ss -tulnp
Displays socket stats.
Example: ss -tulnp
hostname -I
Displays IP addresses.
Example: hostname -I
dig
Queries DNS servers.
Example: dig [Link]
nslookup
Performs DNS lookup.
Example: nslookup [Link]
whois
Displays domain registration info.
Example: whois [Link]
curl -I
Fetches HTTP headers.
Example: curl -I [Link]
wget
Downloads files.
Example: wget [Link]
scp
Securely copies files.
Example: scp [Link] user@host:/home/user/
rsync
Efficiently syncs files/directories.
Example: rsync -avz /src/ user@host:/dest/
tcpdump
Captures network packets.
Example: tcpdump -i eth0
nmap
Scans hosts for open ports.
Example: nmap [Link]
8. System Monitoring
uptime
Shows system uptime.
Example: uptime
dmesg
Displays kernel ring buffer.
Example: dmesg | less
free -m
Displays memory usage in MB.
Example: free -m
vmstat
Reports system performance.
Example: vmstat 1 5
iostat
Shows CPU and I/O usage.
Example: iostat
mpstat
Displays CPU usage per processor.
Example: mpstat -P ALL
top
Monitors running processes.
Example: top
htop
Advanced interactive monitor.
Example: htop
sar -u 5 10
Monitors CPU usage at intervals.
Example: sar -u 5 10
iotop
Monitors disk I/O usage.
Example: iotop
lsof
Lists open files.
Example: lsof -u john
watch -n 2 <command>
Repeats command every 2 seconds.
Example: watch -n 2 df -h
journalctl -xe
Shows system logs with extra info.
Example: journalctl -xe
systemctl status
Checks status of a service.
Example: systemctl status ssh
service status
Legacy way to check services.
Example: service apache2 status
df -h
Shows disk usage.
Example: df -h
du -sh
Shows directory size.
Example: du -sh /var/log
ps aux --sort=-%mem
Lists processes sorted by memory.
Example: ps aux --sort=-%mem
9. Text Processing
cat
Displays file contents.
Example: cat [Link] — Prints the contents of
[Link].
tac
Displays file contents in reverse order.
Example: tac [Link] — Reverses the order of lines
in [Link].
head
Shows the first part of a file.
Example: head -n 5 [Link] — Displays the first 5
lines.
tail
Shows the last part of a file.
Example: tail -n 5 [Link] — Displays the last 5
lines.
tail -f
Monitors a file for real-time changes.
Example: tail -f /var/log/syslog — Follows the
syslog live.
grep
Searches for patterns in files.
Example: grep 'error' [Link] — Finds lines
with 'error'.
grep -r
Recursively searches directories.
Example: grep -r 'TODO' /project — Finds all
TODO comments.
awk
Pattern scanning and processing language.
Example: awk '{print $1, $3}' [Link] —
Prints first and third fields.
sed
Stream editor for filtering text.
Example: sed 's/foo/bar/g' [Link] —
Replaces 'foo' with 'bar'.
cut
Cuts sections from each line.
Example: cut -d':' -f1 /etc/passwd — Displays
only usernames.
sort
Sorts lines in text files.
Example: sort [Link] — Alphabetically sorts file.
uniq
Filters duplicate lines.
Example: sort [Link] | uniq — Removes
duplicates.
wc -l
Counts lines in a file.
Example: wc -l [Link] — Outputs number of lines.
wc -w
Counts words in a file.
Example: wc -w [Link] — Outputs word count.
wc -c
Counts bytes in a file.
Example: wc -c [Link] — Outputs file size in bytes.
tr
Translates or deletes characters.
Example: tr 'a-z' 'A-Z' < [Link] — Converts
lowercase to uppercase.
diff
Compares two files line by line.
Example: diff [Link] [Link] — Shows
differences.
cmp
Compares files byte by byte.
Example: cmp [Link] [Link] — Returns first
mismatch.
tee
Saves output to file and displays it.
Example: echo 'Log entry' | tee [Link] —
Outputs and writes to file.
10. Package Management
For Debian-based systems:
apt update
Updates package lists.
Example: sudo apt update — Refreshes available
packages.
apt upgrade
Upgrades all installed packages.
Example: sudo apt upgrade — Installs latest versions.
apt install
Installs a package.
Example: sudo apt install curl — Installs curl.
apt remove
Removes a package.
Example: sudo apt remove nano — Uninstalls nano.
apt purge
Removes package and config files.
Example: sudo apt purge apache2 — Cleans
Apache fully.
dpkg -i
Installs .deb files manually.
Example: sudo dpkg -i [Link] — Installs
local package.
dpkg -r
Removes a package.
Example: sudo dpkg -r package — Deletes
package.
dpkg -l
Lists all installed packages.
Example: dpkg -l — Displays installed package list.
apt-cache search
Searches for packages.
Example: apt-cache search nginx — Finds nginx
packages.
apt autoremove
Cleans up unused dependencies.
Example: sudo apt autoremove — Frees disk space.
apt clean
Cleans package cache.
Example: sudo apt clean — Removes cached .deb
files.
For RHEL-based systems:
yum update / dnf update
Updates installed packages.
Example: sudo dnf update — Updates all packages.
yum install / dnf install
Installs new packages.
Example: sudo dnf install git — Installs Git.
yum remove / dnf remove
Removes installed packages.
Example: sudo yum remove vim — Uninstalls vim.
rpm -ivh
Installs .rpm package.
Example: sudo rpm -ivh [Link] — Installs a local
.rpm file.
rpm -e
Erases a package.
Example: sudo rpm -e package — Removes an rpm
package.
yum list installed / dnf list installed
Lists all packages.
Example: dnf list installed — Shows installed
software.
yum search / dnf search
Searches the repository.
Example: yum search python — Finds Python-related
packages.
yum clean all
Cleans all cached data.
Example: sudo yum clean all — Frees up space.
11. Archive and Compression
tar -cvf
Creates a tar archive.
Example: tar -cvf [Link] folder/ —
Archives folder.
tar -xvf
Extracts a tar archive.
Example: tar -xvf [Link] — Extracts contents.
tar -tvf
Lists contents of a tar archive.
Example: tar -tvf [Link] — Views file list.
tar -czvf
Creates a compressed archive.
Example: tar -czvf [Link] folder/ —
Compresses to .[Link].
tar -xzvf
Extracts compressed archive.
Example: tar -xzvf [Link] — Unpacks
gzip tarball.
tar -cJvf
Creates a [Link] archive.
Example: tar -cJvf [Link] folder/ —
Compresses to .xz format.
tar -xJvf
Extracts [Link] archive.
Example: tar -xJvf [Link] — Unpacks xz
archive.
zip
Creates a zip archive.
Example: zip [Link] file1 file2 —
Compresses files.
unzip
Extracts files from zip archive.
Example: unzip [Link] — Extracts zip contents.
unzip -l
Lists contents of a zip.
Example: unzip -l [Link] — Views inside
archive.
zip -r
Recursively zips a directory.
Example: zip -r [Link] project/ — Zips
entire folder.
gzip
Compresses a file.
Example: gzip [Link] — Creates [Link].
gunzip
Decompresses a gzip file.
Example: gunzip [Link] — Restores original file.
bzip2
Compresses with bzip2.
Example: bzip2 bigfile — Makes bigfile.bz2.
bunzip2
Decompresses bzip2 file.
Example: bunzip2 bigfile.bz2 — Restores bigfile.
12. Shutdown and Reboot
shutdown -h now
Shuts down the system immediately.
Example: sudo shutdown -h now
shutdown -h +10
Schedules shutdown after 10 minutes.
Example: sudo shutdown -h +10
shutdown -h 22:00
Schedules shutdown at a specific time.
Example: sudo shutdown -h 22:00
shutdown -c
Cancels a scheduled shutdown.
Example: sudo shutdown -c
poweroff
Powers off the machine.
Example: sudo poweroff
halt
Stops all processes and halts.
Example: sudo halt
reboot
Reboots the system.
Example: sudo reboot
shutdown -r now
Immediate reboot.
Example: sudo shutdown -r now
shutdown -r +5
Reboot in 5 minutes.
Example: sudo shutdown -r +5
systemctl reboot
Systemd reboot command.
Example: sudo systemctl reboot
13. Task Scheduling
crontab -e
Edits cron jobs.
Example: crontab -e — Adds a scheduled task.
crontab -l
Lists scheduled tasks.
Example: crontab -l — Displays your cron jobs.
crontab -r
Removes all cron jobs.
Example: crontab -r — Deletes your entire crontab.
crontab -u <user> -l
Lists cron jobs for a specific user.
Example: crontab -u john -l
at
Schedules a one-time task.
Example: echo "shutdown -h now" | at 10:30
14. System Diagnostics and Troubleshooting
journalctl -xe
Views detailed logs.
Example: journalctl -xe — Useful for errors.
journalctl -f
Follows logs live.
Example: journalctl -f — Similar to tail -f.
journalctl --since "1 hour ago"
Shows logs from the past hour.
Example: journalctl --since "1 hour ago"
dmesg | less
Views boot and hardware logs.
Example: dmesg | less
dmesg | grep error
Filters kernel logs for errors.
Example: dmesg | grep error
cat /var/log/syslog
Displays general system log (Debian).
Example: cat /var/log/syslog
cat /var/log/messages
Displays system logs (RHEL).
Example: cat /var/log/messages
uptime
Shows system uptime and load.
Example: uptime
free -m
Displays memory usage in MB.
Example: free -m
top
Real-time process and usage monitor.
Example: top
htop
Improved real-time monitor.
Example: htop
vmstat
System performance metrics.
Example: vmstat 1 5
iostat
CPU and disk usage.
Example: iostat