A file name with a space or special character
The easiest way is to type the start of the name and press Tab: the shell completes and escapes it.
A terminal line is a command name, options (-l, --all) and arguments; the shell splits it into words at spaces.
ls -l -a /etc
a command, two options, an argument
ls -la /etc
short options can be combined
ls --all --human-readable
long options
head -n 5 app.log
an option with a value
head --lines=5 app.log
a long option with a value
cp "my file.txt" docs/
a space in the name — quote it
rm -- -file.txt
after -- only arguments
ls --help | less
short help on options
man ls
the full manual
mkdir logs && cd logs
the second runs if the first succeeded
The shell (bash) splits a line into words at spaces. The first word is the command name; the rest are arguments that the program receives as they are:
The quotes glued two three into a single argument. Double quotes still expand
variables ("$HOME"); single quotes keep the text as is.
By convention, arguments starting with a dash are options: they change how the command behaves. The rest are what the command works on: files, directories, names.
| Form | What it is |
|---|---|
-l |
a short option, one letter |
-la |
several short options together: -l -a |
--all |
a long option, a word |
-n 5, --lines=5 |
an option with a value |
-- |
end of options: only arguments follow |
Only the command itself knows which options it has: see command --help and man
command (see man-help). The shell expands patterns like *.log and ~ before
the program starts, so the program gets ready names — see globbing.
The easiest way is to type the start of the name and press Tab: the shell completes and escapes it.
A \ at the end of a line continues the command on the next one. There must be no
space after the \.
The command has no such option. Check the spelling in command --help. Keep in mind
that the same command's options differ between Linux, macOS and BusyBox.
The command lacks an argument: mkdir with no name, cp with a single file. Add what
to create or where to copy.
The shell split a name with a space into two arguments. Quote the name or complete it with Tab.
The shell waits for the closing quote. Type it and press Enter, or cancel the input with Ctrl+C.
--help, man, apropos.*, ?, {}: what the shell substitutes before running.PATH, where the shell looks for commands.>, | and 2>&1 on the same line.Found an inaccuracy? Report an error in the article