Presentation on theme: "1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need."— Presentation transcript:
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need to know.
2 UNIX Consistency The version of the UNIX kernel that is used on a machine is determined by the architecture of the hardware. Many of the same shells are found across all the versions of UNIX. All the versions of UNIX “seem” to be the same due to the identical interface.
3 Shells Bourne shell (sh) – Only shell guaranteed to be on every version of UNIX – Probably the fastest shell due to its lack of fanciness C - shell (csh) – Uses C programming like syntax, but lacks a strong I/O component which makes scripting hard. Korn shell (ksh) – Combines functionality of C-shell with the scripting strength of Bourne shell. T – Shell (tcsh) – Much better interface than C shell, but not uniformly available across all UNIX. Is on miller / grid
4 Shell Commands Command line UNIX is the most powerful interface, but the most difficult to master. Commands follow a general format: – command [-options] [arguments] – “command” – this is the actual command that you are sending to the shell to be executed. – [-options] – Options are also referred to as ‘flags’. They are usually preceded with a minus sign (-) Options modify the functionality of a command. – [arguments] – Used to tell the command what to work with or what to work upon. The spaces allow for the shell to parse the command.
5 How the shell works Shell displays a prompt. – Example for miller: miller.cs: – Example for alpha: ( alpha ) n: where n is the number of commands so far. You type in a command. You press the return key. The shell interprets the commands you typed and tries to find the correct programs to run. The kernel runs the requested programs and returns the results to the shell. The shell displays the command prompt again.
6 Changing The Shell You can switch between which shell your using relatively easy. – On miller / grid Simply type the shell that you want to use. Example: miller.cs: tcsh – On alpha: use the ‘chsh’ command: Example: (alpha) 1: chsh Changing shell for SampleUser. Old shell: /usr/local/bin/tcsh New shell: csh
7 The Standard Input, Output and Error Standard input – stdin – The place the program normally looks for input. – The keyboard. Standard output – stdout – The place where the program normally sends its output. – The screen. Standard error – stderr – Used by programs to display error messages. – Also the screen.
8 Redirection, >> < – Redirects the standard input. [command] < [file name] – The command will open the file and use its content as its source of input. eg. wc < input.txt
9 Redirection, >> > – Redirects the standard output. [command] > [file name] – The results of the command will be sent to the specified file. – Will create or overwrite the destination file. eg cal 2007 > calendar.file
10 Redirection, >> >> - Also redirects the standard output. [command] >> [file name] - The results of the command will be sent to the specified file. - Will append the results of the command to the existing file. eg.cal 2008 >> calendar.file
11 Grouping commands Executing one command at at time can be tedious. Unix allows for grouping of commands by separating commands with a semi-colon (;). – Example: miller.cs: pwd; cal 1 2000; date
12 | (pipe) Used to link commands. – [command] | [command] etc. The output of the first command is sent as the input to the second command, and so on, and so on … – Example: miller.cs: who | more
13 Wildcards Typing in Unix can be tedious. Unix supports three wild-card characters: – Asterisk (*): matches any string of characters including blanks. – Question mark (?): matches single characters. – Square brackets (): Tells the shell to match any characters that appear inside the brackets.
14 Job control Unix works via jobs or processes. Every command or program is a separate process executed by a user. Processes are usually run in the foreground, but can be made to run in the background. Processes can be killed by the user who created them.
15 Job control ctrl-c: cancels a command/job – Good for breaking out of infinite loops! ctrl-z: suspends a command/job ‘ps’ displays the status of current processes – Example: miller.cs: ps PID TT S TIME COMMAND 3979 pts/131 S 0:00 -csh 5629 pts/131 S 0:00 tcsh
16 bg Forces a process to the background. First, type a ctrl-z to suspend the process. Then type bg and the process is forced to the background. Use the ps command to see it. You can force a process to the background immediately with the &.
17 fg Brings a process to the foreground. Use the ps command to see the processes you have running. Type fg %[number] and that process will be brought to the foreground.
18 kill Kills a process that you have running. Use the ps command to see what you have running. Type kill [number]. Not the most graceful way out, but it works.