unix/linux cs3353. the shell the shell is a program that acts as the interface between the user and...
TRANSCRIPT
![Page 1: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/1.jpg)
Unix/Linux
cs3353
![Page 2: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/2.jpg)
The Shell
• The shell is a program that acts as the interface between the user and the kernel.– The shell is fully programmable and will
interpret lists of commands entered by the user, or read cmds from a file (known as a script).
– A prompt is displayed by the shell program indicating it is ready to accept input from the user.
![Page 3: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/3.jpg)
Shell Types
• Bourne Shell (ALGOL syntax)– sh,– bash– ksh– zsh
• C-shell (based on C language syntax)– csh– tcsh
![Page 4: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/4.jpg)
Unix/Linux Commands
• commandName options files
• man commandName – to read about the command
Example: man find
![Page 5: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/5.jpg)
accounts
• Root– Has absolute control over the OS
• Regular– User login id number, string, and password.
![Page 6: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/6.jpg)
Shell Startup
• The .bash_profile (in place of the .profile) and .bashrc are used at TU.
• Ubuntu, .bashrc
![Page 7: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/7.jpg)
Linux Files
• Everything in the OS is organized into files.
• There is a i-node for every file on the file system (i = information)
![Page 8: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/8.jpg)
Files
• Regular files includes (aka ordinary)– executable (*) and – hidden files (.).
• Special files:– Symbolic link (@)– Directory (d)– Others: block special, named pipe, character special
Use the cmd: file filename
Use the ls command.
![Page 9: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/9.jpg)
The File System
• Navigate with cd, pwd, ls• Organized by directories
– mkdir, rmdir– cp, mv, rm
• / is known as root• /boot• /home• /var• /tmp
![Page 10: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/10.jpg)
Directory Pathnames
• Absolute – always begins with root /.
• Relative – does not begin with root
./aFile
bFile
/home/user/cFile
../data/dFile
![Page 11: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/11.jpg)
File names
• See pg 57
• 255 characters, no / allowed.
![Page 12: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/12.jpg)
ls –l
• Type-user-group-other
• -rwxr-xr—
• Token 1
• Token 2-4
• Token 5-7
• Token 8-10
• Access control is through the chmod cmd.
![Page 13: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/13.jpg)
chmod
• Octal:– chmod [ugo]+|-[rwx]– Octal r=4, w=2, x=1, the complement of
umask– X is required for a script to run (pg 29)
• Examples
![Page 14: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/14.jpg)
The Shell Env
• Variables– Local are only visible in the current process.– Environment variables are inherited by sub-
processes, Example: PATH– PATH is used by the shell to find commands
entered by the user.
export PATH=$PATH:.:~/bin
echo $PATH
![Page 15: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/15.jpg)
Input and Output
• STDIN = 0 the standard input
• STDOUT = 1 the standard output
• STDERR = 2 the standard error
• Most cmds are designed to display output to the stdout
• Many cmds are designed to read input from the stdin.
• Error messages go to stderr.
![Page 16: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/16.jpg)
Input & Output
• The default location for output is the terminal screen.
• It is possible to redirect the output of a command to:– Another command using a pipe |– A file using the output redirect symbol >
Example: date > aFile
ps | wc –l
![Page 17: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/17.jpg)
Input & Output
• It is possible to control the input to a command• The read command is designed to capture input from the
standard input:
cat << stop > file>Steve>stopgreeting < file
echo “What is your name?”read Nameecho “Greetings $Name”
![Page 18: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/18.jpg)
Processes
• Init is process id # 1
• Dummy processes during system startup do not have a process ID.
• All other processes have a process ID.
![Page 19: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/19.jpg)
Example
• Use ps and sleep to introduce background processes using the &
• ps will show processes running on a system.
• A process can be stopped (killed) by using the PID.
kill pid
![Page 20: Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will](https://reader036.vdocuments.us/reader036/viewer/2022072017/56649f0d5503460f94c20798/html5/thumbnails/20.jpg)
Substitution (Meta Characters)
• *, ?, [range]
• !, ^, $