LINUX USER INTERFACES
This Part 2 of Linux tutorial will be covering the Linux User Interface Methods and Introduction to Shell and its types.
TYPES OF INTERFACE:
Linux System comes with the two common Interface environment, Graphical User Interface (GUI) and Command Line Interface. This tutorial will make clear when Command Line should be used and when GUI should be used. Some people are more inclined to use the terminal window and some others prefer more for visual tools. There is no magic ball to prefer one over another both interfaces has some good reasons to use.
GRAPHICAL USER INTERFACE:
The graphical model is the user easy access where the user will be given a GUI where the user can use the system using the mouse. It is similar to another operating system like MS Windows and Apple Mac OS. Let see some use cases where Graphical User Interface is easy to use while writing a document or letter we can make use of Libre office writer tool which is more superior to trying to type the letter in a command line editor such as vim. Because Libre Office editor has good WYSIWYG interface, provides great layout functions, provides the ability to add tables, images and links and you can check the spelling of your document at the end. Within Ubuntu, there is what seems on the surface a perfectly good tool for installing software installed as part of the operating system. Compared to the command line, however, the Software Manager is slow to load and cumbersome to search. The major advantage lies on the Command Line Interface.
COMMAND LINE INTERFACE:
Command Line Interface means where the textual mode is used to execute the requested commands. What the command line provides the graphical user interface are the flexibility and power, and in many cases, it is actually easy to use the command line than the use of the graphical tool. For example let’s look into about installing the software, within Ubuntu on the surface there is a perfectly a good tool for installing software installed as a part of operating system. However, software manager is slow to load and difficult to search. Using the Linux command line you can use the apt command to search for software, install software, remove software and add new repositories with relative ease.
You can guarantee when you are using the apt command that you are seeing all the applications available in the repositories whereas the software manager doesn't.
Our focus will be on the command Line Interface by executing various commands by invoking shells.
INTRODUCTION TO THE SHELL:
In the Linux system, the shell is a command line that interprets the user commands and the script files and tells the operating system what to do with that. After the login, the operating system gives a programming environment where it is a command prompt or the shell prompt where we can write scripts using the interpreted language. It is actually inherited from the UNIX operating system, which predecessor to Linux.
There are two basic categories of shell types login shell and Non-login shell,
A Login shell is started after a successful login, using /bin/login, by reading the /etc/passwd file. Login shell is the first process that executes under our user ID when we log in to a session. The login process tells the shell to behave as a login shell with a convention: passing argument 0, which is normally the name of the shell executable, with a “-” character prepended. For example, for Bash shell, it will be -bash.
When Bash is invoked as a Login shell;
→ Login process calls /etc/profile
→ /etc/profile calls the scripts in /etc/profile.d/
→ Login process calls ~/.bash_profile
→ ~/.bash_profile calls ~/.bashrc
→ ~/.bashrc calls /etc/bashrc
A Non-login shell is started by a program without a login. In this case, the program just passes the name of the shell executable. For example, for a Bash shell, it will be simply bashed.
When bash is invoked as a Non-login shell;
→ Non-login process (shell) calls ~/.bashrc
→ ~/.bashrc calls /etc/bashrc
→ /etc/bashrc calls the scripts in /etc/profile.d/
Following are the example of Non – login shells
TRY THE FOLLOWING COMMAND IN YOUR COMMAND PROMPT
$ cat /etc/shells
$ echo $ 0
THE SHELL – INVOCATION:
The main task of the shell is providing the user environment.
EXECUTING COMMANDS IN SHELL:
Commands can be issued at the command prompt by specifying the name of an executable file, which can be a binary program or a script. There are many standard Linux commands and utilities that are installed with the OS, that allow you navigate the file system, installing the software packages, and configure the system and applications.
An instance of a running command is known as a process. When a command is executed in the foreground, which is the default way that commands are executed, the user must wait for the process to finish before being returned to the command prompt, at which point they can continue issuing more commands.
It is important to note that almost everything in Linux is case-sensitive, including file and directory names, commands, arguments, and options. If something is not working as expected, double-check the spelling and case of your commands!
We will run through a few examples that will cover the basics of executing commands.
WITHOUT ARGUMENTS OR OPTIONS:
To execute a command without any arguments or options, simply type in the name of the command and hit ENTER.
If you run a command like this, it will exhibit its default behavior, which varies from command to command. For example, if you run the cd command without any arguments, you will be returned to your current user’s home directory. The ls command will print a listing of the current directory’s files and directories. The ip command without any arguments will print a message that shows you how to use the ip command.
Try running the ls command with no arguments to list the files and directories in your current directory (there may be none):
Many commands accept arguments, or parameters, which can affect the behavior of a command. For example, the most common way to use the cd command is to pass it a single argument that specifies which directory to change to. For example, to change to the /usr/bin directory, where many standard commands are installed, you would issue this command:
The cd component is the command, and the first argument /usr/bin follows the command. Note how your command prompt’s current path has updated.
If you would like, try running the ls command to see the files that are in your new current directory.
Most commands accept options, also known as flags or switches that modify the behavior of the command. As they are special arguments, options follow a command and are indicated by a single -character followed by one or more options, which are represented by individual upper- or lower-case letters. Additionally, some options start with —, followed by a single, multi-character (usually a descriptive word) option.
For a basic example of how options work, let’s look at the ls command. Here is a couple of common options that come in handy when using ls:
-l: print a “long listing”, which includes extra details such as permissions, ownership, file sizes, and timestamps
-a: list all of a directory’s files, including hidden ones (that start with .)
To use the -l flag with ls, use this command:
Note that the listing includes the same files as before, but with additional information about each file.
As mentioned earlier, options can often be grouped together. If you want to use the -l and -a option together, you could run ls -l -a, or just combine them like in this command:
Note that the listing includes the hidden . and .. directories in the listing, because of the -a option.
WITH OPTIONS AND ARGUMENTS:
Options and arguments can almost always be combined when running commands.
For example, you could check the contents of /home, regardless of your current directory, by running this ls command:
ls -la /home
ls is the command, -la are the options, and /home is the argument that indicates which file or directory to list. This should print a detailed listing of the /home directory, which should contain the home directories of all of the normal users on the server.
THE SHELL – ENVIRONMENTAL VARIABLES:
The Login shells responsibility is to set the Non – login shells and it will set the environmental variables. The Environmental variables are set for every shell and it is generally done at its login time and this environmental variable is set by the system. These environmental variables hold the special values, for instance, $ echo $SHELL.
Environmental variables are defined in the path /etc/profile, /etc/profile.d/ and ~/.bash_profile. When the login shell exists bash reads ~/.bash_logout.
THE SHELL – ENVIRONMENTAL VARIABLES
env – lists shell environmental variable/value pairs.
SHELL – Describes the shell that will be interpreting user commands
TERM – This specifies the type of terminal to emulate when running
USER – The current logged in user
PWD – The current working directory
OLDPWD – The previous working directory
MAIL –The path to the current user’s mailbox
PATH – A list of directories that the system will check when looking for
HOME – The current user’s home directory
HOSTNAME – The hostname of the computer
PS1 – The primary command prompt definition