Boost Your Productivity with 15 Essential Linux Command‑Line Tricks
This guide presents a collection of practical Linux shell techniques—including cursor shortcuts, command substitution, alias creation, terminal flow‑control, history reuse, log monitoring, safe file removal, sudo shortcuts, and custom functions—to help users work faster, avoid errors, and master the command line.
Command line editing
Use Ctrl+A to move the cursor to the beginning of the line and Ctrl+E to move it to the end. The quick‑substitution syntax ^old^new^ replaces the first occurrence of old with new in the previous command and then executes the modified command.
$ eho hello world
Command 'eho' not found, did you mean:
command 'echo' from package coreutils
command 'who' from package coreutils
Try: sudo apt install <em>package-name</em>
$ ^e^ec^
echo hello world
hello worldAlias for remote login
Create a Bash alias that contains the full ssh command, user name and host IP. Add the alias to ~/.bashrc (or another startup file) so it persists across sessions. Example: alias butterfly='ssh -v -l jdoe 192.168.0.11' List current aliases with alias. To replace raw IP addresses with readable hostnames, add entries to /etc/hosts or configure DNS.
Freeze / thaw terminal output
Press Ctrl+S (XOFF) to pause scrolling output; resume with Ctrl+Q (XON). This is useful when a command produces a flood of data.
Reusing commands from history
The shell keeps a numbered history. Use the exclamation syntax to replay commands:
!! # repeat the immediately previous command
!ec # repeat the most recent command that starts with "ec"
!76 # repeat command number 76 from the history listYou can also view the history with history or navigate with the up/down arrow keys.
Dynamic log monitoring
Continuously display new lines appended to a log file with tail -f /var/log/syslog. Replace the path with any file you need to monitor.
Getting quick help
Most commands provide a concise usage summary via the --help option, e.g. ls --help. This is a lightweight alternative to opening the full manual with man.
Safe deletion with rm
Alias rm to rm -i so the shell prompts for confirmation before each removal:
alias rm='rm -i'Temporarily disabling an alias
Use unalias to remove an alias for the current shell session: unalias rm Place the unalias command in a startup script if you need the alias disabled only for specific sessions.
Convenient sudo usage
Run the previous command with super‑user privileges by typing sudo !!. You can also create aliases that already include sudo, for example:
alias update='sudo apt update'Shell functions for more complex tasks
Define a function in ~/.bashrc to combine multiple steps. The following function creates a directory (including parents) and immediately changes into it:
md () {
mkdir -p "$1" && cd "$1"
}After adding the function, reload the configuration with source ~/.bashrc or start a new shell. Then md project creates the project directory and changes into it.
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.
