10 Lesser Known Linux Commands That Are Super Useful

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.

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 '\0'
'

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

Show only common lines.

comm -12 file1.txt file2.txt

The 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/syslog

Reverse the contents of a file and save it.

tac file.txt > reversed.txt

This 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.txt

Skip empty lines when numbering.

nl -ba file.txt

This is useful when working with code snippets, debugging, or formatting logs.

8. yes – Auto-Answer Prompts

Tired of repeatedly pressing "y" for confirmations? The yes command automates responses for prompts.

Auto-confirm package installations.

yes | apt install package-name

Test CPU performance by generating infinite output.

yes > /dev/null

Be 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 -h

Track changes in a directory.

watch -d ls -l

Check system uptime every 5 seconds.

watch -n 5 uptime

This 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 multiplication

Find the remainder of a division.

expr 20 % 3

This 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! 🚀

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

2 Comments

Leave a Reply
  1. Hi,

    Your article was very informative, and will be very useful to me. I have been looking for a means of comparing two text files and highlighting the differences between them.

    Can you help?

    Reply
    • @Kunal,

      Thank you so much for your kind words – I’m really glad you found the article helpful!

      To compare two text files and highlight the differences, you can use the diff command in Linux, which is a powerful tool that shows line-by-line changes between two files.

      diff file1.txt file2.txt
      

      If you prefer a more readable and colorized output, you can try:

      diff --color file1.txt file2.txt
      

      Or use vimdiff for a side-by-side comparison:

      vimdiff file1.txt file2.txt
      

      If you’re looking for a GUI tool, meld is great too.

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.