shell
A Unix shell is a command-line interpreter or shell that provides a traditional Unix-like command line user interface. Users direct the operation of the computer by entering commands as text for a command line interpreter to execute, or by creating text scripts of one or more such commands. Users typically interact with a Unix shell using a terminal emulator, however, direct operation via serial hardware connections, or networking session, are common for server systems.
Computers understand the language of zeros and ones known as binary language. In the early days of computing, instructions were provided using binary language, which is difficult for all of us to read and write. Therefore, in an operating system there is a special program called the shell. The shell accepts human readable commands and translates them into something the kernel can read and process.
Basic Command Line Editing
You can use the following key combinations to edit and recall commands:
CTRL + L : Clear the screen.
CTRL + W : Delete the word starting at cursor.
CTRL + U : Clear the line i.e. Delete all words from command line.
Up and Down arrow keys : Recall commands (see command history).
Tab : Auto-complete files, directory, command names and much more.
CTRL + R : Search through previously used commands (see command history)
CTRL + C : Cancel currently running commands.
CTRL + T : Swap the last two characters before the cursor.
ESC + T : Swap the last two words before the cursor.
CTRL + H : Delete the letter starting at cursor.
mohammedrafi@NOC-RAFI:~$ ssh root@45.56.109.180
root@45.56.109.180’s password:
Last login: Tue Apr 19 09:28:31 2016 from 111.93.18.22
[root@li911-180 ~]# echo $SHELL
/bin/bash
[root@li911-180 ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
[root@li911-180 ~]# chsh /bin/sh
chsh: user “/bin/sh” does not exist.
[root@li911-180 ~]# useradd -s /bin/sh jack
[root@li911-180 ~]# passwd jack
Changing password for user jack.
New password:
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@li911-180 ~]# su – jack
-sh-4.1$ echo $SHELL
/bin/sh
-sh-4.1$ ls -l
total 0
-sh-4.1$ pwd
/home/jack
-sh-4.1$ w
06:17:56 up 51 days, 14:51, 1 user, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 111.93.18.22 05:39 1.00s 0.06s 0.00s w
[root@li911-180 ~]# echo $SHELL
/bin/bash
[root@li911-180 ~]# chsh
Changing shell for root.
New shell [/bin/bash]: sh
chsh: shell must be a full path name.
[root@li911-180 ~]# chsh
Changing shell for root.
New shell [/bin/bash]: /bin/sh
Shell changed.
[root@li911-180 ~]#echo $SHELL
/bin/sh
[root@li911-180 ~]# cat /etc/passwd | grep root
root:x:0:0:root:/root:/bin/sh
[root@li911-180 ~]# logout
Connection to 45.56.109.180 closed.
mohammedrafi@NOC-RAFI:~$ ssh root@45.56.109.180
root@45.56.109.180’s password:
Last login: Mon Apr 25 05:39:28 2016 from 111.93.18.22
-sh-4.1#
| Feature | sh | csh | bash | tcsh |
|---|---|---|---|---|
| Job Control: the jobs command | No | Yes | Yes | Yes |
| Aliasing: renaming complex commands with simple names | No | Yes | Yes | Yes |
| Command History: re-execute frequently used commands quickly | No | Yes | Yes | Yes |
| Command line editing: correct a mis-spelled command name in a complicated command by using the arrow keys and backspace | No | No | Yes | Yes |
| Filename Completion: complete long filenames with a single keystroke | No | Yes | Yes | Yes |
| List Variables: the shell has a built-in list data type, useful when scripting | No | Yes | No | Yes |
| Fully programmable completion: complete command names, hostnames, usernames, etc. with a single keystroke | No | No | No | Yes |
| Can follow symbolic links invisibly | No | No | Yes | No |
| Custom Prompt (easily): for example, change the prompt to display the current working directory | No | No | Yes | Yes |
| Underlying syntax (when writing scripts) | sh | csh | sh | csh |
| Can cope with large argument lists | Yes | No | Yes | Yes |
| Freely available: download the shell and possibly the source code, for free! | No | No | Yes | Yes |
