Linux Command Syntax
When you control Linux OS through the command line, you need to follow the basic rule about Linux commands, which is Linux command syntax.
Standard Linux command syntax has three elements separated by a blank space.
- Command
- Arguments
- Options
Command
A command starts with its name. The command defines what to do (verb). If there are options or arguments, they should follow the command name.
Arguments
Arguments usually define the objects of the command. (If you want to complete a full sentence, you can consider that the shell is the subject and the command is the verb of the sentence). Some commands may require multiple arguments in their syntax. For example, the cp
command requires origin and destination file paths as arguments. In the case of multiple arguments, use a space in between them. In the case below, file_a will be copied to dir_a.
cp file_a dir_a
Options
Options are used for adding more varieties of functionalities in each command. Also, some command options may require option arguments. For example, the tree
command with the -L
option requires the option argument that sets the depth of the tree to display. In the case below, 2 is the argument of the -L
option.
tree /home -L 2
Quoting
If you want to input a sentence with spaces as one argument, you need to use "
"
(double quote) or '
'
(single quote). As spaces are used to separate commands, options, and arguments without giving additional information to Linux OS, the OS misinterprets the spaces as separators of the elements in a command sentence.
For example, you may want to display a sentence with special characters using the echo
command. Without quotes, you cannot display the sentence like the one below.
echo what's your name?
>
However, when you use "
"
(double quote) or '
'
(single quote), the command line returns a correct sentence like the one below.
echo "what's your name?"
what's your name?
Note: The functionality of the echo
command will be explained later.