Linux Commands Guide (Detailed with Examples)
Command Description Example
File and Directory Management
pwd Prints the current working directory. Example: pwd
ls Lists files and directories. Example: ls -l
cd [directory] Changes to the specified directory. Example: cd /home/user
mkdir [dir] Creates a new directory. Example: mkdir my_folder
rm -r [dir] Deletes a directory and its contents. Example: rm -r old_folder
cp [source] [destination] Copies files or directories. Example: cp file.txt /backup/
mv [source] [destination] Moves or renames files. Example: mv old.txt new.txt
User Management
whoami Displays the current user. Example: whoami
id Shows user ID and group ID. Example: id
sudo [command] Runs a command as a superuser. Example: sudo apt update
passwd Changes the user password. Example: passwd
adduser [username] Creates a new user. Example: adduser john
deluser [username] Deletes a user. Example: deluser john
usermod -aG [group] [user] Adds a user to a group. Example: usermod -aG sudo john
Process Management
ps Lists running processes. Example: ps aux
top Shows real-time system processes. Example: top
kill [PID] Terminates a process by ID. Example: kill 1234
pkill [process-name] Kills a process by name. Example: pkill firefox
htop Interactive process viewer. Example: htop
Networking
ping [host] Checks network connectivity. Example: ping google.com
ifconfig Displays network interfaces. Example: ifconfig eth0
wget [URL] Downloads a file from a URL. Example: wget http://example.com/file.zip
scp [file] [user@host:/path] Securely copies files over SSH. Example: scp file.txt user@server:/home/use
ssh user@host Logs into a remote server via SSH. Example: ssh [email protected]
Package Management
apt update Updates package lists (Debian-based). Example: apt update
apt upgrade Upgrades installed packages. Example: apt upgrade
yum install [package] Installs a package (Red Hat-based). Example: yum install nano
dnf remove [package] Removes a package (Fedora-based). Example: dnf remove vim
File Compression
tar -cvf archive.tar [files] Creates a tar archive. Example: tar -cvf backup.tar my_folder
tar -xvf archive.tar Extracts a tar archive. Example: tar -xvf backup.tar
zip [file.zip] [files] Creates a zip file. Example: zip archive.zip file1.txt file2.txt
unzip [file.zip] Extracts a zip file. Example: unzip archive.zip
System Monitoring
uptime Shows system uptime. Example: uptime
df -h Displays disk space usage. Example: df -h
free -m Shows memory usage. Example: free -m
journalctl -xe Views system logs. Example: journalctl -xe
dmesg Displays boot logs. Example: dmesg | tail
Shell Scripting
echo Prints text to the terminal. Example: echo 'Hello, World!'
read Reads user input. Example: read name; echo 'Hello, $name'
chmod +x script.sh Makes a script executable. Example: chmod +x my_script.sh
./script.sh Runs a script. Example: ./my_script.sh
System Administration
shutdown -h now Shuts down the system immediately. Example: shutdown -h now
reboot Restarts the system. Example: reboot
who Shows logged-in users. Example: who
groups Lists groups of a user. Example: groups john