
As Linux users, we often rely on our go-to commands ls, grep, awk, sed, and find – to get things done. But Linux has a treasure trove of lesser-known commands that can save time, automate tasks, and simplify workflows.
In this article, we’ll explore a collection of underrated yet powerful Linux commands that deserve more attention.
Table of Contents
- 1 1. rename – Bulk Rename Files Efficiently
- 2 2. pv – Monitor Data Transfer Progress
- 3 3. timeout – Auto-Kill Commands After a Set Time
- 4 4. shuf – Randomize Input Lines or Select Random Entries
- 5 5. comm – Compare Two Sorted Files Line by Line
- 6 6. tac – Reverse the Order of Lines in a File
- 7 7. nl – Add Line Numbers to a File
- 8 8. yes – Auto-Answer Prompts
- 9 9. watch – Repeatedly Execute a Command
- 10 10. expr – Perform Math Calculations in Shell
1. rename – Bulk Rename Files Efficiently
The rename command is a lifesaver when you need to rename multiple files at once. Instead of using loops with mv, rename allows you to apply complex renaming patterns with ease.
Change all .txt
files to .log
.
rename 's/.txt$/.log/' *.txt
Convert filenames to lowercase.
rename 'y/A-Z/a-z/' *
Add a prefix to all .jpg
files.
rename 's/^/photo_/' *.jpg
The rename
command is much faster than using mv
in a loop and avoids potential filename conflicts.
2. pv – Monitor Data Transfer Progress
Ever wondered how fast your data is transferring between files or devices? The pv (Pipe Viewer) command helps by displaying a progress bar, estimated time, and transfer rate.
Monitor file copy progress.
pv bigfile.iso > /mnt/usb/bigfile.iso
Monitor the progress of a compressed backup.
tar cf - /home | pv | gzip > backup.tar.gz
This is extremely useful when working with large files, as you can see real-time progress instead of waiting blindly.
3. timeout – Auto-Kill Commands After a Set Time
Sometimes, a command runs longer than expected, and you want it to stop automatically after a certain period, you can use timeout
command.
Stop a command after 10 seconds.
timeout 10s ping google.com
Stop a process after 1 hour.
timeout 1h rsync -av /source/ /destination/
This is useful in scripts to prevent commands from hanging indefinitely.
4. shuf – Randomize Input Lines or Select Random Entries
Need to shuffle lines in a file or pick a random item? shuf
is a simple yet powerful command for randomization tasks.
Shuffle lines in a file.
shuf file.txt
Pick a random line from a file.
shuf -n 1 file.txt
Generate a random password (12 characters).
shuf -zer -n12 {A..Z} {a..z} {0..9} | tr -d 'shuf -zer -n12 {A..Z} {a..z} {0..9} | tr -d ' ''
The
shuf
command is great for random sampling, testing, and generating random data.5. comm – Compare Two Sorted Files Line by Line
When working with lists or logs,
comm
lets you compare two sorted files and find common or unique lines.Compare two user lists.
comm file1.txt file2.txtShow only common lines.
comm -12 file1.txt file2.txtThe
comm
command is useful for log analysis, user management, and comparing configurations.6. tac – Reverse the Order of Lines in a File
You know cat, but have you tried
tac
? It displays a file’s contents in reverse order, which is a simple yet effective trick.View a log file in reverse order.
tac /var/log/syslogReverse the contents of a file and save it.
tac file.txt > reversed.txtThis is handy for quickly reading the latest log entries without using tail -r.
7. nl – Add Line Numbers to a File
Need to add line numbers to a file?
nl
does it instantly, without modifying the original file.Number each line of a file.
nl file.txtSkip empty lines when numbering.
nl -ba file.txtThis is useful when working with code snippets, debugging, or formatting logs.
8. yes – Auto-Answer Prompts
Tired of repeatedly pressing
"y"
for confirmations? Theyes
command automates responses for prompts.Auto-confirm package installations.
yes | apt install package-nameTest CPU performance by generating infinite output.
yes > /dev/nullBe careful! If not used wisely,
yes
can overload your system.9. watch – Repeatedly Execute a Command
Want to monitor a command’s output in real time? watch runs a command at a fixed interval, refreshing the output.
Monitor free disk space every 2 seconds.
watch -n 2 df -hTrack changes in a directory.
watch -d ls -lCheck system uptime every 5 seconds.
watch -n 5 uptimeThis is useful for monitoring system stats, log files, or process status in real time.
10. expr – Perform Math Calculations in Shell
Need to perform quick arithmetic in a shell script?
expr
allows you to add, subtract, multiply, and divide numbers.Basic arithmetic.
expr 10 + 5 expr 10 * 5 # Use backslash for multiplicationFind the remainder of a division.
expr 20 % 3This is useful for quick calculations inside scripts without using Python or a calculator.
Final Thoughts
These lesser-known Linux commands can simplify tasks, improve efficiency, and save time. Whether you’re managing files, monitoring processes, or automating tasks, mastering these commands will make you a more powerful Linux user.
Which of these commands do you find most useful? Let us know in the comments!