Linux Command Names, Arguments and Options
Read a command from left to right
A command asks the shell to perform an action. A simple invocation begins with the command name, followed by arguments. Some arguments are options that change behavior; others are operands, such as a file or directory to examine. In ls -a ., ls is the name, -a requests hidden entries, and . refers to the current directory. For file examples, open a terminal in the supplied lab-fixtures/command-basics/sample-data folder (or use a file manager’s Open in Terminal action). It contains notes.txt, Notes.txt, daily report.txt, .hidden and -draft. The examples only read these files. The exact display order depends on locale; the examples below assume the C locale and GNU ls.
The digit 1 in -1 requests one entry per line. Names starting with a dot are normally omitted by GNU ls. A leading dash in a displayed filename is simply part of the name.
The shell passes the option and directory name to the command as separate arguments. The command decides how to interpret them. In this example the option changes the display format; the directory operand selects what to inspect. Neither creates a file.
Short options, long options and option values
GNU ls accepts -a and --all for the same behavior. For this command, -1a combines two short options that take no values. Other options may need a value: for GNU ls, --sort=size sets the sort criterion. Read the help before combining options; different programs have different rules.
The output adds . (this directory), .. (its parent) and .hidden. Both ordinary and hidden entries are now visible.
Prevent a filename from becoming an option
For GNU ls, -- ends option parsing. Without it, a name beginning with a dash may be interpreted as flags. Another safe form for this relative name is ls ./-draft. Not every command supports --; consult its documentation.
Practice
In the supplied folder, predict which entries ls -1a . will include. Then run it and compare. Identify the command name, option and operand. Next, try listing -draft using the explicit relative path.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Command names, arguments and options — Knowledge Check
Apply the command-line concept in a safe beginner lab.
In ls -a ., what is the operand?
Which GNU ls option includes dot-prefixed names?
How can you list the file -draft without it becoming an option?
What does -1a mean for GNU ls?
Can every command use identical flags?