Operations 10 min read

9 Essential Linux Command‑Line Tricks to Boost Your Productivity

This article compiles nine practical Linux command‑line shortcuts—from cursor navigation and Vim editing tricks to quick directory switching, file transfer, Redis access, background job handling, process location, and logging—each with usage scenarios, star ratings, and exact command syntax to help developers and operators work more efficiently.

Liangxu Linux
Liangxu Linux
Liangxu Linux
9 Essential Linux Command‑Line Tricks to Boost Your Productivity

TOP-1: Cursor‑movement shortcuts

Recommendation: ★★★★★

Scenario: Editing long commands where you need to modify specific parts.

Ctrl + a   # Move cursor to the beginning of the line</code>
<code>Ctrl + e   # Move cursor to the end of the line</code>
<code>Ctrl + w   # Delete the word before the cursor</code>
<code>Esc + b   # Move left by one word</code>
<code>Esc + f   # Move right by one word

TOP-2: Vim quick operations

Recommendation: ★★★★★

Scenario: Modifying configuration files efficiently.

All commands are executed in Vim’s command mode (press Esc first if unsure).

:set nu                # Show line numbers</code>
<code>:20                   # Jump to line 20</code>
<code>:%s/aaa/bbb/g         # Replace all occurrences of "aaa" with "bbb"</code>
<code>ddp                    # Delete current line and paste it after the next line</code>
<code>ci"                    # Delete everything inside double quotes (use ci' for single quotes)

TOP-3: Return to the previous directory

Recommendation: ★★★★★

Scenario: Quickly toggle between two directories.

Command: cd - Running the command again swaps back to the earlier directory.

TOP-4: Cross‑server file copy without passwords

Recommendation: ★★★☆☆

Scenario: Copy files between servers when you cannot use scp because the remote password is unknown.

Method 1 – using nc:

# On the source machine</code>
<code>nc -l 10017 < abc.sh</code>
<code># On the destination machine</code>
<code>nc 1.1.1.1 10017 > abc.sh

Method 2 – using Python’s simple HTTP server:

# On the source machine</code>
<code>python -m SimpleHTTPServer 10010</code>
<code># On the destination machine</code>
<code>wget http://1.1.1.1:10010/abc.sh

TOP-5: Simplify command‑line output redirection

Recommendation: ★★★★★

To empty a file or create a new empty file: > a.log If a.log exists, its contents are cleared; if it does not exist, an empty file is created (similar to touch).

TOP-6: Insert the last argument of the previous command

Recommendation: ★★★★☆

Scenario: After running mkdir -p /file/abc, quickly change to that directory.

Press Esc then . after typing cd to insert /file/abc.

TOP-7: Query the local IP address

Recommendation: ★★★★☆

Scenario: Retrieve the machine’s internal IP. hostname -i Note: This works only on machines with DNS resolution; host queries DNS records, while hostname changes the host name.

TOP-8: Connect to Redis without a client

Recommendation: ★★★★☆

Scenario: When a Redis client is unavailable. telnet 127.0.0.1 6379 Use telnet <redis‑host> <port> for quick testing, but for production use a proper Redis client such as redis-cli.

TOP-9: Send the current job to the background

Recommendation: ★★★★★

Scenario: While editing a file in Vim, you need to run a command without leaving the editor.

Steps:

In Vim, after saving with :w, press Ctrl+z to suspend Vim and return to the shell.

Run the desired command (e.g., python aaa.py).

Return to Vim with fg.

TOP-10: Locate the directory of a running process

Recommendation: ★★★★★

Scenario: Find where the executable file of a process resides.

Replace pid with the actual process ID: pwdx pid Useful for tracing scripts like python test.py that are consuming CPU but whose file location is unknown.

TOP-11: Save command output to a file while still seeing it

Recommendation: ★★★★★

Scenario: Run a script, keep a log, and watch live output.

Use tee:

# Direct logging</code>
<code>python test.py > a.log</code>
<code># In another terminal</code>
<code>tail -f a.log</code>

<code># One‑liner with live view</code>
<code>python test.py | tee a.log

This streams the script’s output to the terminal and simultaneously writes it to a.log.

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.

Shell Tips
Liangxu Linux
Written by

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.)

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.