15 Little-Known Unix Commands

Share this article

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!

Frequently Asked Questions (FAQs) about Unix Commands

What are some of the most useful but lesser-known Unix commands?

Unix commands are powerful tools that can greatly enhance your productivity and efficiency when working with Unix-based systems. Some lesser-known but incredibly useful commands include ‘cal’, which displays a calendar, ‘df’, which shows disk space usage, ‘du’, which estimates file and directory space usage, ‘free’, which displays the amount of free and used memory in the system, and ‘wget’, which is a free utility for non-interactive download of files from the web.

How can I use the ‘cal’ command in Unix?

The ‘cal’ command in Unix is used to display a calendar in the terminal. By default, it shows the current month’s calendar. However, you can specify a particular month and year to display by typing ‘cal’ followed by the month and year. For example, ‘cal 12 2022’ will display the calendar for December 2022.

What is the ‘df’ command and how is it used?

The ‘df’ command in Unix stands for Disk Filesystem. It is used to display the amount of disk space used and available on Unix file systems. By typing ‘df’ in the terminal, you can see a summary of the disk usage for all mounted filesystems. If you want to see the disk usage of a specific directory, you can type ‘df’ followed by the directory path.

How can I estimate file and directory space usage with the ‘du’ command?

The ‘du’ command in Unix stands for Disk Usage. It is used to estimate the space usage of files and directories. By typing ‘du’ in the terminal, you can see the disk usage of the current directory and its subdirectories. If you want to see the disk usage of a specific file or directory, you can type ‘du’ followed by the file or directory path.

What is the ‘free’ command in Unix and how can I use it?

The ‘free’ command in Unix is used to display the amount of free and used memory in the system. By typing ‘free’ in the terminal, you can see a summary of the memory usage, including total, used, free, shared, buffers, and cached memory.

How can I download files from the web using the ‘wget’ command?

The ‘wget’ command in Unix is a free utility for non-interactive download of files from the web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies. To download a file, simply type ‘wget’ followed by the URL of the file.

Are there any fun or interesting Unix commands?

Yes, there are several fun and interesting Unix commands. For example, the ‘cowsay’ command makes a cow say whatever you want, the ‘fortune’ command displays a random quote, and the ‘sl’ command displays a steam locomotive running across your terminal.

What are some common mistakes to avoid when using Unix commands?

Some common mistakes to avoid when using Unix commands include not understanding the command before using it, not checking the manual pages for a command before using it, using commands without proper permissions, and not checking the output of a command for errors.

How can I learn more about a specific Unix command?

You can learn more about a specific Unix command by using the ‘man’ command, which stands for manual. By typing ‘man’ followed by the command, you can see a detailed manual page for the command, including its description, options, and examples of how to use it.

Can I customize Unix commands?

Yes, you can customize Unix commands by creating aliases. An alias is a shortcut to a command or a set of commands. You can create an alias by typing ‘alias’ followed by the name of the alias and the command or commands it should execute.

Shaumik DaityariShaumik Daityari
View Author

Shaumik is a data analyst by day, and a comic book enthusiast by night (or maybe, he's Batman?) Shaumik has been writing tutorials and creating screencasts for over five years. When not working, he's busy automating mundane daily tasks through meticulously written scripts!

Command lineunix
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week