390alecture03 12sp
390alecture03 12sp
390alecture03 12sp
Lecture summary
A bit more on combining commands
Text editors
slides created by Marty Stepp, modified by Jessica Miller and Ruth Anderson http://www.cs.washington.edu/390a/
1 2
Tricky Examples
The wc command can take multiple files: wc names.txt student.txt
Can we use the following to wc on every txt file in the directory?
ls *.txt | wc
command1 | command2
Use the console output of command1 as the input to command2
Amongst the top 250 movies in movies.txt, display the third to last movie that contains "The" in the title when movies titles are sorted. Find the disk space usage of the man program
Hints: use which and du... Does which man | du work?
command1 ; command2
Run command1 and then run command2
The back-tick
command1 `command2`
run command2 and pass its console output to command1 as a parameter; ` is a back-tick, on the ~ key; not an apostrophe best used when command2's output is short (one line)
command xargs
xargs
description run each line of input as an argument to a specified command
4/9/2012
Processes
process: a program that is running (essentially)
when you run commands in a shell, it launches a process for each command Process management is one of the major purposes of an OS
PID: 1232 Name: ls
Process commands
command ps or jobs top kill description list processes being run by a user; each process has a unique integer id (PID) show which processes are using CPU/memory; also shows stats about the computer terminate a process by PID terminate several processes by name
killall
PID: 1343 Name: man PID: 1723 Name: Mozilla PID: 1288 Name: cp
Background processes
command & ^Z fg , bg description (special character) when placed at the end of a command, runs that command in the background (hotkey) suspends the currently running process resumes the currently suspended process in either the foreground or background
Linux/Unix are built to be used in multi-user environments where several users are logged in to the same machine at the same time
users can be logged in either locally or via the network
If you run a graphical program like gedit from the shell, the shell will lock up waiting for the graphical program to finish
instead, run the program in the background, so the shell won't wait: $ gedit resume.txt & if you forget to use & , suspend gedit with ^Z , then run bg lets play around with an infinite process
9
Multi-user environments
command whoami passwd hostname w or finger write description outputs your username changes your password outputs this computer's name/address see info about people logged in to this server send a message to another logged in user
4/9/2012
Network commands
command links or lynx ssh sftp or scp wget curl alpine, mail description text-only web browsers (really!) connect to a remote server transfer files to/from a remote server (after starting sftp, use get and put commands) download from a URL to a file download from a URL and output to console text-only email programs command pico or nano emacs vi or vim
Text editors
description simple but crappy text editors (recommended) complicated text editor complicated text editor
13
14
Aliases
description assigns a pseudonym to a command alias
sshfs
An alternate usage model to remotely connecting to servers is mounting remote directories and files and work on them locally
once mounted, use remote directories and files as if they were local
Example: When I type q , I want it to log me out of my shell. Example: When I type ll , I want it to list all files in long format.
alias q=exit alias ll="ls -la"
Exercise : Make it so that typing q quits out of a shell. Exercise : Make it so that typing woman runs man. Exercise : Make it so that typing attu connects me to attu.
16