Linux Format

Easing into a CLI

How to break terminal velocity and not your leg.

-

Aterminal emulator is one of the core applicatio­ns that’s bundled with every Linux desktop environmen­t. Gnome has the gnome-terminal while KDE uses konsole though they are usually simply labelled as ‘Terminal’ in the applicatio­n menu, When you fire up a terminal you get a prompt like bodhi@epoch: ~ $ . While it may vary in appearance somewhat depending on the distributi­on (distro), it’s usually made up of your username@machinenam­e, followed by the current working directory and a dollar sign. Note that the last character changes from $ to # when the terminal session has superuser privileges.

Let’s begin our terminal travels by learning to navigate the Linux file system. Files under Linux are organised in a hierarchic­al directory structure that you can think of as an inverted tree-like pattern. The top most directory is called the root directory which contains files and subdirecto­ries that further contain more files and subdirecto­ries and so on. In the shell you are always inside a directory. To display the current working directory, we use the pwd (print working directory) command, such as: bodhi@epoch: ~ $ pwd /home/bodhi By default the terminal session sets the current working directory to your home directory. As you are probably aware, every user who has an account on your distributi­on gets their own home directory. You can list the contents of a directory with the ls command which can also be used to display various attributes about the files and folders, such as: bodhi@epoch: ~ $ ls -l total 196 -rw-rw-r-- 1 bodhi bodhi 5701 Feb 4 18:20 example-text-file. txt -rw-rw-r-- 1 bodhi bodhi 16405 Dec 13 08:45 chart.ods -rw-rw-r-- 1 bodhi bodhi 23339 Dec 13 08:47 an-ebook.pdf drwxr-xr-x 3 bodhi bodhi 4096 Feb 4 12:32 Desktop drwxr-xr-x 10 bodhi bodhi 20480 Feb 6 15:17 Documents ….

We’ll equip you with the skills to make sense of this output over the next few pages. The Linux shell also keeps a log of all the commands you’ve executed on the shell. You can press the Up arrow key to bring up the previous command. This list of commands is kept in a hidden file named .bash_history under your home directory. To navigate the filesystem you can use the cd command to change the current working directory. By entering cd without any attributes, this will return you to your home directory. To change to another directory you’ll have to append its pathname as an attribute. A pathname can be understood as the route taken along the filesystem tree to get to a desired directory.

Move around

There are two distinct mechanisms for specifying pathnames: absolute pathnames and relative pathnames. An absolute pathname begins with the root directory and follows the tree one from branch to branch until it reaches the desired location. For example, the pathname to get to the directory that apps and various utilities use to house their logs is /var/ log. The leading / represents the root directory under which there is a directory named var that further contains the log directory. Type cd /var/log to move into that directory. Notice the change in the shell prompt that now displays the pathname of the current working directory.

In contrast to absolute pathnames, a relative pathname traces its steps to the destinatio­n directory with respect to the current working directory. To this end it uses a couple of special notations, a single dot (.) and two dots (..). The single dot notation represents the current directory while the double dot represents its parent, e.g. if you wish to move to the /var directory from the /var/log directory, you can type cd .. instead of the absolute pathname which is cd /var .

 ??  ?? You can add options to most commands. Some consist of single characters preceded by a dash, (e.g. -l), but many are longer (e.g. --human-readable).
You can add options to most commands. Some consist of single characters preceded by a dash, (e.g. -l), but many are longer (e.g. --human-readable).

Newspapers in English

Newspapers from Australia