the unix shell
DESCRIPTION
The Unix Shell. The shell is a command interpreter It forms the interface between a user and the operating system. shell. When you log in to a Unix system, a shell starts running. You interact with the shell. Operating System. this is the shell prompt. this is where the shell - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/1.jpg)
The Unix Shell
![Page 2: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/2.jpg)
OperatingSystem
shell The shell is a command interpreterIt forms the interface between auser and the operating system
When you log in to a Unix system,a shell starts running. You interactwith the shell
![Page 3: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/3.jpg)
this is the shell prompt
the SHELL environment variable tellswhich shell is being used
this is where the shellprogram is located/bin/bash
![Page 4: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/4.jpg)
Unix Shells
Shell name Program (Command) namerc rcBourne Shell shC Shell cshBourne Again Shell bashZ shell zshKorn Shell kshTC tcsh
![Page 5: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/5.jpg)
Unix Shells
Shell name descriptionrc a very simple shell - similar to shBourne Shell developed at Bell labs - popularC Shell bsd unix - based on C languageBourne Again Shell open source version of sh - linux/osX Z shell extended sh - very large shellKorn Shell like sh but extensive scripting languageTC c shell with emacs-like command line
![Page 6: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/6.jpg)
you can change shells by typing the shell command
return to the default shellby typing “exit”
![Page 7: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/7.jpg)
The shell command line
prompt showscurrent directory.~ is your home directory
commandlist of arguments
![Page 8: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/8.jpg)
command options (usually preceded with a hyphen)
![Page 9: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/9.jpg)
What happens when you type a command?
The shell parses the command lineIt looks for a program that matches the commandIt starts a new process and runs that programWhile the program executes, the shell sleepsWhen the program is done, the shell wakes upIt displays its promptIt waits for the user to type another command
![Page 10: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/10.jpg)
Commandstdin stdout
Commands generally get their input fromstdin and send their output to stdout
![Page 11: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/11.jpg)
if you run the who command, the system tells you who is logged in and at what terminal.
but . . . this is really a file in the Unix file system thatrepresents a real device, in this case a terminal
commands read from and write to this file!
![Page 12: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/12.jpg)
the cat command is a good example. It takes its input from a fileand outputs to stdout.
![Page 13: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/13.jpg)
if you type the command with no parameters, it takes its inputfrom stdin. It will do this until you type ctrl-D (end of file).
![Page 14: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/14.jpg)
Redirection
You can cause the shell to get its input from some placeother than stdin or send its output to some place other than stdout by using redirection.
![Page 15: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/15.jpg)
Redirecting standard output
command [arguments] > filename
![Page 16: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/16.jpg)
redirect output to newduh.txt
![Page 17: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/17.jpg)
Concatenating Files with cat command
![Page 18: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/18.jpg)
Redirecting standard input
command [arguments] < filename
![Page 19: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/19.jpg)
cat takes its input from the file suppliesand writes to standard output
![Page 20: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/20.jpg)
Appending standard ouputto a file
command [arguments] >> filename
![Page 21: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/21.jpg)
![Page 22: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/22.jpg)
Pipes
The shell uses a pipe to connect the output of onecommand to the input of another command.
![Page 23: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/23.jpg)
Using a pipe
command_a [arguments] | command_b [arguments]
![Page 24: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/24.jpg)
The tr command translates each character in itsinput stream to the corresponding character in itsoutput stream.
![Page 25: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/25.jpg)
![Page 26: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/26.jpg)
Running a command in the background
command_a [arguments] &
the & tells the shell to run the command inthe background. This means that the shellprompt will appear immediately and you cantype in new commands without waiting for the background command to finish.
![Page 27: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/27.jpg)
Some useful Unix Commands
![Page 28: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/28.jpg)
cal
cal month yearcal yearcal
displays a monthly calendar
![Page 29: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/29.jpg)
cat
cat [options] file-list
concatenates files end to end
-e marks end of each line with a $-n displays line numbers
![Page 30: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/30.jpg)
cd
cd [directory]
change to the specified directory
cd with no arguments changes to your home directory
![Page 31: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/31.jpg)
chmod
chmod [options] mode file-list
symbolic u user + add permission g group - remove permission o other a all
changes permissions
![Page 32: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/32.jpg)
chmod
chmod [options] mode file-list
absolute xxx - a binary encoded value
777 - everyone can read, write, execute 755 - owner can read, write, execute, others can read, execute
changes permissions
![Page 33: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/33.jpg)
cp
cp [options] source-file destination-file
-i interactive, prompt if this will overwrite an existing file-r recursive, for directories, copies everything
copies files
![Page 34: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/34.jpg)
diff
diff [options] file-1 file-2
compares files
![Page 35: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/35.jpg)
find
find directory-list criteria
recursively searches in a given directory
-name file-name-type file-type-user user-name
![Page 36: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/36.jpg)
finger
finger [options] user-list
displays information for logged in users
-l detailed listing-s brief listing
![Page 37: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/37.jpg)
grep
grep [options] pattern [file-list]
searches files for a given pattern
-c display the number of lines that match-i ignore case-l display the filenames where a match is found-n displays each line with its line number in the file
![Page 38: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/38.jpg)
grep uses regular expressions in its pattern matching
Consider the file testregex that contains the lines
ringringingbringingtalktalkingwalking
![Page 39: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/39.jpg)
Simple strings
Consider the file testregex that contains the lines
ringringingbringingtalktalkingwalking
> grep ring testregexringringingbringing
![Page 40: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/40.jpg)
Period - represents any character
Consider the file testregex that contains the lines
ringringingbringingtalktalkingwalking
> grep .ing testregexringringingbringingtalkingwalking
![Page 41: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/41.jpg)
[ ] - represents a set of characters
Consider the file testregex that contains the lines
ringringingbringingtalktalkingwalking
> grep [tw] testregextalktalkingwalking
![Page 42: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/42.jpg)
^ - matches a string at the beginning of a line
Consider the file testregex that contains the lines
ringringingbringingtalktalkingwalking
> grep ^ri testregexringringing
![Page 43: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/43.jpg)
$ - matches a string at the end of a line
Consider the file testregex that contains the lines
ringringingbringingtalktalkingwalking
> grep ing$ testregexringringingbringingwalkingtalking
![Page 44: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/44.jpg)
head
head [number] file-list
displays the first number lines of a file
![Page 45: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/45.jpg)
kill
kill [signal-number] PID-list
kills a process
![Page 46: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/46.jpg)
ln
ln [option] existing-file link-name
create a link to a file
by default ln creates a hard link. Hard links must bein the same directory as the file being linked to.
the -s option creates a symbolic link. Symbolic links canbe across file systems and directories.
![Page 47: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/47.jpg)
ls
ls [options] file-list
list information about one or more files
-a list all entries, including invisible files-l show all file information-r shows all subdirectories
![Page 48: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/48.jpg)
t r w x r w x r w x links owner group size date_last_modified filename
type of filed directory- regular fileb block devicec character devicel symbolic linkp pipes socket
file
ow
ner
gro
up
oth
er
![Page 49: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/49.jpg)
mkdir
mkdir [option] directory-list
make a new directory
-p if the parent directory does not already exist, the create it.
![Page 50: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/50.jpg)
more
more [options] [file-list]
display a file, one screenful at a time
-n number output lines
![Page 51: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/51.jpg)
mv
mv [options] existing-name new-name
move (rename) a file
-f moves regardless of file permissions-i prompts if move would overwrite an existing file
![Page 52: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/52.jpg)
ps
ps [options]
displays the status of existing processes
-a display all processes associated with a terminal-e displays some environment information-l long display-x displays daemon processes
![Page 53: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/53.jpg)
rm
rm [options] file-list
remove a file
-f removes files for which you do not have write permission-i prompts before removing each file-r recursive
![Page 54: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/54.jpg)
rmdir
rmdir directory-list
remove an empty directory
![Page 55: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/55.jpg)
tail
tail [number] [file]
display the last number lines of a file
![Page 56: The Unix Shell](https://reader035.vdocuments.us/reader035/viewer/2022062409/5681474b550346895db48d96/html5/thumbnails/56.jpg)
who
who
display logged in users