Command Line Interface (CLI)#
While there are graphical environments to work with a Linux system in a similar way to work with a Windows system. It is very common to work “on the shell”, that is just interact with system via a textual interface by typing commands. While working on remote systems, this is often the only way to interact with the system at all. The name stems from idea of providing the outer layer of the core operating system or kernel.
The interface where commands are typed in is called a terminal or terminal emulator. These software processing these commands is called a shell or command interpreter. This is actually an application just waiting for input to process. Famous examples of shell programs are bash
(Bourne again shell),ksh
(Korn shell) or zsh
(z-shell). The commands typed in are typically names of other programs which are then executed or part of the shells own programming language, like loops, conditional statements or the use of variables.
Example
The pwd
command to show the current working directory, actually executes the program /usr/bin/pwd
which prints the current working directory. Similar typing firefox
will execute the popular web browser typically installed as /usr/bin/firefox
.
Terminal emulators#
There is a whole list of terminal emulators. Their basic functionality is similar and the choice highly opinionated. Good terminals to start with are Terminator
or GNOME Terminal
. The latter is the pre-installed default terminal in the popular GNOME desktop and can simply be selected from the application menu.
Shell#
The terminal spawns the users default shell, (e.g. bash
or to precise /bin/bash
) and a command prompt is shown and waits for further commands.
The command prompt itself already provides some information. In the example below john@laptop
means, this is a session of user john
on the computer named laptop
. This may seem superfluous, but makes sense while working with (multiple) remote machines. The tilde (~
) is a shortcut and shows the current working directory is user john
’s home directory. The final $
indicates that this is a normal shell, opposed to a #
indicating a privilege shell of the root
user.
Commands can be typed in and are run by hitting return. Executing the pwd
command produces a result like below:
[john@laptop ~]$ pwd
/home/john
To exit a shell the Terminal window can be closed or (on remote systems) the exit
or logout
command can be run. Alternatively sending end of transmission character which is typed as CTRL
+d
exits the shell as well.
Note
Which shell is started is defined in the Linux user database on the system. getent passwd
username
shows colon-separated fields with basic information: Besides the username, the numerical ids for the user (uid
) and his primary group (gid
), also the path of the user’s home directory (here: /home/johndoe
) and the user’s login shell (here /bin/bash
).
getent passwd johndoe
john:*:12366:12366:John Doe:/home/john:/bin/bash