Title: CS155: Unix Commands III Lecture 8
1CS155 Unix Commands IIILecture 8
2Review
- Use gt to redirect stderr and stdout
- Use Ctrl-Z, bg, fg, jobs, and to run multiple
jobs at the same time. - C-Shell keeps a history of commands which you can
use to speed up your work.
3Time Commands
- date Display the current date and time
- cal display a simple calendar
- -3 Display previous, current, and next month
- -y Display a calendar for the year
gt date Fri Feb 3 100217 MST 2006 gt cal
February 2006 Su Mo Tu We Th Fr Sa 1 2
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25 26 27 28
3
4System Commands
- uptime information on system load, number of
users, and uptime - who list of users currently logged in
- w combination of uptime and who
gt w 100841 up 1 day, 1841, 5 users, load
average 0.00, 0.01, 0.02 USER TTY FROM
LOGIN_at_ IDLE JCPU PCPU
WHAT boese 0 - Thu12
?xdm? 1250 0.02s /usr/bin/wmaker boese
pts/0 - Thu13 1525 0.14s
0.00s /usr/bin/perl / boese pts/2 -
1005 240 0.01s 0.01s
/usr/local/bin/ boese pts/1
18vpn220.vpn.col 1002 0.00s 0.04s 0.00s w
5Finding Things in the Filesystem
- When you execute a command or program, Unix
search a list of paths for the executable. - which give the full path of an executable
- whereis search all common executable
directories for binaries, man pages, source files.
6find
- find searches the file system for a file or
files based name or other features. - Usage find path expression
- find searches recursively from path down looking
for files that match expression.
7find Common Expressions
- -name pattern search for files with name
matching pattern. Pattern uses wildcard symbols. - find . name html
- Search for directories named html
- find . -name html or html
- Search for files and directories ending with html
gt find -name cs155 /s/chopin/k/fac/boese/mai
l/cs155 /s/chopin/k/fac/boese/school/cs155 /s/chop
in/k/fac/boese/school/BLAHcs155YO /s/chopin/k/fac/
boese/school/cs155_logins
8find Common Expressions
- -user uname file is owned by user
- Time-based
- -amin -n file access up to n minutes ago
- -ctime n file status last changed up to n24
hrs ago - -mtime n file was last modified up to n24
gt find -name cs155 /s/chopin/k/fac/boese/mai
l/cs155 /s/chopin/k/fac/boese/school/cs155 /s/chop
in/k/fac/boese/school/cs155/cs155 /s/chopin/k/fac/
boese/school/cs155/cs155_logins
9find Actions
- We can specify actions for find to perform on
each file it finds. - -delete delete found files
- -ls give full listing of files
- -exec command run command on files
- gt find . amin -5 ls
- 883353 4 drwx------ 5 boese fac 4096 Feb
1 1150 . - 2714705 12 -rw------- 1 boese fac 11534 Jan
17 1426 ./cs155 - 3467028 4 drwx------ 4 boese fac 4096 Jan
28 1037 ./hw2_files - find . name .bak exec mv old \
- Search for a string in a selection of files
(executing grep) - find . -exec grep Boese" '' \ -print
10find exec
- The exec action can be very handy.
- Everything after exec is considered part of the
command to execute until a is encountered.
The must be escaped by using \ because it
is a special character in the shell. - All occurrences of are replaced by the
full path to the found file.
11Miscellaneous Commands
- uname print system information
- -a print all information
- su - switch user (login in as different user)
- whoami get current user name
- touch change access and modification times of
files - bc Basic Calculator
12Miscellaneous Commands 2
- ispell spell check a file
- ping check whether IP Address is accessible
13Printing in Unix
Network
guitar.cs.colostate.edu
sitar.cs.colostate.edu
14Print Commands
- lpr send file to printer without formatting
- -Pprinter sent to printer
- lpr Pguitar my_file
- lpq list the printer queue
- printers print jobs on first in first out basis
- lpq gives order and status of print jobs
- -Pprinter specify the printer
- lprm remove print job
- lprm Pguitar 452
- lprm Pguitar -
15Print Commands
gt lpr Pguitar my_file gt lpr Pguitar my_file2 gt
lpq -Pguitar guitar is ready and printing Rank
Owner Job File(s) Total
Size active boese 1016 my_file
1944576 bytes 1st xhua 1021 (stdin)
12432 bytes 2nd boese 1028
my_file2 134144 bytes gt lprm
Pguitar 1028 gt lpq Pguitar guitar is ready and
printing Rank Owner Job File(s)
Total Size active xhua 1021 (stdin)
12432 bytes
16Printing
- enscriptenscript -2rGjdcymbal
- 2 2 columns
- r rotate (landscape/portrait)
- G fancy header (e.g. date, filename)
- j print borders around columns
- d printerName destination