The Schell
Boiled down:
Command line syntax |
Command editing |
Processing a Command |
stdin, stdout, stderr |
fg, bg |
pipes |
/dev/null |
process control |
Command Line Syntax
- Command [arg1] [arg2] ? [argn] RETURN
- Arguments numbered; command is arg0
- Option/flags - modify the effect of the command
Command Editing
- ctrl-u - erase a line
- ctrl-w - erase a word
- ctrl-h - erase a character
- ctrl-r
Processing a Command
- Shell is running, interprets the command
- Finds the command by checking (in order) $PATH
- Shell execs the command and goes to sleep
- When command finished, shell wakes up, issues prompt and waits for another command
- To change your shell - chsh
Stdin and Stdout
- Standard input (stdin) has fileID 0
- Standard output (stdout) has file ID 1
- Standard error (stderr) has file ID 2
- The who command reports the filename of your window (tty01)
- The cat command copies stdin to stdout
- $ cat
will keep echoing everything you type until ctrl-d is entered
Redirection
- > redirects stdout
- > will overwrite the file
- < redirects stdin
- >> redirects stdout and appends it
- /dev/null (a bit bucket) is a place you can redirect output you do not want
- to redirect stderr to stdout
command 2 >&1
- to redirect stdout to stderr
command 1 >&2
Pipes
- connects stdout of one command to stdin of the next command?
$ tr str1 str2
translates the matched character in str1 to the corresponding character in str2. (1st character in string1translated to 1st character in string2)
- Filters modify a stream of input and produce a stream of output (eg. sort)
- The tee command single input, 2 outputs
$ who | tee file | grep string
output from who goes to file and into grep
Process Control
- To run a program in the background use &
- ps tells what processes are running
- kill is used to terminate processes
- ctrl-z interrupts a running process
- bg %n places an interrupted process into the background. (n is the job number)
- jobs tells what processes are running and there status
- fg %n brings a job to the foreground
All work herein is subject to copyright. Original content to Dr. Deborah Whitfield, text content (Practical Guide to Linux) to Prentice Hall publishing.