Essential Linux Bash Tips and Commands Every Sysadmin Should Know
A comprehensive cheat‑sheet of practical Linux Bash commands covering network checks, process control, file manipulation, Git operations, performance testing, and many other everyday sysadmin tasks, presented in concise examples for quick reference and efficient workflow.
This article collects a wide range of useful Linux Bash commands that can help system administrators and developers perform common tasks more efficiently.
Check if a remote port is open: echo >/dev/tcp/8.8.8.8/53 && echo "open" Suspend a process: Ctrl+z Bring a suspended process to the foreground: fg Generate a random hexadecimal string (n characters): openssl rand -hex n Source a file in the current shell (e.g., .bashrc, .bash_profile): source /home/user/file.name Extract the first five characters of a variable: ${variable:0:5} Enable SSH debug mode: ssh -vvv user@ip_address Connect via SSH using a PEM key: ssh user@ip_address -i key.pem Download a full directory tree with wget:
wget -r --no-parent --reject "index.html*" http://hostname/ -P /home/user/dirsCreate multiple directories at once: mkdir -p /home/user/{test,test1,test2} List processes in a tree view: ps axwef Create a WAR file: jar -cvf name.war file Test disk write speed:
dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync; rm -rf /tmp/output.imgTest disk read speed: hdparm -Tt /dev/sda Compute MD5 of a text string: echo -n "text" | md5sum Validate XML syntax: xmllint --noout file.xml Extract a tar.gz archive to a specific directory: tar zxvf package.tar.gz -C new_dir Get HTTP headers with curl: curl -I http://www.example.com Change file timestamps (YYMMDDhhmm format): touch -t 0712250000 file Download from FTP with wget: wget -m ftp://username:password@hostname Generate a random password (16 characters):
LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16}; echoQuickly backup a file (adds .bkp extension): cp some_file_name{,.bkp} Access a Windows share: smbclient -U "DOMAINuser" //dc.domain.com/share/test/dir Rerun a command from history (e.g., the 100th entry): !100 Unzip an archive to a directory: unzip package_name.zip -d dir_name Append text to a file with elevated privileges: echo "some text" | sudo tee -a /path/file List all supported kill signals: kill -l Generate a base64‑encoded random password (16 bytes): openssl rand -base64 16 Prevent the last command from being recorded in Bash history: kill -9 $$ Scan a network for open ports: nmap -p 8081 172.20.0.0/16 Configure Git email: git config --global user.email "[email protected]" Rebase the current branch onto master: git pull --rebase origin master Move all files containing "txt" in their name to /home/user: find -iname "*txt*" -exec mv -v {} /home/user \; Merge corresponding lines from two files: paste test.txt test1.txt Show a progress bar for a file: pv data.log Send data to a server with netcat:
echo "hosts.sampleHost 10 `date +%s`" | nc 192.168.200.2 3000Convert tabs to spaces: expand test.txt > test1.txt Print a horizontal line of "=" characters: printf '%100sn' | tr ' ' = Set up a temporary RAM disk (512 MiB): mount -t tmpfs tmpfs /tmpram -o size=512m Search for whole-word matches with grep: grep -w "name" test.txt List all users: getent passwd Remount the root filesystem as read‑write: mount -o remount,rw / Bind‑mount a directory (useful when symlinks fail): mount --bind /source /destination Send a DNS dynamic update: nsupdate < Recursively grep a pattern in all directories: grep -r "some_text" /path/to/dir List the ten largest open files (in MB):
lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB " $9 }' | sort -n -u | tailShow free memory in MB (cache column): free -m | grep cache | awk '/[0-9]/{ print $4" MB" }' Open Vim at the end of a file: vim + some_file_name Clone a specific Git branch (master): git clone [email protected]:name/app.git -b master Switch to another Git branch (develop): git checkout develop Delete a local Git branch (myfeature): git branch -d myfeature Delete a remote Git branch: git push origin :branchName Push a new branch to remote: git push -u origin mynewfeature Run the last cat command from history: !cat Find empty subdirectories under /home/user: find /home/user -maxdepth 1 -type d -empty Extract lines 50‑60 from test.txt: < test.txt sed -n '50,60p' Rerun the previous command with sudo: sudo !! Find files with trailing spaces in their names: find . -type f -exec egrep -l " +$" "{}" \; Find files indented with tabs: find . -type f -exec egrep -l $'\t' "{}" \; Print a horizontal line of "=" characters (alternative): printf '%100sn' | tr ' ' = Split a large tar.gz into 100 MiB pieces and reassemble:
split -b 100m /path/large/archive/path/to/output/files/ && cat files* > archiveGet HTTP status code with curl: curl -sL -w "%{http_code}\n" www.example.com -o /dev/null Force‑quit a hung process when Ctrl+C fails: Ctrl+\ Retrieve the owner of a file: stat -c %U file.txt List block devices with filesystem info:
lsblk -fSigned-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.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
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.
