4 min read

Unix Command Line Programs for Beginners

The command line can be intimidating for beginners, but it is actually quite simple to use and understand.
Unix Command Line Programs for Beginners

Command Line Programs

This article is going to take a different approach to teaching command line programs. The goal is more to teach how to use command line programs, how they work, and how you can jump into any command line program and know how to use it. You should be able to take what you learn from this article and be able to work with any command line program.

How Command Line Programs Work?

Programs on the command line are usually referred to as just commands. Programs on the command line are similar to desktop applications. A desktop application, you interact through a GUI (Graphical User Interface). You can think of each click as a command being executed. An example of this would be navigating to a directory using a GUI. You click the directory to navigate to. This same thing can be accomplished on the command line by executing a command to navigate to that directory. One is a GUI, one is text based on the CUI (Command-Line User Interface or Character User Interface).

Command line programs work by typing in commands on a command prompt and executing them by pressing return. When you see someone typing away on the command line, they are pretty much just executing a bunch of small programs.

Commands

Using a real-world example, let's say you ask someone to go to the store for you. They would be the computer, you would be the user, and "go to the store" would be the command you are executing. The command for this could be called gts for "go to store." If you wanted to execute the gts command, you type gts on the command prompt and press enter to execute it.

gts

It is that simple.

Customizing Commands

The gts command isn't very useful by itself. Going back to the real-world example, when that person returns, what store did they go to? What did they get if anything while they were there? Wouldn't it make more sense to say to them, "Go to the grocery store and get eggs?" You can do this same thing with commands.

Options

Options are also referred to as switches. Customizing commands is done through providing options. For example, maybe for the gts command you can specify going tomorrow. This could be done through a tomorrow option. For example, we could execute the gts command with the tomorrow option with the following:

gts --tomorrow

Options start with a single or double dash and are followed by the option. The Unix standard for options is a single dash for a short option and a double dash for a long option. The example above uses the long form of a command. The short form of this option would look something like this.

gts -t

Both the -t and --tomorrow options do the same thing. One is a long form, and one is a short form.

Arguments

An argument is a value that can be passed to an option. With the gts command, let's assume it is only used for going to the grocery store. What do you need from the grocery store? The gts command could have an --items option so you can specify what you want picked up. You need eggs, so the command would look something like this.

gts --items=eggs

Or you could use the short form.

gts -i eggs

If you need multiple things from the store, you can provide a comma separated list of items.

gts --items=eggs,bread,milk

Or using the short form.

gts -i eggs,bread,milk

Multiple options can be specified when using a command. For example, the gts command could both say "get eggs and do it tomorrow."

gts -t --items=eggs

You can mix both the short form and long form for commands.

How do You Know What a Command Can Do?

Now that you understand how to use a command and customize it, how can you find out how to customize the command? There is always the option of searching online to find the answers, but there are ways of learning about a command using the command line.

The Help Option

The help option will list the different options a command has and how to use them. This allows you to learn how to use the command that you are unfamiliar with. With the gts command above, if you were to use the help option, it would list the tomorrow option and the items option with a description on how to use those options. Someone who has never used the gts command can look at the help and then know how to use it.

To use the help option, you can use either the long or short form of it.

gts -h
gts --help

The Man Command

The man (Manual) command is a command that is used to display the manual of the command. This will give you the most information and is generally supported on all systems. You could use the man command to get the man pages (manual pages) for the gts command with the following:

man gts

Man pages can be quite long. To exit out of them on the command line, simply type q.

Conclusion

Command line programs can be intimidating at first but are simple to use. Most of what you need to know is simply understanding commands and options and knowing how to find out what the command can do. Once you understand these basic concepts, you can learn to do anything else on the command line.