Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. UNIX(Linux)Beginner - Command Structure and Important Notes

Command Structure and Important Notes - Images: Japanese

Hey there, everyone!

Let's continue with a look at how UNIX commands are structured, plus a few things to watch out for.

We used the shutdown -h now command in the previous article. Let's break down how it's put together. In general terms, UNIX commands follow this structure.

command-name option(s) argument(s)

So you write the command name, then use a space as a delimiter to specify options and arguments. Let's look at each part.

First, 'command name'. This is the name of the command you want to run — in the 'shutdown' example, that's 'shutdown'. It almost always comes first, and there's typically just one of them, so it's safe to think of the first word as the command name.

Next, 'options'. Options are usually prefixed with '-', like the '-h' in 'shutdown -h now'. Many commands also use '--' as the prefix — keep that in mind too.

Commands often support multiple options at once, which is something to be aware of.

Finally, 'arguments'. Arguments specify what the command should operate on — the target file, the destination directory, and so on. Think of them as the object of the sentence — the thing the command is acting upon. In English grammar terms, it's like the direct object. One note on terminology: the word is "argument" (also written "引数" in Japanese, pronounced "hiki-suu", not "in-suu").

Options and arguments tend to become intuitive as you work with UNIX — you don't need to fixate on them right now. Just move forward.

Also: the command name is mandatory, but options and arguments are not. For example, the 'poweroff' command from the previous article takes neither options nor arguments — it's just a bare command name. That's a useful reference point.

One caveat worth noting: none of this is a hard rule that all command authors are required to follow. The structure of a command is up to whoever wrote it. A programmer could choose to design their command without any '-' prefix on options, or use '_' instead, and that would be valid. In practice, the conventions above are almost universally followed — but technically they're conventions, not requirements.

Here's a small practical tip: many commands let you combine multiple options together. Let's look at a quick example using the 'ls' command, which lists the contents of the current directory.

'ls' supports the 'a' option (show all files including hidden ones) and the 'l' option (show detailed output). Both use '-' as the prefix.

So based on what we've covered, running 'ls' with both 'a' and 'l' options would look like this.

[root@localhost ~]# ls -a -l

That works perfectly fine — but options can also be combined like this.

[root@localhost ~]# ls -al

Instead of '-a -l', it becomes '-al'. The pattern is: place a '-' followed by as many option letters as you need. Keep in mind that not every command supports this — it's not universal — so be aware of that.

The order of combined options is usually flexible too. This produces the same result.

[root@localhost ~]# ls -la

Again, '-al' became '-la' — same outcome. But some commands are order-sensitive, so watch out for that.

Now let's go over a few things to avoid or be careful about.

In UNIX-based OSes, commands and filenames may or may not be case-sensitive depending on the system. For example, in CentOS, typing the 'ls' command like this won't work.

[root@localhost ~]# LS -la
[root@localhost ~]# Ls -la

Interestingly, if you try those same commands in macOS Terminal, they work.

This inconsistency can be confusing. Unless there's a specific reason not to, sticking to lowercase is the recommended approach on UNIX systems. File that away for later.

Next up: a note on filenames.

In nearly all UNIX-based OSes, you can use a '-' in filenames, including at the very beginning. So a file named '-a' is technically possible. The problem is that when you try to pass such a file to a command, the system can't tell whether '-a' is an option or a filename — which causes trouble.

Take the cat command, for instance. It outputs the contents of a file. With the -n option and a filename as the argument, it outputs the file with line numbers.

[root@localhost ~]# cat -n filename

Now suppose you actually have a file called -n. Trying to open it would look like this.

[root@localhost ~]# cat -n

As you might expect, that doesn't work — '-n' gets interpreted as an option, not a filename.

So what do you do if you really need to open a file called '-n' with the cat command? Use '--' like this.

[root@localhost ~]# cat -- -n

The '--' tells the command "everything after this point is not an option." So 'cat -- -n' correctly outputs the contents of the file named '-n'.

That said, this is extra work you really don't need to put yourself through. The simple rule: unless you have a specific reason for it, don't create files with names that start with '-'.

Alright, that covers the structure of commands and the main things to watch out for.

In the next article, we'll dig into the filesystem — the foundation of CUI operation in UNIX — along with the cd and pwd commands. See you there!

This article was written by Sakurama.

Author's beloved small mammal

桜舞 春人 Sakurama Haruto

A Tokyo-based programmer who has been creating various content since the ISDN era, with a bit of concern about his hair. A true long sleeper who generally feels unwell without at least 10 hours of sleep. His dream is to live a life where he can sleep as much as he wants. Loves games, sports, and music. Please share some hair with him.

If you find any errors or copyright issues, please .