By Shaumik Daityari

15 Little-Known Unix Commands

By Shaumik Daityari

Every developer needs to gain a certain mastery over the terminal. It’s not always possible to be physically present near the computer you are going to work on, in which case, you would need to remotely log into the machine. And while it’s true that GUI applications are available to accomplish this, they are often not as fast as getting terminal access (after all, it’s just the exchange of some text!).

Regardless of whether you are a beginner or an experienced user of the terminal, I’m sure you like to pick up new tips and tricks. In this post, I’ll introduce 15 Unix commands you might not have heard of before.

Note: For this post, I will use square brackets to denote any variables. When you actually run the command, you should substitute it with the actual value, with the square brackets removed. For instance, our first example, man [command] can be used as man cd or man grep.

1. man

Let’s start with a simple one. The man command stands for “manual”, as in documentation. If you want to know about any Unix command, you can run the following:

man [command]

The simplest use case for man is to view the manual of the man command itself:

man man

man is not necessarily itself a little-known command, and you would probably find it in any Unix tutorial. However, there are certain special uses which I would like to highlight that likely wouldn’t be in a common tutorial.

If you need to know more about your ASCII characters, try this.

man ascii

ASCII manual page

Ever been confused whether pico- or femto- is smaller? Try the following to get info on unit prefixes:

man units

Man Units page

There are many more such manual pages, and some of them are really funny too! (Tip: Try man xkill.) I will leave you to fiddle with that. Meanwhile, let’s move on to some more commands.

2. cd -

If you are working in a directory and accidentally changed to another one, there is an easy way to get back to the old one. Just run the following to get back to the last working directory:

cd –

use of cd -

3. sudo !!

Use of sudo on XKCD

This comic strip by XKCD emphasizes the importance of the sudo command in Unix systems. sudo runs a command with administrator privileges, provided your user is added to the sudo-ers group.

Let’s say you ran a command without prefixing sudo. If you are reluctant to type the same command again, you could run the following to run the last command as sudo.

sudo !!

Running last command as sudo

4. mtr

mtr is a powerful network diagnostic tool. It combines the functionality of the traceroute and ping commands.

mtr [hostname]

use of mtr

mtr inspects the network connection between the host (from which mtr is run) and a remote [hostname]. Here is a detailed post on mtr, demonstrating the full extent of the command.

5. [space] command

Frequent users of the terminal would probably know that every command they run gets logged in a file ~/.bash_history. To skip this logging step while running a command, just prefix a space, and the command will not be logged:

[space] [command]

6. jot

jot, as the name implies, generates some text — from numbers to characters to gibberish. If you want to generate numbers in a range, run the following:

jot [number_of_numbers] [starting_number]

If you provide a single argument, it will generate numbers from 1 to that number.

The -r option produces random numbers. The syntax is as follows:

jot -r [number_of_numbers] [lower_limit] [upper_limit]

Generating random numbers

The -b option repeats a given word. For a list of options, you could run man jot or see this tutorial.

7. df

A relatively simpler command in our list, df stands for “disk free” and shows the amount of free space in your disks.

use of df

8. pkill

pkill or “process kill”, terminates a running process. This command is particularly useful when an application is unresponsive. The syntax is:

pkill [application_name]

A fun/cruel use-case for pkill is when you have the ability to log remotely into a computer that someone else is using. Check what application they are running, and run the pkill command for that application. Try to act normal when they are bewildered and look around to check who played the prank. Of course, you’ll want to make sure it’s not a critical application or something where important work could be lost!

9. ddate

The Discordian calendar is an alternate calendar, with 1 YOLD as 1166 BC. ddate displays the Discordian date.

Discordian date

10. cal

If you just want the plain old Gregorian calendar, just type cal to get a nice looking view of the current month:


This is just the default view. The manual page for cal lists the various options, which can display more months in a different way.

11. tac

You’ve probably heard of the cat command. It has a range of utilities including creating, copying, merging, and displaying text files. The tac command does the same thing, but in reverse order! Have a look.

Use of tac

12. w

w shows who’s currently logged in to your system. It displays the list of logged in users, along with some more information like system uptime and loads.

who's logged in

13. factor

If you want to factorize a number, do not look any further. Just run the following to get the prime factorization of a number:

factor [number]

prime factorization of 235

14. yes

Coming back to a fun command again, yes prints a string a lot of times.

yes [string]

If you don’t provide a string, it prints “y” recursively until you stop the command. This function is so quick at printing the string that I was unable grab a screenshot with the command on the same screen as the output of the command! If you are doing something fishy and someone happens to pass by, make sure you run yes to confuse them (provided they have little idea about Shell programming).

Note: If you plan to run this command, you should know that the only way to stop it is by pressing CTRL+C/CMD+C (or by closing the terminal).

15. nl

nl attaches line numbers to text. It is best used by passing the output of some other command as an argument. The output of another function is passed as an argument using the pipe (“|”). Let’s look at two examples:

Use of nl - line numbers

Know Any Others?

With this, we come to the end of this list of Unix commands you may not have seen before. How many of these did you know? Do you use some of them in your regular work? Let us know in the comments below how many you knew — 15/15 wins!

  • Steve

    I generally use the up arrow for repeating the last typed command (or going back a few commands) – it would be faster than typing sudo !!

  • jokeyrhyme

    I believe the use case for `yes` is to automatically answer yes to an interactive script / command.

    For example:

    yes | rm file.txt

    • Yes, that’s very much possible- I didn’t think of that! Prints “y” for every time the user is asked to confirm something.

    • Tatsh

      Yes. You can also echo y | or similar. But if you really want full control on a process that is interactive-only, use expect.

  • boltronics

    cat .htaccess | nl
    should be
    cat -n .htaccess

    The cat command basically renders nl redundant.

    I usually use calcurse instead of cal on my desktop, since you can record appointments and a todo list. I have calcurse -d 7 show me the appointments for the upcoming 7 days set in .bashrc, so I see them each time I open an xterm.

    The yes command can also be stopped via kill commands, such as the aforementioned pkill command. If something isn’t responding, SIGQUIT (C-) can be a helpful shortcut.

    Obviously the best command is emacs, although mutt is pretty good also.

    @jokeyrhyme: rm has a built-in -f switch to avoid that problem. The amount of times I’ve had a valid reason for using the yes command could be counted on one hand.

    @Steve: I agree, although in Bash I use C-p C-a.

  • TeryakiTimothy

    3/15. Cool post

  • Hi boltronics,

    I just used that an example for demonstration purposes. In fact, many commands like grep have that “-n” feature, which I regularly use.

    Didn’t know about the other kill commands though, thanks!

    For the calculator, I use Google – it shows me graphs too.

    emacs is great, but I still use vim, and sublime text.

    • boltronics

      I assume you mean calendar, not calculator (I use expr as a calculator, or otherwise bc when integers won’t suffice). I don’t know about graphs in a calendar or when I would use them – but I try to avoid Google as much as I reasonably can. :)

      gpg is also an extremely useful command to use, and lately I’ve replaced my GUI password manager to the pass command, which I’m loving.

  • You need to use the up arrow key, home key and then type sudo, which is the same as typing sudo !! I guess.

    However, for running the last few commands, using the up arrow is definitely faster than anything else.

    • Rustynix

      The up arrow is my preferred way to go back while at the keyboard, but I don’t know how to write an up arrow into a shell script. So knowing these text commands makes that possible.

  • Harry Moreno

    yes | nl woo!

    • Евгений Арасланов


  • James Hibbard

    Tip two “cd -” was new for me. Thanks!

    A further tip: if you just type “cd” you will be taken to your home direcotry.

  • I skimmed through your comment and thought of calendar as calculator! My bad.

    The pass looks really cool, though :)

  • Brian Grinter

    df -h prints free space in human readable format

  • Jim Mortenson

    Excellent article; waiting to get back to the house to try these from the Mac OS X Terminal. :-)

  • I use both ‘rev’ and ‘uniq’ a lot. Also I end some long running scripts with ‘touch’ ~/Desktop/Whatever-is-Done so I know it has finished.

  • Kishore Relangi

    Thanks for the nl command and man command trick to get metrics and ascii map

  • TomAL

    ‘cut’ and ‘expand’ are useful and not widely known.

  • I am curious. Why would you need an up arrow in a Shell script?

  • dude

    mkdir {dir1,dir2,dir3} shorter version of
    mkdir dir1, mkdir dir2, mkdir dir3

  • Jeff Fretman

    Great post, merci beaucoup !
    My favourite command is ” | while read word1 word2 word3 words-remaining”
    This command parses the piped output in word1 word2 ….
    For instance :

    dir -l | while read permissions link user group size month day year filename
    echo permissions variable contains first word of output line ie $permissions
    echo filename variable 9th word of output line ie $filename
    echo I can use all the variable to process whatever I want and iterate to the next output line

    BTW, I like dir as it is a black and white ls so more easy to read ;-)
    Regards from Lyon.

  • Chu Quang Tú

    Amazing list :D I only know few of them. Thanks you so much.

  • Drasko

    tree – list contents of directories in a tree-like format
    file – determine file type
    last – show listing of last logged in users

  • Yunga

    Here’s a long list of shell command, ordered in regard to what they do/relate to, here:
    This is mostly a copy/paste from whatisdb – it’s updated once in a while.

  • I knew the space command that’s all. I love already “sudo !!” !

    Howewer if you use grep you can use ‘grep -b’ instead of using |nl

    Thanks for this article !

  • Vikash

    but how you print lines in case of others command….@that moments nl command required……Thk

Get the latest in Front-end, once a week, for free.