
Linux is a powerhouse for developers, sysadmins, and ethical hackers. Knowing the right command-line tricks can significantly boost your productivity and make tasks much more efficient. Here are some of the best Linux command tricks to help you work smarter and faster! π₯
π‘ Want to learn Linux from scratch? Check out our book: Linux Playbook for Hackers β a practical guide to mastering Linux for cybersecurity enthusiasts! ππ¨βπ»
β
1οΈβ£ Use cd -
to Quickly Switch Between Directories
Instead of typing long paths, switch between the last two directories instantly:
cd -
πΉ Saves time when navigating between multiple folders.
β
2οΈβ£ Run the Last Command as Root (sudo !!
)
Ever run a command and forget sudo
? Instead of retyping, just use:
sudo !!
πΉ Re-executes the last command with root privileges.
β
3οΈβ£ Find Large Files Eating Up Space
To locate the biggest files on your system:
du -ah / | sort -rh | head -10
πΉ Helps you clean up disk space efficiently.
β
4οΈβ£ Kill a Process by Name (pkill
)
Instead of finding a process ID, kill a process by name:
pkill -9 process_name
πΉ Example: To kill Firefox, use pkill -9 firefox
.
β
5οΈβ£ Monitor Real-Time Disk Usage (iotop
)
To check which processes are using the most disk I/O:
sudo iotop
πΉ Useful for diagnosing slow system performance.
β
6οΈβ£ Repeat a Command Every X Seconds (watch
)
To monitor command output in real-time:
watch -n 2 df -h
πΉ Refreshes disk space usage (df -h
) every 2 seconds.
β
7οΈβ£ Download a File from the Internet (wget
)
To quickly download a file via the terminal:
wget https://example.com/file.zip
πΉ Useful for grabbing software or scripts directly from a URL.
β
8οΈβ£ Extract Any Archive with One Command
Instead of remembering different extraction commands, define this alias:
extract() {
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1";;
*.7z) 7z x "$1" ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
πΉ Now, just run extract filename.ext
to extract any archive easily.
β
9οΈβ£ Check System Uptime and Load (uptime
)
To see how long your system has been running:
uptime
πΉ Also shows system load averages.
β
π Find and Delete Files in One Command
To delete .log
files older than 7 days:
find /path/to/directory -name "*.log" -type f -mtime +7 -exec rm -f {} \;
πΉ Replace /path/to/directory
with your target folder.
β
π₯ Bonus Tricks!
πΉ Mastering the Power of alias
for Efficiency
Save time by creating shortcuts for frequently used commands. Add this to ~/.bashrc
or ~/.zshrc
:
alias ll="ls -lah"
alias update="sudo apt update && sudo apt upgrade -y"
πΉ Now, just type ll
for a detailed list or update
to update the system.
β
πΉ Automating Tasks with cron
Jobs
Want to automate backups or scripts? Use cron
:
crontab -e
Add a job that runs a script every day at midnight:
0 0 * * * /path/to/script.sh
πΉ Super useful for scheduling tasks automatically!
β
πΉ Using rsync
for Efficient File Synchronization
To sync files between two locations:
rsync -avz /source/path/ user@remote:/destination/path/
πΉ This is great for backups or transferring files between servers.
πΉ Monitoring System Resources with htop
For an interactive view of system performance:
htop
πΉ A better alternative to top
for checking CPU, memory, and processes.
β
Final Thoughts π‘
Mastering these Linux command tricks will make you more efficient and confident in managing your system. Whether youβre a sysadmin, hacker, or just love Linux, these commands will save you time and effort! π
π Want to Master Linux for Hacking?
If youβre serious about learning Linux for cybersecurity and hacking, check out our book:
π Linux Playbook for Hackers β A practical guide to mastering Linux commands, automation, and security!
Also, if youβre stepping into bug bounty, grab our Bug Bounty Beginner Edition book to kickstart your journey in ethical hacking! π
π¬ Which trick is your favorite? Let me know! π