GNU/Linux is a free clone of the Unix OS which was a text-based operating system. To properly administrate Linux, there is a need for understanding the most basic command line tools. The early computers did not have graphical user interfaces and the only way to “communicate” with them was to use the command line. To use the command line, we first need to have a shell. A shell is the program that provides the user an interface to the system. It accepts and interprets text-mode commands. The commands which can be entered depends which shell is being used. Terminals and shells are two different things: the terminal is a program that allows you to access the shell and a terminal can therefore run diverse types of shell.

But still, why should you bother learning how to use the shell? Simply because it is powerful… Very powerful. Computers are built to do the task for you rather than  you pointing and clicking and clicking and pointing. With the command line, you can find all files on the system that are greater than 3 Mb, older than 3 days, find their individual size, get rid of the permission errors, sort them, write them down in a file, compress that file and mail it to you as well as delete the compressed file created. Imagine doing that on a Windows PC with over 300 GB of data and thousands of files. A lot of clicks and pointing, sorting, wasting time compressing, connecting to your email account, attaching the file and so on. Well a whole lot of time! On Linux, a single line would suffice:

find * -mtime +3 -size +3M -type f 2> /dev/null | xargs du -chs | sort -rh | bzip2 -9 > largest_files.bz2 &&  echo “Largest files on computer” | mail -s “Largest_Files” -a largest_files.bz2 && rm -rf largest_files.bz2

Just press enter, let the computer do the work for you and go have a cup of tea!

While this may seem complicated and long (I wanted to show you how specific tasks and powerful things can be done with the command line), simpler things can be done like mailing the usage of the different partitions:

df -h | mail -s “Disk Usage”

While you can easily do it in some seconds on Linux, it is more time-consuming pointing, clicking and writing a mail. Computers were built so that you do things quicker. I therefore recommend you learn how to use the command line to get things done faster.

Back to shells. Each individual user of the system can configure the shell to be used for entering commands. The most common shells are the following:

  1. bash – created back in 1987 by Fox Brian,the GNU Bourne Again Shell is based on the oldest of shells, the Bourne Shell of Unix. It extends in several ways and is available by default on Linux distributions as well as Mac OS X
  2. sh – The Bourne Shell is the ancestor of all shells and was created in 1977 by R.Bourne Stephen
  3. ksh – Created by  Korn David in 1982, the Korn Shell is a powerful shell quite present on Unix systems, but is also available in free version and is compatible with bash.
  4. csh – C Shell, created by  Joy Bill in 1979 is a shell using a syntax close to the C language.
  5. tcsh – Tenex C Shell, created by  Greer Ken in 1979 is an improvement to the C shell.
  6. zsh – Z Shell, created by  Falstad Paul in 1990 is a shell with the best ideas of ksh, bash and tcsh.

There are other shells which are available but which are not commonly used. Users’ default shell can be changed by editing their account.

  1. The user can select his/her shell by doing chsh -s [absolute path of shell {e.g. /bin/bash}]
  2. The administrator can change the passwd file and edit the shell by doing chsh -s [absolute path of shell {e.g. /bin/bash}] [username]
  3. When manually creating a user the -s parameter can be passed with the full path of the desired shell inserted just after
  4. The /etc/skeleton can be modified so that new users have the desired shell by default

The user needs to logout and login again for the default shell to be activated.

We will launch a simple command to start with the shell : uname. To find details on the operating system which is being run, simply type “uname -a”

[metalinux@localhost root]$ uname -a
Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[metalinux@localhost root]$

The uname -a command provides information on the kernel being used, the hostname of the system and much more.

The GNU/Linux shell is fairly straight-forward: the user types in a command and the computer executes the command. Most of the time, Linux commands are external ones. They are programs that are not part of the shell. However, there are some commands that are internal to the shell. Internal commands as the name indicates are built into the shell and are also known as built-in commands. Examples of built-in commands are cd and ls.

To know if a command is an internal command or an external one, we simply need to use the command type. For example, “type -a pwd”.

[metalinux@localhost ~]$ type -a pwd
pwd is a shell builtin
pwd is /usr/bin/pwd
[metalinux@localhost ~]$

The -a option allows us to see if there are internal commands installed on the system as well as duplicate external commands. Do note that internal commands have precedence over external ones. In order to access external commands, the full path needs to be provided. For example /usr/bin/time instead of time.

When a command which is typed into the shell is not recognized as an internal command, the shell verifies the paths provided to find a program with that name and tries to execute it. The path is a defined list of directories from which commands may be found. It is defined by the variable $PATH. This variable may be modified to specify unusual directories where you may have stored some programs.

[metalinux@localhost root]$ env | grep -i path
[metalinux@localhost root]$

It must also be noted that there are 2 types of shell. A default interactive shell which the user uses to enter commands and the default system shell which the system uses to run system scripts. The most common shell is bash (/bin/bash). Shells can also be downloaded

sudo yum install csh [RedHat/CentOS]

sudo apt-get install csh [Debian and derivatives (Ubuntu, Elementary, Linux Mint)]

sudo zipper in csh [openSUSE]

sudo pacman -S csh  [Arch Linux]

If we log into a text-mode login screen, we will be directly accessing the default shell.  On a GUI however we will need to access the terminal manually. Different Linux distributions employ different names for the terminal. In the menu option, type either terminal, xterm, gnome-terminal, rxvt, kvt or konsole in order to bring up the virtual console terminal.

To start another shell (if installed), just type the shell name from the terminal. Note that shells too have configuration files as most other Linux programs. The bash configuration files are normally scripts. The configuration files are /etc/profile, .bashrc and .bash_profile. Simple changes can be made to these files even if one does not have much knowledge.

Leave your comments and questions right below if you have any difficulties using the shell, I will be very glad to help you out and learn at the same time. You can also ask for tutorials you would like to see. Do not forget to share and like! Go Linux!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s