Operations 10 min read

10 Must‑Know Command‑Line Tricks to Supercharge Your Workflow

This article compiles ten essential command‑line shortcuts and tricks—including cursor navigation, Vim commands, directory switching, file transfer, log handling, Redis access, and process inspection—to help developers work faster and more efficiently in Unix‑like shells.

Liangxu Linux
Liangxu Linux
Liangxu Linux
10 Must‑Know Command‑Line Tricks to Supercharge Your Workflow

TOP‑1: Most Used Cursor‑Movement Shortcuts

Recommendation: ★★★★★

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

Method:

Ctrl + a  – move cursor to the beginning of the line
Ctrl + e  – move cursor to the end of the line
Ctrl + w  – delete the word before the cursor
Esc + b   – move left by one word
Esc + f   – move right by one word

TOP‑2: Vim Quick Operations

Recommendation: ★★★★★

Scenario: Editing configuration files.

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

Enter :set nu to display line numbers.

Enter :20 to jump to line 20.

Enter :%s/aaa/bbb/g to replace all occurrences of aaa with bbb in the file.

Enter ddp to swap the current line with the next line.

Place the cursor between two quotes and type ci' (or ci" for double quotes) to delete everything inside the quotes, useful for quickly editing parameters in config files.

TOP‑3: Quickly Return to the Previous Directory

Recommendation: ★★★★★

Scenario: Frequently switching between two directories.

Command: cd - Explanation: Executes a toggle between the current directory and the last visited directory (e.g., from /a/work to /b/work and back).

TOP‑4: Cross‑Server File Copy Without Password

Recommendation: ★★★☆☆

Scenario: Copying files between servers when you cannot use scp because the remote password is unknown. (In production, prefer deployment pipelines.)

Method 1 – Using nc (netcat)

On the source machine: nc -l 10017 < abc.sh
On the target machine: nc 1.1.1.1 10017 > abc.sh

Method 2 – Using Python’s SimpleHTTPServer

On the source machine: python -m SimpleHTTPServer 10010
On the target machine: wget http://1.1.1.1:10010/abc.sh
# If the target is a local PC on the same network, you can also open the URL in a browser.

TOP‑5: Simplify Command‑Line File Operations

Recommendation: ★★★★★

Method:

Clear a file’s contents or create a new empty file: > a.log If a.log exists, the command empties the file.

If a.log does not exist, it creates an empty file (a lightweight alternative to touch).

Press Ctrl + C to abort a running command; any output generated before abort is stored in a.log.

Quickly repeat the last command’s final argument (space‑separated) by pressing Esc then .. Example: after mkdir -p /file/abc, type cd followed by Esc . to insert /file/abc instantly.

TOP‑6: Query the Local Intranet IP

Recommendation: ★★★★☆

Scenario: Retrieve the machine’s internal IP address.

Command: hostname -i Note: Works only on machines with DNS resolution. Do not confuse hostname (which changes the host name) with host (which queries DNS records).

TOP‑7: Connect to Redis Without a Client

Recommendation: ★★★★☆

Scenario: When no Redis client is installed, use a quick workaround.

Command: telnet 127.0.0.1 6379 (replace with the target Redis host and port).

Usage: After connecting, you can issue Redis commands manually. Note that Telnet does not support the full Redis protocol; for production, use redis-cli or another proper client.

TOP‑8: Send the Current Job to the Background

Recommendation: ★★★★★

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

Commands: Press Ctrl + Z to suspend Vim, run the desired command (e.g., python aaa.py), then type fg to resume Vim.

TOP‑9: Locate the Directory of a Running Process

Recommendation: ★★★★★

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

Command: pwdx PID (replace PID with the actual process ID).

Note: Useful after spotting a Python process via top and needing to locate the script file.

TOP‑10: Save Command Output to a File While Still Viewing It

Recommendation: ★★★★★

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

Command: your_command | tee logfile Explanation: tee writes the output to logfile and also forwards it to the terminal, eliminating the need for a separate tail -f window.

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.

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