Most commands in Linux follow simple syntax rules. Knowing the syntax to Linux commands will help avoid frustrating error messages and unexpected results.
- [Instructor] Learning the Linux command line can be difficult, but understanding the syntax of a Linux command can help. The standard Linux command syntax is "command [options]" and then "<arguments>". The "command [options]" and "<arguments>" are separated by blank spaces. A Linux command is usually an executable program residing on the Linux disc. In our example, "ls" is the command name. If the options are full words, they'll usually be preceded by two dashes.
If the options are single letters, they're usually by preceded by one dash. For instance, "ls space --size" and "ls space -s". There are no real standards in Linux, but most commands follow these rules. You may, however, come across commands that don't. It's also possible to have more than one argument. Arguments are separated by blank spaces. If we have more than one single character option, we can stack them together. Instead of typing "ls space -s space -1", we can do "ls space -s1".
Let's go to our virtual machine now and open a terminal. So we'll go to Applications, Favorites, and Terminal. I'm going to make my terminal full screen and zoom the font. Let's type in "ls space -s/etc". This will display the size of each file in the /etc directory. Hit Enter. Now let's format the output one item per line. "ls -s -1/etc" and hit Enter.
Now let's combine these two options by typing in "ls -s1/etc". This will give us the same output but allow a shorter command line. We can also mix long options with short options, but they have to be separate. For instance, "ls --size -1/etc". If you're mixing short options and long options, you'll need to put them on the command line separated by white space. What we've covered here is standard Linux syntax. However, due to the nature of Linux and its historical UNIX roots, there's a lot of exceptions.
You may have commands with options that are full words but don't include hyphens, or even have commands that will allow the options to go on the end of the command line after the arguments. Most commands, however, follow the rules in this video.
- Distinguish the difference between the –help option and the output of the man command.
- Define what the uptime command is used for.
- Compare the more command with the less command.
- State which compression algorithm is built into the tar command.
- Write where all operating system files in Linux are stored.
- List the three mods in vi.