10 Lesser Known Commands for Linux – Part 3

Overwhelmed with the response of last two articles of “Lesser Known Linux Article” series namely.

  1. 11 Lesser Known Useful Linux Commands – Part I
  2. 10 Lesser Known Linux Commands – Part 2
  3. 10 Lesser Known Effective Linux Commands – Part IV
  4. 10 Lesser Known Useful Linux Commands- Part V
Lesser Known Linux Commands

10 Lesser Known Linux Commands

We have come up with the third article of this series which includes few other lesser known Linux commands, worth knowing. May be you are already aware of these commands, no doubt you are an experienced Linux user and loves exploration.

22. ^foo^bar Command

Run the last command with modification, in a single instance. Suppose I need to run a command ‘ls -l‘ to long list the content of a directory say ‘Desktop’. Accidentally, you type ‘lls -l‘. So now you will have to retype the whole command or edit the previous command using navigation key. That is painful when the command is long.

[email protected]:~/Desktop$ lls -l 

bash: lls: command not found
[email protected]:~/Desktop$ ^lls^ls 

ls -l 
total 7489440 

drwxr-xr-x 2 avi  avi       36864 Nov 13  2012 101MSDCF 
-rw-r--r-- 1 avi  avi      206833 Nov  5 15:27 1.jpg 
-rw-r--r-- 1 avi  avi      158951 Nov  5 15:27 2.jpg 
-rw-r--r-- 1 avi  avi       90624 Nov  5 12:59 Untitled 1.doc

Note: In the above replacement we used “^typo(to be replaced)^original_command”. This command may be very dangerous if you knowingly or unknowingly replaced the typo with system command or anything risky say rm -rf.

23. > file.txt Command

This command flush the contents of a file without the need of removing and creating the same file again. This command is very useful in scripting language when we need an output or log on the same file again and again.

I have a file say ‘test.txt’ on my ‘Desktop‘ with a lot of text.

[email protected]:~/Desktop$ cat test.txt 

Linux 
GNU 
Debian 
Fedora 
kali 
ubuntu 
git 
Linus 
Torvalds
[email protected]:~/Desktop$ > test.txt 
[email protected]:~/Desktop$ cat test.txt

Note: Again, this command can be dangerous, don’t ever try to flush the contents of a system file or configuration file. If you do so, you will be in serious trouble.

24. at Command

The ‘at‘ command is similar to cron command and can be used for scheduling a task or command to run at specified time.

[email protected]:~/Desktop$ echo "ls -l > /dev/pts/0" | at 14:012

OR

[email protected]:~/Desktop$ echo "ls -l > /dev/pts/0" | at 2:12 PM
Sample Output
-rw-r--r-- 1 avi  avi      220492 Nov  1 13:49 Screenshot-1.png 
-rw-r--r-- 1 root root        358 Oct 17 10:11 sources.list 
-rw-r--r-- 1 avi  avi  4695982080 Oct 10 20:29 squeeze.iso 
..
..
-rw-r--r-- 1 avi  avi       90624 Nov  5 12:59 Untitled 1.doc 
-rw-r--r-- 1 avi  avi       96206 Nov  5 12:56 Untitled 1.odt 
-rw-r--r-- 1 avi  avi        9405 Nov 12 23:22 Untitled.png

Note: echo “ls -l” : This string echo’s the command (here ls -l) on standard terminal. You can replace ‘ls -l‘ with any command of your need and choice.

> : redirects the output

The /dev/pts/0 : This is the output device and/or file, where output is sought, here the output is at terminal.

In my case, my tty is at /dev/pts/0, at that time. You can check your tty by running command tty.

[email protected]:~/Desktop$ tty 

/dev/pts/0

Note: The ‘at‘ command execute the task as soon as the system clock matches the specified time.

25. du -h –max-depth=1 Command

The below command outputs the size of sub-folders within the current directory, in human readable format.

[email protected]:/home/avi/Desktop# du -h --max-depth=1 

38M	./test 
1.1G	./shivji 
42M	./drupal 
6.9G	./101MSDCF 
16G	.

Note: The above command can be very much useful in checking system disk usage.

Download Linux Command Line Cheat Sheet

Download Linux Command Line Book

26. expr Command

The ‘expr‘ command is not that much lesser known command. This command is very much useful in carrying out simple mathematical calculation in terminal.

[email protected]:/home/avi/Desktop# expr 2 + 3 
5
[email protected]:/home/avi/Desktop# expr 6 – 3 
3
[email protected]:/home/avi/Desktop# expr 12 / 3 
4
[email protected]:/home/avi/Desktop# expr 2 \* 9 
18

27. look Command

Check for words from English dictionary in case of confusion, from the terminal itself. Viz., I am a bit confused if the spelling is carrier or carieer.

[email protected]:/home/avi/Documents# look car 

Cara 
Cara's 
…
... 
carps 
carpus 
carpus's 
carrel 
carrel's 
carrels 
carriage 
carriage's 
carriages 
carriageway 
carriageway's 
carried 
carrier 
carrier's 
carriers 
carries 
…
... 
caryatids

The above command showed all the words from dictionary starting with string ‘car’. I got what I was searching for.

28. yes Command

Another command which is not used frequently on regular basis, normally but is very useful in scripting language and for system Administrators.

This command continues to print a given string, till interrupt instruction is given by you.

[email protected]:~/Desktop$ yes "Tecmint is one of the best site dedicated to Linux, how to" 

Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
…
…
...
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to 
Tecmint is one of the best site dedicated to Linux, how to

29. factor Command

The factor command is actually a command of mathematical origin. This command outputs all the factors of a given number.

[email protected]:~/Desktop$ factor 22 
22: 2 11
[email protected]:~/Desktop$ factor 21 
21: 3 7
[email protected]:~/Desktop$ factor 11 
11: 11

30. ping -i 60 -a IP_address

All of us use ping command to check is server is live or not. And I usually ping google, to check if I am connected to internet or not.

It is sometimes irritating, when you wait and keep watching your terminal to get reply of ping command or say, wait for server to get connected.

How about an audible sound as soon as the server comes live.

[email protected]:~/Desktop$ ping -i 60 -a www.google.com 

PING www.google.com (74.125.200.103) 56(84) bytes of data. 
64 bytes from www.google.com (74.125.200.103): icmp_req=1 ttl=44 time=105 ms 
64 bytes from 74.125.200.103: icmp_req=2 ttl=44 time=281 ms

Let me tell you one thing, before you report that the command didn’t return any audible sound. Make sure your system audio is not mute, sound theme must be enabled in ‘sound preferences‘ and make sure ‘Enable window and window sound‘ is checked.

31. tac Command

This command is very interesting which prints the content of a text file in reverse order, i.e., from last line to first line.

I have a text file 35.txt in my Documents directory, under home folder. Checking it’s content using cat command.

[email protected]:~/Documents$ cat 35.txt
Sample Output
1. Linux is built with certain powerful tools, which are unavailable in windows. 

2. One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it's Linux Counterpart. 

3.Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages.

Now reverse the content of file using tac command.

[email protected]:~/Documents$ tac 35.txt
Sample Output
3.Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages. 

2. One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it's Linux Counterpart. 

1. Linux is built with certain powerful tools, which are unavailable in windows.

That’s all for now. If you are aware of other lesser known Linux commands, you can put a comment, so that we can include those in our future articles.

Don’t forget to provide us with your value-able comment. I’ll be soon coming with another interesting article, very soon. Till then stay tuned and connected to Tecmint.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

17 Responses

  1. Jan says:

    great! Some of the commands were not known to me….but hey…the system already had it…feeling ashamed :) :) maybe I should list the bin-directories in a free minutes to see, if there’s something I’m missing so far :)

  2. Vijay says:

    gpasswd – to remove user from group

  3. Rubberman says:

    Got set of articles. After 30+ years of *nix experience, I learned quite a bit, and these articles are going into my archives of “useful” stuff! :-)

    Thanks for your efforts. I see a great career for you in this domain.

    P.S. I am a senior systems engineer for a tier-one tech company and help handle performance engineering for thousands of Linux servers world-wide, supporting 150M+ users.

  4. ZIADI Mohamed-Ali says:

    Problem :
    # vgscan; pvscan; lvscan
    # ^scan^display

    gives :
    #vgscan; pvscan; lvdisplay

    Solution: full substitution with gs :
    # vgscan; pvscan; lvscan
    # !:gs/scan/display

    gives:

    #vgdisplay; pvdisplay; lvdisplay

    • Avishek Kumar says:

      @ ZIADI Mohamed-Ali, True ^foo^bar works with single substitution only, for multiple substitution, wait for our next article.

  5. Kathy says:

    Great column. I just found your website last week and it is very useful. Thank you for sharing.

  6. PSV says:

    My favourite:
    du -ch –max-depth=1 * | sort -rh

  7. Josh says:

    Awesome pro tips. I completely forgot about the “factor” command, I could have used that on Monday! “the more you know”

  8. j. says:

    For the > command, you might say “truncate” instead of flush. I can’t be the only one here thinking flush as in write all changes to disk from cache.

  9. toma says:

    the command “fc” from bash is also quite nice

Leave a Reply to Avishek Kumar Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.