J
Jarret W. Buse
Guest
Linux+: Linux Shell 01 – Introduction
Not all Linux systems have a Graphical User Interface (GUI). Originally, Linux systems had no GUI and were command-line based like DOS. Sometimes, the GUI can fail or lock up requiring the use of a shell to shutdown the system.
A shell is an interface to the the kernel. In the GUI, a user can click on icons which create a command that is managed by the kernel. For example, clicking on a file icon will cause an associated application to load using the clicked file as needed by the application. If a document is clicked, then an appropriate editor is used to open the file. In this way, clicking the file checks an associations list which then causes the application to be executed. Parameters are passed to the application which causes the original file to be loaded with the application as needed.
Before the GUI, the application name could be entered from the residing folder of the application. Parameters could be passed on the command-line to load the necessary file or once the application was loaded, the file could be opened from there. For example, the command 'python /home/jarret/script.py' would load the Python program and then the Python program would load the script.py file from the folder /home/jarret/.
NOTE: All command syntax and parameters are case-sensitive. If the previous file was 'Script.py' it would have to be typed in the same case to be loaded.
When a command is entered, the built-in commands are checked first to find a match. If no match is found in the built-in commands, then the PATH environment variable is checked.
NOTE: The PATH environment variable contains a list of directories which are used to check for commands. To find the PATH variable contents, type 'echo $PATH' at a prompt.
There are four basic shells (others do exist):
BASH is the most popular shell for Linux.
NOTE: When the BASH shell is started there is a BASH script, ~/.bashrc, which is executed first.
When a terminal is first opened, which shows the shell, you will be shown a prompt. The prompt consists of your username, hostname and the current directory name as shown:
username@hostname: directory$
For example, on my system, the prompt may be: jarret@jarret-Presario-CQ62-Notebook-PC:~$
My username is jarret and my hostname is jarret-Presario-CQ62-Notebook-PC. The current directory is shown as a tilde (~) which represents the current user's Home folder.
NOTE: The hostname is set during the installation of the Operating System (OS).
If you are logged in as root the prompt will change to something like: root@jarret-Presario-CQ62-Notebook-PC:/home/jarret#. Now the username is root and the last character the pound sign (#) shows you are logged in with root privileges.
Since there are four shells you will need to determine which shell is being used. To find the shell type, enter 'echo $SHELL' at a prompt. The response should designate the shell type by its location.
Bourne Again Shell - /bin/bash
Bourne - /bin/sh
C Shell - /bin/csh
Korn Shell - /bin/ksh
NOTE: The C Shell does not recognize $SHELL, it requires $shell. Always remember that the commands entered are case-sensitive.
If you have multiple shells installed, you can use the shell abbreviation at a prompt to change to another shell type. For example, to change to the C Shell, enter csh at a prompt. If the shell is not installed, you will receive an error that the command is not found.
NOTE: To install the shells, use your installer such as Synaptic.
To maneuver around the command prompt, there is a history of commands kept. To execute a previous command, press the Up Arrow key. Each keypress goes back one previous command until the first entered command is reached. The Down Arrow can be used to move back through the commands.
The size of the history list can be found by entering 'echo $HISTSIZE'. The default value is usually 1,000. By default, one thousand commands will be stored to use the Up and Down Arrow keys. To see a list of the entered commands, type 'history' at a command prompt.
To change the HISTSIZE, at a command prompt, enter 'HISTSIZE=number'. The number you enter is the maximum value of the history. The maximum value is 32,767.Even if the size is set higher than 32,767, the maximum is still only 32,767.
NOTE: The location of the BASH History file is /usr/username/.bash_history, or ~/.bash_history.
Once the maximum set number of entries is reached for the history, the next entry entered will overwrite the first entry. Overwriting will continue until the entries are full and then the first entry is used again.
NOTE: The process of filling a log and then overwriting the first entry and continuing again is known as circular logging.
Not all Linux systems have a Graphical User Interface (GUI). Originally, Linux systems had no GUI and were command-line based like DOS. Sometimes, the GUI can fail or lock up requiring the use of a shell to shutdown the system.
A shell is an interface to the the kernel. In the GUI, a user can click on icons which create a command that is managed by the kernel. For example, clicking on a file icon will cause an associated application to load using the clicked file as needed by the application. If a document is clicked, then an appropriate editor is used to open the file. In this way, clicking the file checks an associations list which then causes the application to be executed. Parameters are passed to the application which causes the original file to be loaded with the application as needed.
Before the GUI, the application name could be entered from the residing folder of the application. Parameters could be passed on the command-line to load the necessary file or once the application was loaded, the file could be opened from there. For example, the command 'python /home/jarret/script.py' would load the Python program and then the Python program would load the script.py file from the folder /home/jarret/.
NOTE: All command syntax and parameters are case-sensitive. If the previous file was 'Script.py' it would have to be typed in the same case to be loaded.
When a command is entered, the built-in commands are checked first to find a match. If no match is found in the built-in commands, then the PATH environment variable is checked.
NOTE: The PATH environment variable contains a list of directories which are used to check for commands. To find the PATH variable contents, type 'echo $PATH' at a prompt.
There are four basic shells (others do exist):
- Bourne Again Shell (bash)
- Bourne Shell (sh)
- C Shell (csh)
- Korn Shell (ksh)
BASH is the most popular shell for Linux.
NOTE: When the BASH shell is started there is a BASH script, ~/.bashrc, which is executed first.
When a terminal is first opened, which shows the shell, you will be shown a prompt. The prompt consists of your username, hostname and the current directory name as shown:
username@hostname: directory$
For example, on my system, the prompt may be: jarret@jarret-Presario-CQ62-Notebook-PC:~$
My username is jarret and my hostname is jarret-Presario-CQ62-Notebook-PC. The current directory is shown as a tilde (~) which represents the current user's Home folder.
NOTE: The hostname is set during the installation of the Operating System (OS).
If you are logged in as root the prompt will change to something like: root@jarret-Presario-CQ62-Notebook-PC:/home/jarret#. Now the username is root and the last character the pound sign (#) shows you are logged in with root privileges.
Since there are four shells you will need to determine which shell is being used. To find the shell type, enter 'echo $SHELL' at a prompt. The response should designate the shell type by its location.
Bourne Again Shell - /bin/bash
Bourne - /bin/sh
C Shell - /bin/csh
Korn Shell - /bin/ksh
NOTE: The C Shell does not recognize $SHELL, it requires $shell. Always remember that the commands entered are case-sensitive.
If you have multiple shells installed, you can use the shell abbreviation at a prompt to change to another shell type. For example, to change to the C Shell, enter csh at a prompt. If the shell is not installed, you will receive an error that the command is not found.
NOTE: To install the shells, use your installer such as Synaptic.
To maneuver around the command prompt, there is a history of commands kept. To execute a previous command, press the Up Arrow key. Each keypress goes back one previous command until the first entered command is reached. The Down Arrow can be used to move back through the commands.
The size of the history list can be found by entering 'echo $HISTSIZE'. The default value is usually 1,000. By default, one thousand commands will be stored to use the Up and Down Arrow keys. To see a list of the entered commands, type 'history' at a command prompt.
To change the HISTSIZE, at a command prompt, enter 'HISTSIZE=number'. The number you enter is the maximum value of the history. The maximum value is 32,767.Even if the size is set higher than 32,767, the maximum is still only 32,767.
NOTE: The location of the BASH History file is /usr/username/.bash_history, or ~/.bash_history.
Once the maximum set number of entries is reached for the history, the next entry entered will overwrite the first entry. Overwriting will continue until the entries are full and then the first entry is used again.
NOTE: The process of filling a log and then overwriting the first entry and continuing again is known as circular logging.
Attachments
Last edited: