10 Unix commands every Mac and Linux user should know

Spread the love

Graphical interfaces are great—we wouldn’t want to live without them. But if you’re a Mac or Linux user and you want to get the most out of your operating system (and your keystrokes), you owe it to yourself to get acquainted with the Unix command line. Point-and-click is wonderful whenever you need to do something once or twice. But if you need to repeat that task many times, the command line is your savior.

The command line is a window into the full, awesome power of your computer. If you long to break free of the constraints of the GUI or think that programming or administering remote machines is in your future, then learning the Unix command line is definitely for you.

Don’t worry if Unix commands seem like magical incantations or the mysterious internals of the system seem beyond your grasp. They aren’t that difficult to learn, and this article will give you the 10 essential commands you need to get started. Before long those cryptic strings will be second nature.

Shell basics

The Unix command line shell is roughly equivalent to the command window in Microsoft Windows (cmd or PowerShell). The commands we walk through below will work on any Unix-like system, including Linux, Darwin (the foundation of MacOS), FreeBSD, and even Windows with something like Git Bash or the new Bash shell in Windows 10. The options and output vary slightly, but you should have no trouble making sense of them.

First, you must open a shell, sometimes called a terminal window. Often Unix distributions put this under the Administration or System menus. In MacOS, you’ll find the terminal in Applications > Utilities > Terminal. When you launch it, you’ll see something like this:

01 bash shellIDG

This screen, from MacOS 10.11, is typical of most shells in a GUI. At the top of the window we see the type of shell, in this case Bash (Bourne Again Shell, which is the default shell in MacOS and most Linux distributions), and the size of the window. Inside the window is the prompt, in this case configured to display the name of the machine (Mercury), the name of the current working directory (here the tilde, ~, which is shorthand for the user’s home directory), the name of the user, and finally the prompt symbol (the $). Note that your prompt will change as you move around the file system or if you become a different user on your machine (such as the root or superuser in order to run administrative commands). The prompt displays this information, so you can easily tell where and who you are on any machine.

It’s worth knowing there are two major flavors of the Unix shell: Bourne and C shell. Bourne and company were derived from the original AT&T Unix, while the C shell hails from the University of California at Berkeley and BSD Unix. Generally the Bourne and C shell derivatives are good for interactive work at the terminal. The POSIX standard shell, the Korn shell, is the one you’d want to use for writing your own programs in the shell, called scripts. We use the Bash shell for the examples in this tutorial.

The shell environment

One of the first facts to understand about working on the Unix command line is that the shell operates in its own environment. Understanding how to control the shell environment is an important part of becoming efficient at the command line. Let’s take a look at the environment using the env command:

Leave a Reply

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