Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Unix Shell. Operating System shell The shell is a command interpreter It forms the interface between a user and the operating system When you log.

Similar presentations


Presentation on theme: "The Unix Shell. Operating System shell The shell is a command interpreter It forms the interface between a user and the operating system When you log."— Presentation transcript:

1 The Unix Shell

2 Operating System shell The shell is a command interpreter It forms the interface between a user and the operating system When you log in to a Unix system, a shell starts running. You interact with the shell

3 this is the shell prompt the SHELL environment variable tells which shell is being used this is where the shell program is located /bin/bash

4 Unix Shells Shell nameProgram (Command) namerc Bourne Shellsh C Shellcsh Bourne Again Shellbash Z shellzsh Korn Shellksh TCtcsh

5 Unix Shells Shell name description rca very simple shell - similar to sh Bourne Shelldeveloped at Bell labs - popular C Shellbsd unix - based on C language Bourne Again Shellopen source version of sh - linux/osX Z shellextended sh - very large shell Korn Shelllike sh but extensive scripting language TCc shell with emacs-like command line

6 you can change shells by typing the shell command return to the default shell by typing “exit”

7 The shell command line prompt shows current directory. ~ is your home directory command list of arguments

8 command options (usually preceded with a hyphen)

9 What happens when you type a command? The shell parses the command line It looks for a program that matches the command It starts a new process and runs that program While the program executes, the shell sleeps When the program is done, the shell wakes up It displays its prompt It waits for the user to type another command

10 Command stdin stdout Commands generally get their input from stdin and send their output to stdout

11 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 that represents a real device, in this case a terminal commands read from and write to this file!

12 the cat command is a good example. It takes its input from a file and outputs to stdout.

13 if you type the command with no parameters, it takes its input from stdin. It will do this until you type ctrl-D (end of file).

14 Redirection You can cause the shell to get its input from some place other than stdin or send its output to some place other than stdout by using redirection.

15 Redirecting standard output command [arguments] > filename

16 redirect output to newduh.txt

17 Concatenating Files with cat command

18 Redirecting standard input command [arguments] < filename

19 cat takes its input from the file supplies and writes to standard output

20 Appending standard ouput to a file command [arguments] >> filename

21

22 Pipes The shell uses a pipe to connect the output of one command to the input of another command.

23 Using a pipe command_a [arguments] | command_b [arguments]

24 The tr command translates each character in its input stream to the corresponding character in its output stream.

25

26 Running a command in the background command_a [arguments] & the & tells the shell to run the command in the background. This means that the shell prompt will appear immediately and you can type in new commands without waiting for the background command to finish.

27 Some useful Unix Commands

28 cal cal month year cal year cal displays a monthly calendar

29 cat cat [options] file-list concatenates files end to end -emarks end of each line with a $ -ndisplays line numbers

30 cd cd [directory] change to the specified directory cd with no arguments changes to your home directory

31 chmod chmod [options] mode file-list symbolic u user+ add permission g group- remove permission o other a all changes permissions

32 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

33 cp cp [options] source-file destination-file -iinteractive, prompt if this will overwrite an existing file -rrecursive, for directories, copies everything copies files

34 diff diff [options] file-1 file-2 compares files

35 find find directory-list criteria recursively searches in a given directory -name file-name -type file-type -user user-name

36 finger finger [options] user-list displays information for logged in users -ldetailed listing -sbrief listing

37 grep grep [options] pattern [file-list] searches files for a given pattern -cdisplay the number of lines that match -iignore case -ldisplay the filenames where a match is found -ndisplays each line with its line number in the file

38 grep uses regular expressions in its pattern matching Consider the file testregex that contains the lines ring ringing bringing talk talking walking

39 Simple strings Consider the file testregex that contains the lines ring ringing bringing talk talking walking > grep ring testregex ring ringing bringing

40 Period - represents any character Consider the file testregex that contains the lines ring ringing bringing talk talking walking > grep.ing testregex ring ringing bringing talking walking

41 [ ] - represents a set of characters Consider the file testregex that contains the lines ring ringing bringing talk talking walking > grep [tw] testregex talk talking walking

42 ^ - matches a string at the beginning of a line Consider the file testregex that contains the lines ring ringing bringing talk talking walking > grep ^ri testregex ring ringing

43 $ - matches a string at the end of a line Consider the file testregex that contains the lines ring ringing bringing talk talking walking > grep ing$ testregex ring ringing bringing walking talking

44 head head [number] file-list displays the first number lines of a file

45 kill kill [signal-number] PID-list kills a process

46 ln ln [option] existing-file link-name create a link to a file by default ln creates a hard link. Hard links must be in the same directory as the file being linked to. the -s option creates a symbolic link. Symbolic links can be across file systems and directories.

47 ls ls [options] file-list list information about one or more files -alist all entries, including invisible files -lshow all file information -rshows all subdirectories

48 t r w x r w x r w x links owner group size date_last_modified filename type of file d directory - regular file b block device c character device l symbolic link p pipe s socket file owner group other

49 mkdir mkdir [option] directory-list make a new directory -pif the parent directory does not already exist, the create it.

50 more more [options] [file-list] display a file, one screenful at a time -nnumber output lines

51 mv mv [options] existing-name new-name move (rename) a file -fmoves regardless of file permissions -iprompts if move would overwrite an existing file

52 ps ps [options] displays the status of existing processes -adisplay all processes associated with a terminal -edisplays some environment information -llong display -xdisplays daemon processes

53 rm rm [options] file-list remove a file -fremoves files for which you do not have write permission -iprompts before removing each file -r recursive

54 rmdir rmdir directory-list remove an empty directory

55 tail tail [number] [file] display the last number lines of a file

56 who display logged in users


Download ppt "The Unix Shell. Operating System shell The shell is a command interpreter It forms the interface between a user and the operating system When you log."

Similar presentations


Ads by Google