Operations 13 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Essential Linux Command-Line Tricks Every Sysadmin Should Know

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 + z
3. Bring a process to the foreground:
fg
4. Generate a random hexadecimal string of length n:
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:
ssh -vvv user@ip_address
8. SSH with a PEM key:
ssh user@ip_address -i key.pem
9. 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/dirs
10. Create multiple directories at once:
mkdir -p /home/user/{test,test1,test2}
11. List the 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.img
14. Test disk read speed:
hdparm -Tt /dev/sda
15. Get the MD5 hash of a text string:
echo -n "text" | md5sum
16. Validate XML format:
xmllint --noout file.xml
17. Extract a tar.gz archive into 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 a file or directory timestamp (YYMMDDhhmm):
touch -t 0712250000 file
20. Download files via FTP using wget:
wget -m ftp://username:password@hostname
21. 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/dir
24. Execute a command from history (line 100):
!100
25. Unzip a package 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. 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.raw
31. Repeatedly run a command and display its output (default every 2 seconds):
watch ps -ef
32. List the first 10 largest files:
lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB " $9 }' | sort -n -u | tail
33. 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_name
35. Clone a specific branch (master) with Git:
git clone [email protected]:name/app.git -b master
36. Switch to another branch (develop) with Git:
git checkout develop
37. Delete a local branch (myfeature) with Git:
git branch -d myfeature
38. Delete a remote branch with Git:
git push origin :branchName
39. Push a new branch to the remote server:
git push -u origin mynewfeature
40. Print the last cat command from history:
!cat:p
41. Run the last cat command from history:
!cat
42. Find all empty subdirectories under /home/user:
find /home/user -maxdepth 1 -type d -empty
43. 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=512m
46. Grep whole words:
grep -w "name" test.txt
47. Append text to a file with elevated privileges:
echo "some text" | sudo tee -a /path/file
48. List all kill signal names:
kill -l
49. 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/16
51. Set Git email address:
git config --global user.email "[email protected]"
52. Sync with master when you have unpublished commits:
git pull --rebase origin master
53. 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.txt
55. Show a progress bar for a file with pv:
pv data.log
56. Send data to a Graphite server using netcat:
echo "hosts.sampleHost 10 `date +%s`" | nc 192.168.200.2 3000
57. Convert tabs to spaces:
expand test.txt > test1.txt
58. Skip bash history for a command:
< space >cmd
59. 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* > archive
61. Get HTTP status code with curl:
curl -sL -w "%{http_code}
" www.example.com -o /dev/null
62. Run MySQL secure installation to set root password and harden security:
/usr/bin/mysql_secure_installation
63. When Ctrl + C does not work, use Ctrl + \:
Ctrl + \
64. Get the owner of a file:
stat -c %U file.txt
65. List block devices with filesystem information:
lsblk -f
66. 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 ' ' =
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxSysadmin
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.