Linux notes: Introduction to shell

Q1) What is shell?

shell is a command interpreter which provides a prompt to enter the command. That is, the shell displays a prompt, you type a command, and the shell executes the commands and displays another prompt.

Q2) List the types of shells.
  1. Bourne Again Shell (bash)
  2. TC Shell (tcsh)
  3. Z Shell (zsh)
Q3) How to find which shell you are working with?

You can identify the shell you are running by using the ps utility. This command shows that you running two utilities: bash and ps. If you are running a different shell then it will show that shell name (tcsh, etc) and ps.

$ ps
  PID TTY          TIME CMD
10791 pts/0    00:00:00 ps
11157 pts/0    00:00:00 bash

Note: if you see multiple bash then identify your shell based on terminal number.

Q4) How to correct typing mistakes in shell?

Until you press ENTER/RETURN the command is not executed. Different ways in which you can correct typing mistakes, include erasing one character at a time using the BACKSPACE key, back up a word at a time using CTRL + LEFT/RIGHT ARROW key, or backup to the beginning of the command line using the HOME key.

To delete a word, use CTRL+W.

To delete a line, use the line kill key (or line kill key), CTRL+U. If this key does not work, try CTRL+X.

To erase characters, use BACKSPACE, DELETE, or CTRL+H. If these keys do not work, then use the following command.

$ stty ek

Q5) How to suspend a running program and resume a suspended program?

Use CTRL+Z to suspend a program and fg command to resume the suspended program from where it was suspended.

Q6) How to abort a running program?

To terminate a running program, we use the interrupt key, CTRL+C or sometimes the DELETE or DEL key.

When you press the interrupt key, the Linux operating system send a terminal interrupt signal to both the program you are running and the shell. What effect this signal has depends on the program that is running.

Q7) How to abort a running program when the interrupt key is not working?

If the interrupt key is not working,

  1. Try stopping the program with the suspend key ( CTRL+Z)
  2. Give the “jobs” command to verify the job number of the program
  3. Use the “kill” command to abort the program
$ longjob
[1]+ Stopped        longjob
$ jobs 
[1]+ Stopped        longjob
$ kill %1
[1]+ Stopped        longjob
[1]+ Killed         longjob

The job number is the number within the brackets at the left end of the line that jobs displays ([1]).

The “kill” command sends a signal to the job specified as its argument. The job number must be preceded with the % sign (%1).

By default, the “kill” command sends a software termination signal (-TERM). When this signal does not work, try using a kill (-Kill) signal:

$ kill -KILL %1

A running program cannot ignore a kill signal- it will definitely abort the program.

Q8) How to repeat commands?

To repeat the previous command on command line, press the UP ARROW key.

Leave a Reply


Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: