15 Essential Linux Command‑Line Tricks to Boost Your Productivity
This article presents a collection of fifteen practical Linux command‑line techniques—including fast file clearing, large file generation, secure disk wiping, process timing, log monitoring, timestamp conversion, and history shortcuts—to help users automate tasks and work more efficiently.
Linux users know that the command line is a powerful tool for automating repetitive tasks and increasing efficiency. The following fifteen tips demonstrate concise commands and shortcuts that can be immediately applied in everyday workflows.
1. Quickly empty a file
The shortest way to truncate a file is: $ > access.log Other common methods include:
: > access.log true > access.log cat /dev/null > access.log echo -n "" > access.log echo > access.log truncate -s 0 access.logThe built‑in : command is a no‑op; it writes nothing, effectively overwriting the file with empty content.
2. Generate a large file quickly
Use dd to create a test file of a specific size, e.g., 1 GB:
$ dd if=/dev/zero of=file.img bs=1M count=10243. Securely erase a disk
Overwrite a whole disk with random data using dd and /dev/urandom: $ dd if=/dev/urandom of=/dev/sda This method provides a simple way to securely delete all data on the target drive.
4. Create a bootable system USB
Write an ISO image directly to a USB device (or any block device) with a single command:
$ dd if=ubuntu-server-amd64.iso of=/dev/sdb5. Show a process’s elapsed time
Instead of the generic ps aux, specify the -o option to display only the desired fields: $ ps -p 10167 -o etimes,etime Use etime to see that the process has been running for 19 days.
6. Monitor logs in real time
Tail a log file continuously: $ tail -f test.log Stop automatically when a line containing "Failed" appears:
$ tail -f test.log | sed '/Failed/ q'7. Convert timestamps
Convert a Unix timestamp to a readable date: $ date -d@1234567890 +"%Y-%m-%d %H:%M:%S" Show the current timestamp:
$ date +%s8. Measure program execution time
Use the time command: $ time ./test The output shows real (wall‑clock time), user (CPU time in user space), and sys (CPU time in kernel space). Differences arise when the program blocks (e.g., sleep, I/O) or runs on multiple CPUs.
9. View ASCII table
Display the ASCII reference directly in the terminal:
$ man ascii10. Delete files with garbled names
Find a file by its inode number and remove it:
$ ls -i $ find . -inum 132395 -exec rm {} \;11. Get your public IP address
Query an external service with curl:
$ curl ip.sb $ curl ifconfig.me12. Batch download web resources
Recursively download all PDF files from a site using wget:
$ wget -r -nd -np --accept=pdf http://fast.dpdk.org/doc/pdf-guides/13. History command shortcuts
!!– repeat the previous command. !N – repeat command number N from history. !pw – repeat the most recent command starting with pw. !$ – expand to the last argument of the previous command.
14. Quickly search command history
Press Ctrl+r and type a keyword to perform an incremental reverse search through the history.
15. Prevent a command from being saved in history
Prefix the command with a space; Bash will skip recording it, which is useful for commands containing sensitive information.
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.
