The Shell
The Shell
2
The Shell
COMP500
Spring 2019
● Popularity of Linux
● Types of Licensing
Learning Objectives
1
2020-08-20
The Shell
Program that allows a user to interact with the system using typed text
commands displayed in the screen
The most popular implementation is the Bash Shell (Bourne Again Shell). Other
examples are Dash, Fish and ZShell
When used properly, allows for a faster interaction with the machine so it is the
System Administrators’ tool of choice
2
2020-08-20
Dennis Ritchie
PDP-11
Ken Thompson
Teleprinter
(also called
Teletype or TTY)
Terminal
https://i.stack.imgur.com/mTxcb.jpg
Shell Commands
A command is a program that is run by inputting its name in the shell
Users can create their own programs and define a text command for execution
3
2020-08-20
Example: rm -r /user
Command is the name of the program: “rm” is the command for remove
Options modify the behavior of the program: “-r” indicates recursive operation
Arguments are variables passed from the user to the program: “/user” is the
folder to be removed
IMPORTANT OBSERVATIONS
4
2020-08-20
Command Autocompletion
If a user types cle and then hits <TAB> the shell autocompletes clear
The text is auto completed only if characters typed so far are unique to the target
Command History
Can use ↑ and ↓ to cycle through previously used commands
Press the ↑ key to retrieve the last command from the command history
Press the ↓ key to go forward though the command history after using ↑ to go
back through the history
5
2020-08-20
To display documentation type man and then the command (e.g. man ls)
6
2020-08-20
7
2020-08-20
Packages often feature extra help content that can be found in /usr/doc or
/usr/share/doc
Also possible to use locate command which can find any file provided the correct
permission
8
2020-08-20
uname
Prints system information
sudo
Executes a command as the root user (or another user)
The user must have the proper permissions in order to use sudo
https://linuxacademy.com/blog/linux/linux-commands-for-beginners-sudo/
exec
Executes another command that replaces the current shell
https://www.computerhope.com/unix/bash/exec.htm
9
2020-08-20
history
Search, delete and manipulate the command history
Display a list of commands entered since the start of the session: history
https://opensource.com/article/18/6/history-command
echo
Mostly used in shell scripts and batch files to output status text to STDOUT
10
2020-08-20
All have a system-defined variable used in the shell. STDIN is $0, STDOUT is $1
and STDERR is $2
Piping
A command expects some input in order to produce an output
Redirection
Output redirection “>” STDOUT or STDERR are redirected to another output or file
cat myfile > newfile saves the contents of myfile to newfile instead of
displaying it
11
2020-08-20
The Filesystem
/home/user1/file.txt
12
2020-08-20
The user has all permissions (read, write and execute) inside his/hers home folder
https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
https://www.howtogeek.com/117435/htg-explains-the-linux-directory-structure-explained/
13
2020-08-20
/bin
Essential binaries (programs) for default commands are stored in this directory
Commands used by all the users of the system are located here
Some common binaries are: bash, cat, date, echo, kill, mv, cp
/boot
Contains files needed to boot the system
/dev
Contains device files (everything is a file in Linux, even hardware)
These include a file for each terminal, usb, or any device attached to the system
14
2020-08-20
/etc
Contains configuration files required by all programs
This also contains startup and shutdown shell scripts used to start/stop individual
programs
/home
Stores home directories for all non-root users
/lib
Contains essential library files that support the binaries located under /bin and
/sbin
15
2020-08-20
/opt
opt stands for optional
/proc
Contains special files that represent system and process information
The directory /proc/{pid} contains information about the process with that
particular pid
16
2020-08-20
/root
home directory of the root user
/sbin
Similar to /bin, /sbin contains binary executables
/srv
Contains data for services provided by the system
For example:
● Website files could be stored in /srv/www
● CVS files could be stored in /srv/cvs
17
2020-08-20
/usr
Contains binaries, libraries, documentation, and source-code for second level
programs
/usr/bin contains binary files for user programs. For example: at, awk, cc, less, scp
/usr/sbin contains binary files for system administrators. For example: atd, cron,
sshd, useradd, userdel
/usr/local contains users programs that you install from source. For example,
when you install apache from source, it goes under /usr/local/apache2
/var
Content of files that are expected to change can be found under this directory
File Management
18
2020-08-20
Change Directory
To change directories use the cd command: cd ~/Downloads
Listing Files
List files and directories in a directory with ls command
Creating Files
Using the ‘touch’ command to create an empty file: touch myfile
Using the ‘echo’ command to redirect STDOUT to a file: echo “Hello” > myfile
Using the ‘cat’ command cat > myfile any text entered after this line will be sent to
the file ‘myfile’. End with Ctrl-D
19
2020-08-20
Summary
● Describe the Linux Shell
20
2020-08-20
● Linux Kernel
● Kernel Provisioning
References
Nemeth, E., & Snyder, G., Hein, T., Whaley, B., Mackin, D. (2018). UNIX and
Linux System Administration Handbook. Toronto: Addison-Wesley.
21