Let’s understand the SHELL and its working

Linux Tutorial

Details about Command Line Interface

In early days of computing, there was no Graphical User Interface. There was only CLI to interact with the computer. Computers back then were very costly and providing personal workstations to individuals was not economical. Mainframe Computers were used for computing by attaching terminal devices to them so that multiple users can access the same mainframe from each terminal device.

A Terminal device is a set of input and output device i.e. it is a user interface. It used to be connected to mainframes via a serial port. One such terminal device was VT-100.

In modern computing age, computers are within the reach of common people and so we do not need to use terminals anymore.

Linux was designed to work with mainframes and so it had the feature to work with terminals. As there is no need for us to use physical terminals anymore we have the feature of “Virtual Terminal” or “Virtual Console” in Linux.

A Virtual Terminal is the user interface where the functionality of a physical terminal is implemented in software. Having more than one virtual terminal allows the administrator to switch to another terminal if necessary.

In all Linux, Distros VTs are found. By default 6 VTs are enabled which can be accessed through the key combinations displayed in above image. GUI is running on first VT if DE is installed and the system is set to boot into GUI.

Linux Tutorials: terminals key shortcuts

 

How to login to Virtual Terminal

Access a Virtual terminal where no GUI is running. You will be presented with a login prompt. Type your username and password and on successful authentication, you will get a Shell.

Linux Tutorial: cli-login image
cli-login image

 

Once Shell gets started you will see a cursor waiting for a command from the user. This is called a shell prompt. Shell prompt ends with a $symbol, when a regular user is logged on ,or with # symbol when a super user is logged on. On shell prompt, you will also be seeing the current directory you are working in. When a user logged in, the current directory is set to user’s home directory which is displayed as tilde symbol~

 

Know about  USER ACCOUNTS

Linux user accounts have following properties.

  • Every User has a UID
  • Every User has a primary group
  • Every Group has a GID

Linux has three types of user accounts – Super, System, and Regular.

Super Account

  • UID = 0
  • GID = 0
  • Has All Privileges

 

System Accounts

  • UID = 1 – 999
  • GID = 1 – 999
  • Has Limited Privileges
  • Cannot Login into the system
  • Used to run background processes called daemons

 

Regular Accounts

  • UID = 1000 – 60000
  • GID = 1000 – 60000
  • Has Limited Privileges

 

SHELL

In order to perform some task in CLI we have specialized utilities which run in text mode and generate text mode output. When we want to use these utilities we type their name on shell prompt as commands. Shell then searches for the executable file of these commands and once its found that, it will execute them. After the command has finished execution the control is given back to shell which again waits for user to input commands on shell prompt.

In a nutshell, shell is a command interpreter.

Different types Shells are available in Linux.

  • sh – Original Unix Shell
  • bash – Bourne Again Shell
  • csh – C Shell
  • tcsh – Turbo C Shell
  • ksh – Korn Shell
  • zsh – Z Shell

BASH is default shell available in most of the Linux distributions.

cat /etc/shells lists the available shells on your system. The Shell currently being used can be verified with commandecho $0.

Commands entered at the shell prompt have three basic parts:

  • Command to run
  • Options to adjust the behavior of the command generally prepended with one or two dash symbols (-, –)
  • Arguments which are typically the targets of the command

List of General Commands we use

To print UID, GID, Groups, and SELinux contexts

$ id
$ id root

To print name of current logged in user

$ whoami

 

To print names of all logged in users

$ who
$ who am i

Same as who with extra information about what the user is doing

$ w

 

To print names of all logged in users

$ users

 

To print names of all groups to which the user currently belongs

$ groups

 

To print name of current terminal

$ tty

 

To print system uptime along with the load average

$ uptime
$ uptime -p

 

To print or change date and time

$ date
$ date +"%d-%m-%Y"

 

To prints or set date and time

$ timedatectl

 

To print calendar

$ cal
$ cal -3
$ cal 2017
$ cal 5 2017
$ cal 15 5 2017

 

To print system information

$ uname
$ uname -a

 

To print text on screen

$ echo 'Hello Linux!'
To sleep for given number of seconds
$ sleep 5

To change the terminal

$ chvt 3

To print command history

$ history
$ history -c

To clear the screen

$ clear

To change user password

$ passwd
# passwd student

Commands regarding the System Information

 To print CPU Information
$ lscpu

To list PCI devices

$ lspci

To list USB devices

$ lsusb

To print memory usage

$ free
$ free -m

To print or change machine name

$ hostname
$ hostname neo.matrix.com

To print or set machine name

$ hostnamectl
$ hostnamectl set-hostname neo.example.com

To print BIOS information

$ dmidecode