Programming
Article
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:

[shell]
man man
[/shell]

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.

[shell]
man ascii
[/shell]

ASCII manual page

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

[shell]
man units
[/shell]

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:

[shell]
cd –
[/shell]

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.

[shell]
sudo !!
[/shell]

Running last command as sudo

4. mtr

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

[shell]
mtr [hostname]
[/shell]

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:

[shell]
[space] [command]
[/shell]

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:

[shell]
jot [number_of_numbers] [starting_number]
[/shell]

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:

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

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:

[shell]
pkill [application_name]
[/shell]

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:

Calendar

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:

[shell]
factor [number]
[/shell]

prime factorization of 235

14. yes

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

[shell]
yes [string]
[/shell]

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!

Recommended
Sponsors
The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account