Essential Linux Command-Line Tricks for Everyday Tasks
This guide presents practical Linux command-line techniques, covering file checksum verification, locating files, command-line editing shortcuts, process inspection, log capturing, library dependency checks, ELF header inspection, and various text file viewing commands.
Linux users often need quick, reliable ways to verify files, locate resources, manage processes, and view logs. This article compiles a set of practical command-line tricks to streamline these tasks.
1. Verify File Checksums
To ensure file integrity after copying or transferring, generate and compare checksums using tools such as md5sum, cksum, and sum:
md5sum file_name
cksum file_name
sum -r file_name # system V algorithm
sum -s file_name # BSD algorithmExample with test.txt:
MD5: md5sum test.txt CRC: cksum test.txt SUM (system V): sum -r test.txt SUM (BSD):
sum -s test.txt2. Locate Files Quickly
(1) locate
locatesearches a prebuilt database ( /var/lib/slocate) and is usually faster than find. Install it if missing (e.g., apt-get update && apt-get install mlocate on Ubuntu).
locate file_name(2) find
Use find for real‑time filesystem searches with criteria such as name, type, size, or owner:
find / -name stdio.h3. Command‑Line Editing Shortcuts
When a long, erroneous command line is entered, use these shortcuts instead of repeatedly pressing Backspace: Ctrl+U – delete everything before the cursor. Ctrl+K – delete everything after the cursor. Ctrl+A – move cursor to the beginning of the line. Ctrl+E – move cursor to the end of the line.
4. View Process IDs
pidof process_nameExample output is shown in the accompanying screenshot.
5. Monitor Specific Processes
Use top -p $(pidof kcalc) to display only the desired process. Multiple processes can be monitored simultaneously:
top -p $(pidof kcalc) -p $(pidof test_x86)6. Terminate Processes
(1) kill
kill -9 process_pid(2) killall
killall process_name7. Save Terminal Output to a File
(1) tee
executable_file | tee log_file(2) script
Start recording: script log.txt Stop recording with exit.
(3) Terminal tools with built‑in logging (e.g., Terminator)
8. Check Dynamic Library Dependencies
ldd executable_file9. Inspect ELF File Headers
Use readelf -h elf_file to view architecture and other metadata. The file command also provides a quick summary.
10. View Text Files Efficiently
cat– simple concatenation; cat -n adds line numbers. tac – display file from bottom to top. more – paginated view with progress percentage. less – flexible pagination (PgUp/PgDn) without progress bar. head – show the first n lines (e.g., head -n 20 /etc/profile). tail – show the last n lines. nl – display file with line numbers, similar to cat -n.
11. Set LD_LIBRARY_PATH
export LD_LIBRARY_PATH=./:$LD_LIBRARY_PATHThis adds the current directory to the library search path for dynamic linking.
These tips collectively help Linux users perform routine diagnostics, file handling, and process management more efficiently.
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.
