03. Command Structure commands, options, arguments

Before we take a look into some commands, let's take a formal look at how they are structured.

Three main components of a command

There are three main components that go into a command.

1) Command

When entering a command, order matters. It's important to place the command name first - otherwise, the shell won't know how to process your submission.

2) Options

Most commands come with certain options, which modify how the command is run. To apply an option, trail it immediately after your command with a hyphen (-).

There is also a long option form of each short option that uses two hyphens (--). We'll stick to the short option for the sake of brevity.

$ command -shortOptions 
$ command --longOptions 

Note that some commands that we'll discuss in the future have actions instead of options. For example, when we later learn about package management, we'll see that some commands use actions words (eg. apt-get install packagename.deb instead of options.

3) Arguments

An argument is some information you pass to the command when it is started.

$ command -options arguments

You may have multiple options and arguments, as we'll discuss real soon.

How commands are interpreted

We can use the type command to see how our shell interprets our command.

1) As a shell builtin

One of the many possibile ways that the shell may interpret a command is as a shell builtin. This means that the command is called from the shell and directly executed in the shell itself.

$ type type
type is a shell builtin

2) As an external program

Commands may also be loaded and run from an external file.

$ type ls
ls is hashed (/bin/ls)

3) As an alias

Another way a command can be referenced is through user-defined aliasing. In the example below, we aliased db to guide us to our Dropbox directory. We'll learn how to implement an alias real soon.

$ type db
db is aliased to `cd ~/Dropbox'

Commenting in the shell

To comment in the shell, use the pound (#) symbol. Anything after # will be ignored.

Take your Linux skills to the next level!

Linux for Beginners

Take your Linux skills to the next level! Try Linux & UNIX

Linux for Beginners doesn't make any assumptions about your background or knowledge of Linux. You need no prior knowledge to benefit from this book. You will be guided step by step using a logical and systematic approach. As new concepts, commands, or jargon are encountered they are explained in plain language, making it easy for anyone to understand.

$ Check price
24.9924.99Amazon 4.5 logo(101+ reviews)

More Linux & UNIX resources

Aching back from coding all day?

Acupressure Mat & Pillow

Aching back from coding all day? Try Back Problems

Relieve your stress, back, neck and sciatic pain through 1,782 acupuncture points for immediate neck pain relief. Made for lower, upper and mid chronic back pain treatment, and improves circulation, sleep, digestion and quality of life.

$$ Check price
144.87144.87Amazon 4.5 logo(1,890+ reviews)

More Back Problems resources

Ad