Essential Linux Command‑Line Tips and Tricks for Efficient System Use
This article compiles a comprehensive set of Linux command‑line shortcuts, Bash expressions, daily utilities, data‑processing commands, and system‑debugging tools, providing practical examples and code snippets to help users work faster and manage servers more effectively.
1. Basic Commands
Familiarize yourself with core Bash concepts, read the full man page, and master VIM as a powerful editor.
Learn SSH key‑based authentication using ssh-agent and ssh-add, for example:
#!/bin/sh
scp ~/.ssh/id_dsa.pub $1@$2:~/
ssh $1@$2 "touch ~/.ssh/authorized_keys ; cat ~/id_dsa.pub >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys; exit"Know common task‑management shortcuts such as &, Ctrl‑Z, Ctrl‑C, jobs, fg, bg, kill, and essential file‑handling commands like ls, chmod, chown, du, df, mount.
Basic network tools include ifconfig, dig, and regular‑expression utilities such as grep with options -o, -A, -B. Package installation uses apt‑get or yum.
2. Useful Bash Expressions
Quick command recall: !! repeats the last command, !$ expands to the last argument, {a..b} generates a numeric range, and {a,b,c} expands to a list of strings.
Parameter expansions include ${1‑9} for script arguments, $0 for the script name, $# for argument count, $? for the previous exit status, $$ for the current PID, and $* for all arguments.
3. Daily Command‑Line Tools
Search command history with Ctrl‑R. Editing shortcuts: Ctrl‑W deletes the previous word, Ctrl‑U clears the line, Alt‑BackSpace deletes the word before the cursor.
Navigate directories with cd - to return to the previous location.
Powerful utilities include xargs (e.g., find . -name *.py | xargs grep some_function), parallel for parallel execution, pstree -p to view process trees, pgrep / pkill for name‑based process control, and session managers like screen, tmux, dtach.
Network inspection with lsof, netstat -lntp, and debugging with set -x (trace) or set -e (exit on error). Use a semicolon to run commands in a subshell: (cd /some/other/dir; other‑command).
Shell parameter tests such as ${name:?error message} and substring removal ${var%suffix}, ${var#prefix} are also covered.
Redirection examples: some_command > logfile 2>&1 and input‑output tricks like <tab> via Ctrl‑V or $'\t'.
4. Data Processing
Sorting and deduplication with sort, uniq, uniq -u, uniq -d. Text manipulation tools include cut, paste, join, and set operations using pipelines, e.g.:
cat a b | sort | uniq > c # union
cat a b | sort | uniq -d > c # intersection
cat a b b | sort | uniq -u > c # differenceSet locale to LC_ALL=C for faster sorting. Use awk for column calculations ( awk '{ x += $3 } END { print x }'), sed for in‑place edits, shuf to randomize lines, and sort -k with stable option -s for multi‑field sorting.
Binary file utilities: hd, bvi, strings, grep, and encoding converters iconv / uconv. Splitting files with split or csplit.
5. System Debugging
Performance and resource monitoring with iostat, netstat, top, htop, dstat, free, vmstat. Generate Java stack traces using kill -3 <pid>.
Network diagnostics via mtr, traceroute, iftop, nethogs. Load testing with ab or siege. Deep packet inspection with wireshark or tshark.
Trace system calls with strace and library calls with ltrace; both support profiling ( -c) and attaching to processes ( -p). Inspect shared libraries via ldd and debug binaries with gdb. The /proc filesystem provides runtime information (e.g., /proc/cpuinfo, /proc/XXX/fd).
Historical performance with sar, advanced profiling with stap or perf, and kernel messages via dmesg.
SSH tunneling shortcuts ( ssh -L, ssh -D) and configuration tweaks ( TCPKeepAlive=yes, ServerAliveInterval=15, StrictHostKeyChecking=no, Compression=yes, ForwardAgent=yes) help maintain stable remote sessions.
Finally, the article notes that adding a leading # (via Alt‑#) comments out a partially typed command, preserving it in history for later reuse.
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.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
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.
