Essential Linux Command Cheat Sheet: 73 Handy Bash Tips
A comprehensive cheat sheet of 73 practical Linux shell commands and techniques, covering networking checks, process control, file manipulation, system monitoring, Git operations, and more, to boost productivity for developers and system administrators.
1. Check if remote port is open for bash: echo >/dev/tcp/8.8.8.8/53 && echo "open" 2. Send a process to background: Ctrl+z 3. Bring a background process to foreground: fg 4. Generate a random hexadecimal string of n characters: openssl rand -hex n 5. Execute commands from a file in the current shell: source /home/user/file.name 6. Extract the first 5 characters of a variable: ${variable:0:5} 7. SSH debug mode (verbose): ssh -vvv user@ip_address 8. SSH with a PEM key: ssh user@ip_address -i key.pem 9. Download an entire website directory structure with wget:
wget -r --no-parent --reject "index.html*" http://hostname/ -P /home/user/dirs10. Create multiple directories at once: mkdir -p /home/user/{test,test1,test2} 11. List process tree including child processes: ps axwef 12. Create a WAR file: jar -cvf name.war file 13. Test disk write speed:
dd if=/dev/zero of=/tmp/output.img bs=8k count=256k; rm -rf /tmp/output.img14. Test disk read speed: hdparm -Tt /dev/sda 15. Get MD5 hash of a text string: echo -n "text" | md5sum 16. Validate XML format: xmllint --noout file.xml 17. Extract a tar.gz archive to a new directory: tar zxvf package.tar.gz -C new_dir 18. Retrieve HTTP headers with curl: curl -I http://www.example.com 19. Change file or directory timestamp (YYMMDDhhmm): touch -t 0712250000 file 20. Perform FTP download with wget: wget -m ftp://username:password@hostname 21. Generate a random password (default 16 characters):
LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16}; echo22. Quickly backup a file: cp some_file_name{,.bkp} 23. Access a Windows share directory: smbclient -U "DOMAIN\user" //dc.domain.com/share/test/dir 24. Execute a command from history (line 100): !100 25. Unzip an archive to a directory: unzip package_name.zip -d dir_name 26. Input multiple lines of text (Ctrl+D to exit): cat > test.txt 27. Create an empty file or truncate an existing one: > test.txt 28. Sync time with Ubuntu NTP server: ntpdate ntp.ubuntu.com 29. List all listening TCP4 ports:
netstat -lnt4 | awk '{print $4}' | cut -f2 -d: | grep -o '[0-9]*'30. Convert qcow2 image to raw format:
qemu-img convert -f qcow2 -O raw precise-server-cloudimg-amd64-disk1.img precise-server-cloudimg-amd64-disk1.raw31. Repeatedly run a command and show output (default every 2 seconds): watch ps -ef 32. List all users: getent passwd 33. Remount root filesystem as read/write: mount -o remount,rw / 34. Bind-mount a directory (no symlink): mount --bind /source /destination 35. Dynamically update DNS server:
nsupdate <<EOF
update add $HOST 86400 A $IP
send
EOF36. Recursively grep through all directories: grep -r "some_text" /path/to/dir 37. List top 10 largest files:
lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB " $9 }' | sort -n -u | tail38. Show remaining memory in MB: free -m | grep cache | awk '/[0-9]/{ print $4" MB" }' 39. Open Vim and jump to end of file: vim + some_file_name 40. Clone a specific Git branch (master): git clone [email protected]:name/app.git -b master 41. Switch to another Git branch (develop): git checkout develop 42. Delete a Git branch (myfeature): git branch -d myfeature 43. Delete a remote Git branch: git push origin :branchName 44. Push a new branch to remote: git push -u origin mynewfeature 45. Print the last "cat" command from history: !cat:p 46. Execute the last "cat" command from history: !cat 47. Find all empty subdirectories under /home/user: find /home/user -maxdepth 1 -type d -empty 48. Show lines 50‑60 of test.txt: sed -n '50,60p' test.txt 49. Run the previous command with sudo (e.g., mkdir): sudo !! 50. Create a temporary RAM disk (512 MiB): mount -t tmpfs tmpfs /tmpram -o size=512m 51. Grep whole words: grep -w "name" test.txt 52. Append text to a file with elevated privileges: echo "some text" | sudo tee -a /path/file 53. List all kill signal names: kill -l 54. Terminate the current Bash session: kill -9 $$ 55. Scan network for open ports (e.g., 8081): nmap -p 8081 172.20.0.0/16 56. Set Git user email: git config --global user.email "[email protected]" 57. Rebase local commits onto upstream master: git pull --rebase origin master 58. Move all files containing "txt" in their name to /home/user: find -iname "*txt*" -exec mv -v {} /home/user \; 59. Display files side‑by‑side (columnar): paste test.txt test1.txt 60. Show a progress bar for a file: pv data.log 61. Send metrics to a Graphite server via netcat:
echo "hosts.sampleHost 10 `date +%s`" | nc 192.168.200.2 300062. Convert tabs to spaces: expand test.txt > test1.txt 63. Skip Bash history for a command: < space >cmd 64. Return to previous working directory: cd - 65. Split a large tar.gz into 100 MiB parts and reassemble:
split –b 100m /path/to/large/archive /path/to/output/files
cat files* > archive66. Get HTTP status code with curl: curl -sL -w "%{http_code}\n" www.example.com -o /dev/null 67. Secure MySQL installation and set root password: /usr/bin/mysql_secure_installation 68. Force‑quit a hanging process when Ctrl+C fails: Ctrl+\ 69. Get file owner name: stat -c %U file.txt 70. List block devices with filesystem info: lsblk -f 71. Find files whose names end with a space: find . -type f -exec egrep -l " +$" {} \; 72. Find files with tab characters in their names: find . -type f -exec egrep -l $'\t' {} \; 73. Print a line of 100 equal signs:
printf '%100s
' | tr ' ' =Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
