Advanced Unix Commands How Unix works along with

  • Slides: 18
Download presentation
Advanced Unix Commands How Unix works along with some additional, useful Unix commands you

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

Shells z What is a shell? z Bourne shell y Developed by Steve Bourne

Shells z What is a shell? z Bourne shell y Developed by Steve Bourne at AT&T z Korn shell y Developed by David Korn at AT&T z C-shell y Developed by Bill Joy for Berkeley Unix z EZ-shell y Developed by somebody at UWM. 2

How the shell works z Shell displays a prompt. z You type in a

How the shell works z Shell displays a prompt. z You type in a command. z You press the return key. z The shell interprets the commands you typed and tries to find the correct programs to run. z The kernel runs the requested programs and returns the results to the shell. z The shell displays the command prompt again. 3

The Standard Input, Output and Error z Standard input y stdin y The place

The Standard Input, Output and Error z Standard input y stdin y The place the program normally looks for input. y The keyboard. z Standard error y stderr y Used by programs to display error messages. y Also the screen. z Standard output y stdout y The place where the program normally sends its output. y The screen. 4

Redirection <, >, >> z< y Redirects the standard input. x[command] < [file name]

Redirection <, >, >> z< y Redirects the standard input. x[command] < [file name] y The command will open the file and use its content as its source of input. 5

Redirection <, >, >> z> y Redirects the standard output. x[command] > [file name]

Redirection <, >, >> z> y Redirects the standard output. x[command] > [file name] y The results of the command will be sent to the specified file. y Will create or overwrite the destination file. xcat june july aug > summer 2000 6

Redirection <, >, >> z Also redirects the standard output. y [command] >> [file

Redirection <, >, >> z Also redirects the standard output. y [command] >> [file name] z The results of the command will be sent to the specified file. z Will append the results of the command to the existing file. 7

Grouping commands z Executing one command at at time can be tedious. z Unix

Grouping commands z Executing one command at at time can be tedious. z Unix allows for grouping of commands by separating commands with a semi-colon (; ). y pwd; cal 1 2000; date 8

| (pipe) z Similar to redirection and grouping. z Used to link commands. y

| (pipe) z Similar to redirection and grouping. z Used to link commands. y [command] | [command] etc. z The output of the first command is sent as the input to the second command, and so on … y who | more 9

Wildcards z Typing in Unix can be tedious. z Unix supports three wild-card characters:

Wildcards z Typing in Unix can be tedious. z Unix supports three wild-card characters: y Asterisk (*): matches any string of characters including blanks. y Question mark (? ): matches single characters. y Square brackest ([]): Tells the shell to match any characters that appear inside the brackets. z Quoting special characters 10

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

wc z word count z Used to display a word count of a file. y wc [-c l w] [file name(s)] z The output you will see will be a line showing the number of lines, words and characters. z Limit display with the flags. 11

sort z Sorts the contents of a file. y sort [-b f n r]

sort z Sorts the contents of a file. y sort [-b f n r] [file name(s)] z Takes the contents of a file and displays it in sorted order. z Flags: y -b: ignores blanks y -f: folds upper- and lowercase letters together y -n: numeric sort y -r: reverse usual order 12

Job control z Unix works via jobs or processes. z Every command or program

Job control z Unix works via jobs or processes. z Every command or program is a separate job/process executed by a user. z Jobs are usually run in the foreground, but can be made to run in the background. z Jobs can be killed by the user who created them. 13

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

Job control z ctrl-c: cancels a command/job z ctrl-z: suspends a command/job z jobs y Lists the jobs (programs) that you currently have running. 14

bg z Forces a job to the background. z First, type a ctrl-z to

bg z Forces a job to the background. z First, type a ctrl-z to suspend the job. z Then type bg and the job is forced to the background. z Use the jobs command to see it. z You can force a job to the background immediately with the &. 15

fg z Brings a job to the foreground. z Use the jobs command to

fg z Brings a job to the foreground. z Use the jobs command to see the jobs you have running. z Type fg %[number] and that job will be brought to the foreground. 16

kill z Kills a job that you have running. z Use the jobs command

kill z Kills a job that you have running. z Use the jobs command to see what you have running. z Type kill %[number]. z Not the most graceful way out, but it works. 17

Reading z Chapters 10 and 11. z Shell Customization 18

Reading z Chapters 10 and 11. z Shell Customization 18