1 the shell and some useful administrative unix commands how unix works along with some additional,...

18
1 The Shell and some The Shell and some useful administrative useful administrative Unix Commands Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need to know.

Upload: harriet-hopkins

Post on 17-Dec-2015

218 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

1

The Shell and some useful The Shell and some useful administrative Unix Commandsadministrative Unix Commands

How Unix works along with some additional, useful administrative Unix commands you might need to know.

Page 2: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

2

UNIX ConsistencyUNIX 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.

Page 3: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

3

ShellsShells 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

Page 4: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

4

Shell CommandsShell 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.

Page 5: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

5

How the shell worksHow 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.

Page 6: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

6

Changing The ShellChanging 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

Page 7: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

7

The Standard Input, Output and The Standard Input, Output and ErrorError

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.

Page 8: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

8

Redirection <, >, >>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

Page 9: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

9

Redirection <, >, >>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

Page 10: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

10

Redirection <, >, >>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

Page 11: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

11

Grouping commandsGrouping 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

Page 12: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

12

| (pipe)| (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

Page 13: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

13

WildcardsWildcards

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.

Page 14: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

14

Job controlJob 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.

Page 15: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

15

Job controlJob 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: psPID TT S TIME COMMAND 3979 pts/131 S 0:00 -csh 5629 pts/131 S 0:00 tcsh

Page 16: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

16

bgbg

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 &.

Page 17: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

17

fgfg

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.

Page 18: 1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need

18

killkill

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.