Linux Command LineThe Linux command line provides a way to manually interact with the Linux operating system. The shell program is a program that acts as an interface between the user and the rest of the Linux operating system, including the kernel.
The shell displays the shell prompt. Users enter commands at this prompt. By default, the shell display one of two prompts, depending on the type of user logged in.
For root users, the prompt is the # symbol:
|The command line ends when you hit the Enter key.
A command line however can be extended beyond a single line. I.e. if the command line is longer than one line, you can use the backslash to extend the command line to two or more lines, e.g.
When the shell sees the backslash, it knows to ignore the Enter key and expect more arguments and/or options.
There are many shells in Linux. A commonly used shell is bash, the Bourne Again SHell. When you start a Linux container in Docker, you can specify which shell it should run, e.g. $ docker run --rm -it debian bash.
The Linux command line consists of three main types of objects: command, argument(s), option(s).
Command is the application/program to run, e.g. ls, perl, docker, docker-compose, etc. The command is always the first object on the command line.
|There is normally one command object per command line. An exception is if you have pipes (|). A pipe allows multiple commands to be run in series on the same "command line". More on pipes in a later article.|
An argument is a parameter or sub-command used to provide command with additional information, e.g. by itself, the ls command lists the files or directories in the current directory. To list files in another directory, you can enter the other directory as an argument, e.g. ls /opt/bin. A command line can have zero or more arguments.
Options are used to modify the behavior of the command. E.g. the ls command will display visible files/directories. Given the -a option, e.g. ls -a, it will display both visible and non-visible files.
Options come in two forms: short-form, typically prepended with a single dash, and long-form, prepended with two dashes. Examples:
- short-form option: ls -a or docker ps -a
- Long-form option: ls --all or docker ps --all
- ls --all -l
An exception to being able to combine options is if the option requires an argument, i.e. the -v option in Docker requires the volume path or directory as an argument, e.g. docker run -v /data, as such it should stand by itself.
|Licensed under a Creative Commons Attribution 4.0 International License.|