Operations 16 min read

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 process monitoring, log handling, and advanced shell shortcuts—designed to help heavy users work more efficiently and avoid common pitfalls.

Efficient Ops
Efficient Ops
Efficient Ops
27 Essential Linux Command-Line Tricks to Boost Your Productivity

Cautious File Deletion

Use rm -i to request confirmation before deleting files, or set an alias for safety.

rm -i

Disable Alias Temporarily

Run unalias rm to temporarily disable the rm alias without changing its configuration. unalias rm If rm -i is set as an alias but you want to bypass confirmation, place the unalias rm command in a startup file such as ~/.bashrc.

Using sudo Efficiently

Repeat the last command with sudo by typing sudo !!, or create aliases that embed sudo, e.g., alias update='sudo apt update'.

alias update='sudo apt update'

More Complex Tricks

Beyond simple aliases, define functions in .bashrc for richer behavior. Example: a function that creates a directory and immediately enters it.

md () { mkdir -p "$@" && cd "$1"; }

Command Editing and Cursor Movement

Use keyboard shortcuts to edit commands efficiently: Ctrl+U – delete from the start of the line to the cursor. Ctrl+K – delete from the cursor to the end of the line. Ctrl+A – move cursor to the beginning of the line. Ctrl+E – move cursor to the end of the line. Alt+F – move cursor forward one word. Alt+B – move cursor backward one word. Ctrl+W – delete the word before the cursor.

Quick Execution of History Commands

Use !n where n is the command number, or !string to repeat the most recent command starting with string. history shows the list.

Real‑Time Log Viewing

Run tail -f filename.log to follow a log file as it grows. less with Shift+F provides similar functionality.

tail -f filename.log

Disk and Memory Usage

Check disk space with df -h and memory with free -h. The -h flag makes the output human‑readable.

df -h
free -h

Find Process IDs

Locate a process by name using pgrep name or pidof name.

pgrep hello
pidof hello

Kill Processes by Name

Terminate processes with killall name or pkill name.

killall hello
pkill hello

View Process Runtime

Show when a process started and its elapsed time:

ps -p 24525 -o lstart,etime

Execute Multiple Commands

Separate commands with ; to run them sequentially, but use && to ensure the next command runs only if the previous one succeeds.

cd /temp/log && rm -rf *

Read Compressed Logs

View gzipped logs without extracting using zcat file.gz or zless file.gz.

zcat test.gz
zless test.gz

Clear File Content

Truncate a file quickly with redirection:

: > filename

Log to File and Console Simultaneously

Pipe script output through tee to write to a log file while still displaying it.

./test.sh | tee test.log

Pause and Resume Processes

Press Ctrl+Z to suspend a job, then use fg to bring it to the foreground or bg to continue it in the background.

Measure Program Execution Time

Prefix a command with time to see real, user, and system time.

time ./fibo 30

Show Top Memory‑Consuming Processes

List the ten processes using the most memory:

ps -aux | sort -k4nr | head -n 10

Search Manual Pages by Keyword

Find commands related to a keyword with man -k "keyword".

man -k "copy files"

Copy‑Paste in the Terminal

Use Ctrl+Insert to copy and Shift+Insert to paste.

Ctrl+Insert
Shift+Insert

Search Files for a String

Locate files containing a pattern with grep -rn "pattern".

grep -rn "test"

Freeze and Unfreeze Terminal Output

Press Ctrl+S to pause output and Ctrl+Q to resume.

Edit Files Without an Editor

Create or overwrite a file using cat >file.txt, type the content, then press Ctrl+D to save.

cat >file.txt

Inspect ELF Files

Show ELF header information with readelf -h filename and search for symbols with nm filename | grep symbol.

readelf -h filename
nm filename | grep interface

Command Line Editing Shortcuts

Use Ctrl+A and Ctrl+E to jump to the start or end of a line, and ^old^new^ to replace text in the previous command.

^e^ec^   # replaces e with ec in the previous command

Remote Login Alias

Create an alias for SSH connections, e.g., alias butterfly='ssh -v -l jdoe 192.168.0.11', and store it in ~/.bashrc.

alias butterfly='ssh -v -l jdoe 192.168.0.11'

Reuse Commands from History

Use !! for the last command, !ec for the most recent command starting with ec, or !76 for command number 76.

!!
!ec
!76

Dynamic Log Monitoring

Continuously display new log entries with tail -f /var/log/syslog.

tail -f /var/log/syslog

Get Help for Commands

Append --help to most commands for a quick usage summary, in addition to the traditional man pages.

command --help
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.

LinuxCommand-linebashShell Tips
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

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.