27 Essential Linux Command‑Line Tricks to Boost Your Productivity
This guide presents 27 practical Linux command‑line techniques—from safe file deletion and alias management to cursor shortcuts, process monitoring, log handling, and advanced scripting—helping power users work faster and avoid common pitfalls.
Cautious File Deletion
Use rm -i to request confirmation before removing files; many admins set this as an alias.
Disable Aliases Temporarily
Run unalias rm to turn off the rm alias for the current session, or place the command in ~/.bashrc to re‑enable it later.
Convenient sudo Usage
Repeat the last command with sudo by typing sudo !!, or create aliases such as alias update='sudo apt update' to prepend sudo automatically.
More Complex Tricks with Functions
Define shell functions in .bashrc for richer behavior. Example function creates a directory and immediately cd’s into it:
md() { mkdir -p "$@" && cd "$1"; }Command Editing and Cursor Movement
Ctrl+Udeletes from the start of the line to the cursor. Ctrl+K deletes from the cursor to the end of the line. Ctrl+A moves the cursor to the beginning; Ctrl+E to the end. Alt+F and Alt+B move forward/backward one word. Ctrl+W deletes the word before the cursor.
History‑Based Quick Execution
Use !<em>n</em> (where n is a history number) to rerun a previous command, or !! for the most recent one.
Real‑Time Log Viewing
Run tail -f filename.log to follow a log file live; less with Shift+F achieves the same effect.
Disk and Memory Inspection
Check mounted filesystem usage with df -h and overall memory with free -h. The -h flag makes sizes human‑readable.
Process Identification and Management
Find a PID by name: pgrep hello or pidof hello.
Terminate by name: killall hello or pkill hello.
View Process Runtime
Show start time and elapsed time with ps -p 24525 -o lstart,etime.
Directory Navigation Shortcuts
cd -returns to the previous directory; cd alone jumps to the home directory.
Multiple Commands in One Line
Separate commands with ; (executes regardless of previous success) or use && to run the next command only if the prior one succeeds.
Viewing Compressed Logs
Use zcat test.gz or zless test.gz to read gzipped logs without manual decompression.
Clearing File Contents
Truncate a file instantly with >filename.
Logging While Displaying Output
Pipe a script’s output through tee to write to a log file and still see it on the console: ./test.sh | tee test.log.
Suspend and Resume Processes
Press Ctrl+Z to suspend; resume with fg (foreground) or bg (background).
Measure Program Execution Time
Wrap a command with time to see real, user, and system durations, e.g., time ./fibo 30.
Top Memory‑Consuming Processes
List the ten processes using the most memory: ps -aux | sort -k4nr | head -n 10.
Search for Commands
Find commands related to a keyword with man -k "copy files", which lists matching manual entries.
Copy‑Paste in Terminal
Use Ctrl+Insert to copy and Shift+Insert to paste.
Search Files for a String
Locate files containing a pattern: grep -rn "test" . shows filename and line number.
Freeze/Unfreeze Terminal Output
Press Ctrl+S to pause output (XOFF) and Ctrl+Q to resume (XON).
Edit Files Without an Editor
Redirect input to a new file with cat >file.txt, type content, then press Ctrl+D to save.
Inspect ELF Files
Show ELF header: readelf -h filename.
Search for a symbol: nm filename | grep interface.
Command Line Editing Shortcuts
Move to line start/end with Ctrl+A / Ctrl+E. Use ^old^new^ to replace text in the previous command and re‑execute.
Alias for Remote SSH Login
Create a shortcut like alias butterfly='ssh -v -l jdoe 192.168.0.11' and store it in ~/.bashrc for persistent use.
Reuse Commands from History
!!– repeat the last command. !ec – repeat the most recent command starting with “ec”. !76 – repeat command number 76 from history.
Live Log Monitoring
Continuously display new log entries with tail -f /var/log/syslog.
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
