Essential Linux Command-Line Tricks Every Sysadmin Should Know
This article compiles 73 practical Linux shell commands and tips, ranging from network checks and process management to file manipulation, version control, and system monitoring, providing sysadmins and developers with quick reference commands to enhance productivity and troubleshoot efficiently.
This collection provides useful Linux command-line shortcuts for various tasks.
1. Check if a remote port is open for bash:
echo >/dev/tcp/8.8.8.8/53 && echo "open"2. Send a process to the background:
Ctrl + z3. Bring a process to the foreground:
fg4. Generate a random hexadecimal string of length n:
openssl rand -hex n5. Execute commands from a file in the current shell:
source /home/user/file.name6. Extract the first 5 characters of a variable:
${variable:0:5}7. SSH debug mode:
ssh -vvv user@ip_address8. SSH with a PEM key:
ssh user@ip_address -i key.pem9. Use wget to download an entire website directory structure to a local folder:
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 the process tree including child processes:
ps axwef12. Create a WAR file:
jar -cvf name.war file13. 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/sda15. Get the MD5 hash of a text string:
echo -n "text" | md5sum16. Validate XML format:
xmllint --noout file.xml17. Extract a tar.gz archive into a new directory:
tar zxvf package.tar.gz -C new_dir18. Retrieve HTTP headers with curl:
curl -I http://www.example.com19. Change a file or directory timestamp (YYMMDDhhmm):
touch -t 0712250000 file20. Download files via FTP using wget:
wget -m ftp://username:password@hostname21. Generate a random password (example length 16 characters):
LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;22. Quickly backup a file:
cp some_file_name{,.bkp}23. Access a Windows shared directory:
smbclient -U "DOMAIN\user" //dc.domain.com/share/test/dir24. Execute a command from history (line 100):
!10025. Unzip a package to a directory:
unzip package_name.zip -d dir_name26. Input multiple lines of text (Ctrl + D to exit):
cat > test.txt27. Create an empty file or truncate an existing one:
> test.txt28. Sync time with Ubuntu NTP server:
ntpdate ntp.ubuntu.com29. Show all listening TCP4 ports with netstat:
netstat -lnt4 | awk '{print $4}' | cut -f2 -d: | grep -o '[0-9]*'30. Convert a 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 display its output (default every 2 seconds):
watch ps -ef32. List the first 10 largest files:
lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB " $9 }' | sort -n -u | tail33. Show remaining memory in MB:
free -m | grep cache | awk '/[0-9]/{ print $4" MB" }'34. Open Vim and jump to the end of a file:
vim + some_file_name35. Clone a specific branch (master) with Git:
git clone [email protected]:name/app.git -b master36. Switch to another branch (develop) with Git:
git checkout develop37. Delete a local branch (myfeature) with Git:
git branch -d myfeature38. Delete a remote branch with Git:
git push origin :branchName39. Push a new branch to the remote server:
git push -u origin mynewfeature40. Print the last cat command from history:
!cat:p41. Run the last cat command from history:
!cat42. Find all empty subdirectories under /home/user:
find /home/user -maxdepth 1 -type d -empty43. Show lines 50‑60 of test.txt:
< test.txt sed -n '50,60p'44. Re‑execute the last command with sudo (e.g., sudo mkdir /root/test):
sudo !!45. Create a temporary RAM filesystem (ramdisk) after creating /tmpram directory:
mount -t tmpfs tmpfs /tmpram -o size=512m46. Grep whole words:
grep -w "name" test.txt47. Append text to a file with elevated privileges:
echo "some text" | sudo tee -a /path/file48. List all kill signal names:
kill -l49. Prevent the last session from being recorded in bash history:
kill -9 $$50. Scan a network for open ports:
nmap -p 8081 172.20.0.0/1651. Set Git email address:
git config --global user.email "[email protected]"52. Sync with master when you have unpublished commits:
git pull --rebase origin master53. Move all files containing "txt" in their name to /home/user:
find -iname "*txt*" -exec mv -v {} /home/user \;54. Display two files side by side, line by line:
paste test.txt test1.txt55. Show a progress bar for a file with pv:
pv data.log56. Send data to a Graphite server using netcat:
echo "hosts.sampleHost 10 `date +%s`" | nc 192.168.200.2 300057. Convert tabs to spaces:
expand test.txt > test1.txt58. Skip bash history for a command:
< space >cmd59. Return to the previous working directory:
cd -60. Split a large tar.gz file into 100 MB parts and re‑assemble:
split –b 100m /path/to/large/archive /path/to/output/files
cat files* > archive61. Get HTTP status code with curl:
curl -sL -w "%{http_code}
" www.example.com -o /dev/null62. Run MySQL secure installation to set root password and harden security:
/usr/bin/mysql_secure_installation63. When Ctrl + C does not work, use Ctrl + \:
Ctrl + \64. Get the owner of a file:
stat -c %U file.txt65. List block devices with filesystem information:
lsblk -f66. Find files whose names end with a space:
find . -type f -exec egrep -l " +$" {} \;67. Find files whose names contain a tab character:
find . -type f -exec egrep -l '\t' {} \;68. 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.
