70+ Essential Linux Commands
File and Directory Commands
ls (Windows: dir) Lists files/directories.
# Basic: List files with details
ls -la
# Advanced: List recursively with file sizes
ls -lR --human-readable2. cd (Windows: cd)
Changes directory
# Basic: Navigate to a folder
cd /home/user
# Advanced: Switch to path with spaces
cd "/usr/local/share"mkdir (Windows: mkdir/md) Creates a directory.
# Basic: Create a single folder
mkdir data
# Advanced: Create nested folders
mkdir -p parent/child/grandchildrmdir (Windows: rmdir/rd) Deletes an empty directory.
# Basic: Remove empty folder
rmdir data
# Advanced: Remove non-empty folder
rm -r datarm (Windows: del) Deletes files.
# Basic: Delete a file
rm temp.txt
# Advanced: Delete all .log files silently
rm -f *.logcp (Windows: copy) Copies files.
# Basic: Copy a file
cp file.txt /mnt/backup
# Advanced: Copy multiple files with overwrite
cp -f *.txt /mnt/backupcp -r (Windows: xcopy) Copies directories recursively.
# Basic: Copy a directory
cp -r data /mnt/backup
# Advanced: Copy with hidden files and preserve attributes
cp -ra data /mnt/backupmv (Windows: move) Moves/renames files.
# Basic: Move a file
mv file.txt /mnt/archive
# Advanced: Rename multiple files
mv *.txt *.bakchmod (Windows: attrib) Changes file permissions.
# Basic: Make file executable
chmod +x script.sh
# Advanced: Set specific permissions recursively
chmod -R 644 datamv (Windows: ren) Renames files/directories.
# Basic: Rename a file
mv old.txt new.txt
# Advanced: Bulk rename files
for f in *2023*.txt; do mv "$f" "${f/2023/2024}"; doneSystem Information Commands
uname -a (Windows: systeminfo) Shows system information.
# Basic: Display kernel info
uname -a
# Advanced: Export detailed system info
lscpu && free -h > sysinfo.txthostname (Windows: hostname) Shows the system hostname.
# Basic: Get hostname
hostname
# Advanced: Log hostname in script
hostname > device.txtcat /etc/os-release (Windows: ver) Shows Debian version.
# Basic: Check OS version
cat /etc/os-release
# Advanced: Extract version name
grep PRETTY_NAME /etc/os-releaseenv (Windows: set) Manages environment variables.
# Basic: View all variables
env
# Advanced: Add custom path
export PATH=$PATH:/usr/local/binlscpu/lspci (Windows: wmic) Queries hardware details.
# Basic: Get CPU info
lscpu
# Advanced: List PCI devices
lspci -vwhoami (Windows: whoami) Shows the current user.
# Basic: Display username
whoami
# Advanced: Get user ID and groups
idps aux (Windows: tasklist) Lists running processes.
# Basic: Show all processes
ps aux
# Advanced: Filter specific process
ps aux | grep apache2Network Commands
ip addr (Windows: ipconfig) Shows network configuration.
# Basic: Display IP details
ip addr
# Advanced: Refresh network interface
sudo ip addr flush dev eth0 && sudo dhclient eth0ping (Windows: ping) Test network connectivity.
# Basic: Ping a website
ping -c 4 google.com
# Advanced: Continuous ping with timestamp
ping google.com | while read line; do echo "$(date): $line"; donetraceroute (Windows: tracert) Traces the route to a host.
# Basic: Trace to domain
traceroute google.com
# Advanced: Trace without DNS
traceroute -n 8.8.8.8ss (Windows: netstat) Shows network connections/ports.
# Basic: List active connections
ss -tuln
# Advanced: Show process IDs
ss -tulnpdig (Windows: nslookup) Queries DNS (install via
sudo apt install dnsutils).
# Basic: Resolve domain
dig google.com
# Advanced: Query a specific DNS server
dig @8.8.8.8 google.comip neigh (Windows: arp) Manages ARP cache.
# Basic: Show ARP table
ip neigh
# Advanced: Delete ARP entry
sudo ip neigh del 192.168.1.1 dev eth0ip route (Windows: route) Manages the routing table.
# Basic: Display routing table
ip route
# Advanced: Add persistent route
sudo ip route add 10.0.0.0/24 via 192.168.1.1mount (Windows: net use) Mounts network filesystems.
# Basic: Mount NFS share
sudo mount server:/share /mnt/share
# Advanced: Mount SMB with credentials
sudo mount -t cifs //server/share /mnt/share -o username=user,password=passss -tuln (Windows: netstat -an) Shows connections numerically.
# Basic: List listening ports
ss -tuln
# Advanced: Log connections
ss -tuln > netlog.txtnmcli (Windows: netsh) Configures network (install via
sudo apt install network-manager).
# Basic: Show Wi-Fi networks
nmcli dev wifi
# Advanced: Connect to Wi-Fi
nmcli con up id "MyWiFi"Disk and Drive Commands
fsck (Windows: chkdsk) Checks/repairs filesystem errors.
# Basic: Scan filesystem
sudo fsck /dev/sda1
# Advanced: Auto-repair on unmounted disk
sudo fsck -y /dev/sda1parted (Windows: diskpart) Manages disks/partitions (install via
sudo apt install parted).
# Basic: List partitions
parted /dev/sda print
# Advanced: Create partition
parted /dev/sda mkpart primary ext4 1MiB 100%mkfs (Windows: format) Formats a filesystem.
# Basic: Format to ext4
sudo mkfs.ext4 /dev/sdb1
# Advanced: Format with label
sudo mkfs.ext4 -L MyUSB /dev/sdb1e2label (Windows: label) Sets volume label.
# Basic: Change label
sudo e2label /dev/sdb1 MyDrive
# Advanced: Remove label
sudo e2label /dev/sdb1 ""blkid (Windows: vol) Shows volume information.
# Basic: Display volume UUID
blkid /dev/sda1
# Advanced: Pipe to file
blkid /dev/sda1 > volume.txttune2fs (Windows: fsutil) Manages ext filesystem properties.
# Basic: Check filesystem details
tune2fs -l /dev/sda1
# Advanced: Disable journaling
sudo tune2fs -O ^has_journal /dev/sda1Task and Process Management Commands
kill/pkill (Windows: taskkill) Terminates processes.
# Basic: Kill process by name
pkill apache2
# Advanced: Force-kill by PID
kill -9 1234Investigation Context: Monitor process termination with
auditd(install viasudo apt install auditd). Example rule to logkillactions:
sudo auditctl -a exit,always -F arch=b64 -S kill -k process_killCheck logs with: sudo ausearch -k process_kill.
crontab (Windows: schtasks) Manages scheduled tasks.
# Basic: Create daily task
crontab -e
0 9 * * * /usr/bin/firefox
# Advanced: List all cron jobs
crontab -lsystemctl (Windows: sc) Controls systemd services.
# Basic: Check service status
systemctl status ssh
# Advanced: Restart service
sudo systemctl restart sshshutdown (Windows: shutdown) Performs shutdown/restart.
# Basic: Shutdown in 1 minute
sudo shutdown -h +1
# Advanced: Cancel shutdown
sudo shutdown -cxdg-open (Windows: start) Opens files/programs.
# Basic: Open text file
xdg-open file.txt
# Advanced: Open URL in browser
xdg-open https://google.comread (Windows: pause) Pauses script for input.
# Basic: Pause script
read -p "Press Enter to continue..."
# Advanced: Timeout pause
read -t 10 -p "Press Enter or wait 10s..."sleep (Windows: timeout) Adds delay in scripts.
# Basic: Wait 10 seconds
sleep 10
# Advanced: Non-interactive delay
sleep 10 &User and Security Commands
useradd/usermod (Windows: net user) Manages user accounts.
# Basic: Add user
sudo useradd -m johndoe
# Advanced: Set password
sudo passwd johndoegroupadd/usermod (Windows: net localgroup) Manages group memberships.
# Basic: Add user to group
sudo usermod -aG sudo johndoe
# Advanced: List group members
getent group sudosudo -u (Windows: runas) Runs command as another user.
# Basic: Run command as user
sudo -u johndoe firefox
# Advanced: Run with preserved environment
sudo -u johndoe -E firefoxchmod (Windows: cacls) Modifies file permissions.
# Basic: Grant read access
chmod o+r file.txt
# Advanced: Deny execute recursively
chmod -R o-x datachown (Windows: icacls) Changes file ownership.
# Basic: Change owner
sudo chown johndoe file.txt
# Advanced: Change owner and group recursively
sudo chown -R johndoe:users dataloginctl lock-session (Windows: lock) Locks user session.
# Basic: Lock session
loginctl lock-session
# Advanced: Lock all sessions
loginctl lock-sessionsupdate-rc.d (Windows: gpupdate) Manages system services (Debian-specific).
# Basic: Enable service
sudo update-rc.d ssh enable
# Advanced: Disable serviceapparmor (Windows: secedit) Applies security profiles (install via
sudo apt install apparmor).
# Basic: Check AppArmor status
sudo aa-status
# Advanced: Enforce profile
sudo aa-enforce /etc/apparmor.d/usr.bin.firefoxPower and Shutdown Commands
upower (Windows: powercfg) Manages power settings (install via
sudo apt install upower).
# Basic: Show battery info
upower -i /org/freedesktop/UPower/devices/battery_BAT0
# Advanced: Monitor battery
upower -mshutdown -h now (Windows: shutdown /s /t 0) Immediate shutdown.
# Basic: Shutdown now
sudo shutdown -h now
# Advanced: Shutdown with message
sudo shutdown -h now "System maintenance"reboot (Windows: shutdown /r /t 0) Immediate restart.
# Basic: Restart now
sudo reboot
# Advanced: Restart with message
sudo shutdown -r now "Applying updates"loginctl terminate-session (Windows: shutdown /l) Logs off user.
# Basic: Terminate session
loginctl terminate-session self
# Advanced: Terminate specific session
loginctl terminate-session c1Troubleshooting Commands
fsck (Windows: sfc /scannow) Repairs filesystem.
# Basic: Check filesystem
sudo fsck /dev/sda1
# Advanced: Auto-repair
sudo fsck -y /dev/sda1dpkg --configure (Windows: DISM) Repairs package configurations.
# Basic: Check package status
dpkg -l | grep ^ii
# Advanced: Reconfigure broken packages
sudo dpkg --configure -adf/du (Windows: cleanmgr) Manages disk space.
# Basic: Check disk usage
df -h
# Advanced: Find large files
du -ah /home | sort -rh | headjournalctl (Windows: eventvwr) Views system logs.
# Basic: Show recent logs
journalctl -n 10
# Advanced: Filter by service
journalctl -u sshlscpu/lsmem (Windows: msinfo32) Shows system info.
# Basic: Display CPU info
lscpu
# Advanced: Export system info
lscpu && lsmem > sysinfo.txtAdvanced and Miscellaneous Commands
tree (Windows: tree) Displays folder structure (install via
sudo apt install tree).
# Basic: Show folder tree
tree /home/user
# Advanced: Include files
tree -f /home/userecho (Windows: echo) Displays messages or writes to files.
# Basic: Print message
echo "Hello, World!"
# Advanced: Append to file
echo "Log entry" >> log.txtclear (Windows: cls) Clears terminal screen.
# Basic: Clear screen
clear
# Advanced: Clear in script
echo "Clearing..." && cleartitle (Windows: title) Sets terminal title (bash-specific).
# Basic: Set title
echo -ne "\033]0;My Script\007"
# Advanced: Dynamic title
echo -ne "\033]0;Backup_$(date)\007"tput (Windows: color) Changes terminal colors.
# Basic: Green text
tput setaf 2
# Advanced: Blue on white
tput setaf 4 && tput setab 7exit (Windows: exit) Closes terminal.
# Basic: Exit shell
exit
# Advanced: Exit with code
exit 1PS1 (Windows: prompt) Changes shell prompt.
# Basic: Set simple prompt
PS1='\u@\h:\w\$ '
# Advanced: Custom colored prompt
PS1='\[\e[32m\]\u@\h:\w\$\[\e[m\] 'man (Windows: help) Shows command help.
# Basic: Help for ls
man ls
# Advanced: Search manuals
man -k listScripting and Shell Commands
if (Windows: if) Conditional logic in scripts.
# Basic: Check file existence
if [ -f file.txt ]; then echo "Found"; fi
# Advanced: Check command success
if [ $? -eq 0 ]; then echo "Success"; fifor (Windows: for) Loops through values.
# Basic: List .txt files
for f in *.txt; do echo "$f"; done
# Advanced: Copy files recursively
for f in $(find . -name "*.txt"); do cp "$f" /mnt/backup; donefunction (Windows: goto) Defines functions for script flow.
# Basic: Call function
myfunc() { echo "Done"; }; myfunc
# Advanced: Conditional function call
[ $? -eq 1 ] && error || echo "OK"; error() { echo "Failed"; }source/. (Windows: call) Calls another script/function.
# Basic: Source script
source myscript.sh
# Advanced: Source with arguments
source myscript.sh --arg1local (Windows: setlocal/endlocal) Manages variable scope.
# Basic: Local variable
myfunc() { local var=123; echo $var; }; myfunc
# Advanced: Preserve variable
myfunc() { local var=$(date); echo $var > out.txt; }; myfuncBonus Useful Commands
tee (Windows: clip) Redirects to file and stdout.
# Basic: Pipe to file and screen
ls | tee out.txt
# Advanced: Append to file
ls | tee -a out.txtgrep (Windows: find) Searches text in files.
# Basic: Find text
grep "error" log.txt
# Advanced: Case-insensitive recursive search
grep -ri "error" /var/logfile (Windows: assoc) Shows file type.
# Basic: Check file type
file file.txt
# Advanced: Check multiple files
file *.txtlsmod (Windows: driverquery) Lists kernel modules.
# Basic: List modules
lsmod
# Advanced: Export to file
lsmod > modules.txtwmctrl (Windows: taskview) Manages windows/desktops (install via
sudo apt install wmctrl).
# Basic: List open windows
wmctrl -l
# Advanced: Switch to desktop
wmctrl -s 1Last updated