1 advanced unix commands how unix works along with some additional, useful unix commands you might...

18
1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know.

Upload: sheryl-wilcox

Post on 05-Jan-2016

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

1

Advanced Unix Commands

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

Page 2: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

2

Shells

What is a shell? Bourne shell

Developed by Steve Bourne at AT&T

Korn shell Developed by David Korn at AT&T

C-shell Developed by Bill Joy for Berkeley Unix

EZ-shell Developed by somebody at UWM.

Page 3: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

3

How the shell works

Shell displays a prompt. 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 4: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

4

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.

Page 5: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

5

Redirection <, >, >>

< Redirects the standard input.

[command] < [file name] The command will open the file and use its content as

its source of input.

Page 6: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

6

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.

cat june july aug > summer2000

Page 7: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

7

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.

Page 8: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

8

Grouping commands

Executing one command at at time can be tedious.

Unix allows for grouping of commands by separating commands with a semi-colon (;). pwd; cal 1 2000; date

Page 9: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

9

| (pipe)

Similar to redirection and grouping. 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 … who | more

Page 10: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

10

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 brackest ([]): Tells the shell to match any

characters that appear inside the brackets.

Quoting special characters

Page 11: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

11

wc

word count Used to display a word count of a file.

wc [-c l w] [file name(s)]

The output you will see will be a line showing the number of lines, words and characters.

Limit display with the flags.

Page 12: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

12

sort

Sorts the contents of a file. sort [-b f n r] [file name(s)]

Takes the contents of a file and displays it in sorted order.

Flags: -b: ignores blanks -f: folds upper- and lowercase letters together -n: numeric sort -r: reverse usual order

Page 13: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

13

Job control

Unix works via jobs or processes. Every command or program is a separate

job/process executed by a user. Jobs are usually run in the foreground, but can be

made to run in the background. Jobs can be killed by the user who created them.

Page 14: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

14

Job control

ctrl-c: cancels a command/job ctrl-z: suspends a command/job jobs

Lists the jobs (programs) that you currently have running.

Page 15: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

15

bg

Forces a job to the background. First, type a ctrl-z to suspend the job. Then type bg and the job is forced to the

background. Use the jobs command to see it. You can force a job to the background

immediately with the &.

Page 16: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

16

fg

Brings a job to the foreground. Use the jobs command to see the jobs you have

running. Type fg %[number] and that job will be brought

to the foreground.

Page 17: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

17

kill

Kills a job that you have running. Use the jobs command to see what you have

running. Type kill %[number]. Not the most graceful way out, but it works.

Page 18: 1 Advanced Unix Commands How Unix works along with some additional, useful Unix commands you might like to know

18

Reading

Chapters 10 and 11. Shell Customization