Appendix A. Useful UNIX Utilities for Shell Programmers

CONTENTS

Appendix A. Useful UNIX Utilities for Shell Programmers

  •  at at, batch execute commands at a later time
  •  awk pattern scanning and processing language
  •  banner make posters
  •  basename with a directory name delivers portions ofthe pathname
  •  bc processes precision arithmetic
  •  bdiff compares two big files
  •  cal displays a calendar
  •  cat concatenates and displays files
  •  chmod change the permissions mode of a file
  •  chown changes owner of file
  •  clear clears the terminal screen
  •  cmp compares two files
  •  compress compress, uncompress, zcat compress,uncompress files, or display expanded files
  •  cp copies files
  •  cpio copy file archives in and out
  •  cron the clock daemon
  •  crypt encodes or decodes a file
  •  cut removes selected fields or characters from eachline of a file
  •  date displays the date and time or sets the date
  •  diff compares two files for differences diff [ bitw][ c | Cn
  •  du summarizes disk usage
  •  echo echoes arguments
  •  egrep searches a file for a pattern using fullregular expressions
  •  expr evaluates arguments as an expression
  •  fgrep search a file for a character string
  •  file determines the type of a file by looking atits contents
  •  find finds files
  •  finger displays information about local and remoteusers
  •  fmt simple text formatters
  •  fold folds long lines
  •  ftp file transfer program
  •  getopt(s) parses command line options
  •  grep searches a file for a pattern
  •  groups prints group membership of user
  •  id prints the username, user ID, group name andgroup ID
  •  jsh the standard, job control shell
  •  line reads one line
  •  logname gets the name of the user running theprocess
  •  lp sends output to a printer (AT&T)
  •  lpr sends output to a printer (UCB)
  •  lpstat print information about the status of the LPprint service (AT&T)
  •  lpq print information about the status of theprinter (UCB)
  •  ls lists contents of directory
  •  mail mail, rmail read mail or send mail to users
  •  mailx interactive message processing system
  •  make maintains, updates, and regenerates groups ofrelated programs and files
  •  mesg permits or denies messages resulting from thewrite command
  •  mkdir creates a directory
  •  more browse or page through a text file
  •  mv move or rename files
  •  nawk pattern scanning and processing language
  •  newgrp log in to a new group
  •  news prints news items
  •  nice runs a command at low priority
  •  nohup makes commands immune to hangups and quits
  •  od octal dump
  •  pack pack, pcat, unpack compresses and expandsfiles
  •  passwd changes the login password and passwordattributes
  •  paste merges same lines of several files orsubsequent lines of one file
  •  pcat (see pack)
  •  pg displays files a page at a time
  •  pr prints files
  •  ps reports process status
  •  pwd displays the present working directory name
  •  rcp remote file copy
  •  rlogin remote login
  •  rm removes files from directories
  •  rmdir removes a directory
  •  rsh starts a remote shell
  •  ruptime shows the host status of local machines
  •  rwho who is logged in on local machines
  •  script creates a typescript of a terminal session
  •  sed streamlined editor
  •  size prints section sizes in bytes of object files
  •  sleep suspends execution for some number of seconds
  •  spell finds spelling errors
  •  split splits a file into pieces
  •  strings finds any printable strings in an object orbinary file
  •  stty sets the options for a terminal
  •  su become superuser or another user
  •  sum calculates a checksum for a file
  •  sync updates the superblock and sends changedblocks to disk
  •  tabs set tab stops on a terminal
  •  tail displays the tail end of a file.
  •  talk allows you to talk to another user
  •  tar stores and retrieves files from an archivefile, normally a tape device
  •  tee replicates the standard output
  •  telnet communicates with a remote host
  •  test evaluates an expression
  •  time displays a summary of time used by this shelland its children
  •  timex times a command; reports process data andsystem activity
  •  touch updates access time and/or modification timeof a file
  •  tput initializes a terminal or queries theterminfo database
  •  tr translates characters
  •  true provide successful exit status
  •  tsort topological sort
  •  tty gets the name of the terminal
  •  umask sets file-creation mode mask for permissions
  •  uname prints name of current machine
  •  uncompress restores files to their original stateafter they have been compressed using the compress command
  •  uniq reports on duplicate lines in a file
  •  units converts quantities expressed in standardscales to other scales
  •  unpack expands files created bypack
  •  uucp copy files to another system, UNIX-to-UNIXsystem copy
  •  uuencode uuencode, uudecode encode a binary fileinto ASCII text in order to send it through e-mail, or convert it back into itsoriginal form
  •  wc counts lines, words, and characters
  •  what extracts SCCS version information from a fileby printing information found after the @(#) pattern
  •  which locates a command and displays its pathnameor alias (UCB)
  •  whereis locates the binary, source, and manual pagefiles for a command (UCB)
  •  who displays who is logged on the system
  •  write writes a message to another user
  •  xargs constructs an argument list(s) and executes acommand
  •  zcat uncompress a compressed file to standardoutput. Same as uncompress c

at at, batch execute commands at a later time


at [ csm] [ f script] [ qqueue] time [date] [+ increment]
at  l [ job...]
at  r job...
batch
 

at and batch read commands from standard input to be executed at a later time. at allows you to specify when the commands should be executed, while jobs queued with batch will execute when system load level permits. Executes commands read from stdin or a file at some later time. Unless redirected, the output is mailed to the user.

Example A.1
1   at 6:30am Dec 12 < program 2   at noon tomorrow < program 3   at 1945 pm August 9 < program 4   at now + 3 hours < program 5   at 8:30am Jan 4 < program 6   at -r 83883555320.a

EXPLANATION

  1. At 6:30 in the morning on December 12th, start the job.

  2. At noon tomorrow start the job.

  3. At 7:45 in the evening on August 9th, start the job.

  4. In three hours start the job.

  5. At 8:30 in the morning of January 4th, start the job.

  6. Removes previously scheduled job 83883555320.a.

awk pattern scanning and processing language


awk [  fprogram file ] [  Fc ] [ prog ] [ parameters ]
[ filename...]
 

awk scans each input filename for lines that match any of a set of patterns specified in prog.

Example A.2
1   awk '{print $1, $2}' file 2   awk '/John/{print $3, $4}' file 3   awk -F: '{print $3}' /etc/passwd 4   date | awk '{print $6}'

EXPLANATION

  1. Prints the first two fields of file where fields are separated by whitespace.

  2. Prints fields 3 and 4 if the pattern John is found.

  3. Using a colon as the field separator, prints the third field of the /etc/passwd file.

  4. Sends the output of the date command to awk and prints the sixth field.

banner make posters

banner prints its arguments (each up to 10 characters long) in large letters on the standard output.

Example A.3
banner Happy Birthday 

EXPLANATION

Displays in banner format the string Happy Birthday.

basename with a directory name delivers portions of the pathname


basename string [ suffix ]
dirname string
 

basename deletes any prefix ending in / (forward slash) and the suffix (if present in string) from string, and prints the result on the standard output.

Example A.4
1   basename /usr/local/bin 2   scriptname="'basename $0'" 

EXPLANATION

  1. Strips off the prefix /usr/local/ and displays bin.

  2. Assigns just the name of the script, $0, to the variable scriptname

bc processes precision arithmetic


bc [  c ] [  l ] [ filename...]
 

bc is an interactive processor for a language that resembles C but provides unlimited precision arithmetic. It takes input from any files given, then reads the standard input.

Example A.5
1   bc << EOF     scale=3     4.5 + 5.6 / 3     EOF     Output : 6.366     ----------------------------- 2   bc     ibase=2     5     101 (Output)     20     10100 (Output     ^D 

EXPLANATION

  1. This is a here document. From the first EOF to the last EOF input is given to the bc command. The scale specifies the number of digits to the right of the decimal point. The result of the calculation is displayed on the screen.

  2. The number base is two. The number is converted to binary (AT&T only).

bdiff compares two big files

bdiff compares two files that are too large for diff.

cal displays a calendar


cal [ [ month ] year ]
 

cal prints a calendar for the specified year. If a month is also specified, a calendar just for that month is printed. If neither is specified, a calendar for the present month is printed.

Example A.6
1   cal 1997 2   cal 5 1978 

EXPLANATION

  1. Prints the calendar year 1997.

  2. Prints the month of May for 1978.

cat concatenates and displays files


cat [  bnsuvet ] filename...
 

cat reads each filename in sequence and writes it on the standard output. If no input file is given, or if the argument is encountered, cat reads from the standard input file.

Example A.7
1   cat /etc/passwd 2   cat -n file1 file2 >> file3 

EXPLANATION

  1. Displays the contents of the /etc/passwd file.

  2. Concatenates file1 and file2 and appends output to file3. The n switch causes each line to be numbered.

chmod change the permissions mode of a file


chmod [  fR ] mode filename...
chmod [ugoa ]{ + |   | = }[ rwxlsStTugo] filename...
 

chmod changes or assigns the mode of a file. The mode of a file specifies its permissions and other attributes. The mode may be absolute or symbolic.

Example A.8
1   chmod +x script.file 2   chmod u+x,g-x file 3   chmod 755 * 

EXPLANATION

  1. Turns on execute permission for user, group, and others on script.file.

  2. Turns on execute permission for user, and removes it from group on file.

  3. Turns on read, write, and execute for the user, read and execute for the group, and read and execute for others on all files in the current working directory. The value is octal ( 111 101 101 ).

    rwxxr-xr-x 

chown changes owner of file


chown [  fhR ] owner filename ...
 

chown changes the owner of the files to owner. The owner may be either a decimal user ID or a login name found in /etc/passwd file. Only the owner of a file (or the superuser) may change the owner of that file.

Example A.9
1   chown john filex 2   chown -R ellie ellie 

EXPLANATION

  1. Changes the user ID of filex to john.

  2. Recursively changes the ownership to ellie for all files in ellie directory.

clear clears the terminal screen

cmp compares two files


cmp [  l ] [  s ] filename1 filename2
 

The two files are compared. cmp makes no comment if the files are the same; if they differ, it announces the byte and line numbers at which the first difference occurred.

Example A.10
cmp file.new file.old 

EXPLANATION

If the files differ, the character number and the line number are displayed.

compress compress, uncompress, zcat compress, uncompress files, or display expanded files


compress [  cfv ] [  b bits ] [ filename... ]
uncompress [  cv ] [ filename... ]
zcat [ filename... ]
 

compress reduces the size of the named files using adaptive Lempel-Ziv coding. Whenever possible, each file is replaced by one with a .Z extension. The ownership modes, access time, and modification time will stay the same. If no files are specified, the standard input is compressed to the standard output.

Example A.11
1   compress -v book     book:Compression:35.07% -- replaced with book.Z 2   ls     book.Z 

EXPLANATION

  1. Compresses the book into a file called book.Z and displays the percentage that the file was compressed and its new name.

cp copies files


cp [  i ] [  p ] [  r ] [ filename ... ] target
 

The cp command copies filename to another target, which is either a file or directory. The filename and target cannot have the same name. If the target is not a directory, only one file may be specified before it; if it is a directory, more than one file may be specified. If target does not exist, cp creates a file named target. If target exists and is not a directory, its contents are overwritten. If target is a directory, the file(s) are copied to that directory.

Example A.12
1   cp file1 file2 2   cp chapter1 book 3   cp -r desktop /usr/bin/tester 

EXPLANATION

  1. Copies the contents of file1 to file2.

  2. Copies the contents of chapter1 to the book directory. In the book directory, chapter1 has its original name.

  3. Recursively copies the entire desktop directory into /usr/bin/tester.

cpio copy file archives in and out


cpio  i [ bBcdfkmrsStuvV6 ] [  C bufsize ] [  E filename ]
 [  H header ] [  I filename [  M message ] ] [  R id ]
 [ pattern ... ]
cpio  o [ aABcLvV ] [  C bufsize ] [  H header ]
 [  O filename [  M message ] ]
cpio  p [ adlLmuvV ] [  R id ] directory
 

Copies file archives according to the modifiers given, usually for backup to a tape or directory.

Example A.13
find . -depth -print | cpio -pdmv /home/john/tmp 

EXPLANATION

Starting at the current directory, find descends the directory hierarchy, printing each entries of the directory even if the directory does not have write permission, and sends the filenames to cpio to be copied into the john/tmp directory in the /home partition.

cron the clock daemon

cron executes commands at specified dates and times. Regularly scheduled jobs can be specified in the /etc/crontab file. In order to use cron, one of the following must be true: (1) you are superuser; (2) you are regular user, but your user ID is listed in the /etc/cron.allow file; (3) you are regular user, but your system contains a file /etc/cron.deny, which is empty.

crypt encodes or decodes a file


crypt [ password ]
 

crypt encrypts and decrypts the contents of a file. The password is a key that selects a type of transformation.

cut removes selected fields or characters from each line of a file


cut  clist [ filename ... ]
cut  flist [  dc ] [  s ] [ filename ... ]
 

The cut command cuts out columns or characters from a line of a file; if no files are given, uses standard input. The d option specifies the field delimiter. The default delimiter is a tab.

Example A.14
1   cut -d: -f1,3 /etc/passwd 2   cut -d: -f1-5 /etc/passwd 3   cut -c1-3,8-12 /etc/passwd 4   date | cut -c1-3

EXPLANATION

  1. Using the colon as a field delimiter, displays fields 1 and 3 of the /etc/passwd file.

  2. Using the colon as a field separator, displays fields 1 through 5 of the etc/passwd file.

  3. Cuts and displays characters 1 through 3 and 8 through 12 of each line from the /etc/passwd file.

  4. Sends the output of the date command as input to cut. The first three characters are printed.

date displays the date and time or sets the date


[  u ] [  a [   ] sss.fff ] [ yymmddhhmm [ .ss ] ]
[+format ]
 

Without arguments, the date command displays the date and time. If the command line argument starts with a plus sign, the rest of the argument is used to format the output. If a percent sign is used, the next character is a formatting character to extract a particular part of the date, such as just the year or weekday. To set the date. the command line argument is expressed in digits representing the year, month, day, hours, and minutes.

Example A.15
1   date +%T 2   date +20%y 3   date "+It is now %m/%d /%y"

EXPLANATION

  1. Displays the time as 20:25:51

  2. Displays 2096.

  3. Displays It is now 07/25/96.

diff compares two files for differences diff [ bitw] [ c | Cn

Compares two files and displays the differences on a line-by-line basis. Also displays commands that you would use with the ed editor to make changes.

Example A.16
diff file1 file2 1c1 < hello there --- > Hello there. 2a3 > I'm fine.

EXPLANATION

Shows how each line of file1 and file2 differs. The first file is represented by the < symbol, and the second file by the > symbol. Each line is preceded by an ed command indicating the editing command that would be used to make the files the same.

du summarizes disk usage


du [ arskod] [name ...]
 

The du command reports the number of 512-byte blocks contained in all files and (recursively) directories within each directory and file specified.

Example A.17
1   du -s /desktop 2   du -a

EXPLANATION

  1. Displays a summary of the block usage for all the files in /desktop and its subdirectories.

  2. Displays block usage for each file in this directory and subdirectories.

echo echoes arguments


echo [ argument ] ...
echo [  n ] [ argument ]
 

echo writes its arguments separated by blanks and terminated by a newline on the standard output.


System V echo options:
\b       backspace
\c       suppress newline
\f       form feed
\n       newline
\r       return
\t       tab
\v       vertical tab
\\       backslash
\0n n is a 1, 2, or 3, octal value
 

egrep searches a file for a pattern using full regular expressions


egrep [  bchilnsv ] [  e special expression ][  f filename ]
[ strings ] [ filename ... ]
 

egrep (expression grep) searches files for a pattern of characters and prints all lines that contain that pattern. egrep uses full regular expressions (expressions with string values that use the full set of alphanumeric and special characters) to match the patterns.

Example A.18
1   egrep 'Tom|John' datafile 2   egrep '^ [A-Z]+' file

EXPLANATION

  1. Display all lines in datafile containing the pattern either Tom or John.

  2. Display al lines starting with one or more uppercase letters.

expr evaluates arguments as an expression


expr arguments
 

The arguments are taken as an expression. After evaluation, the result is written to the standard output. The terms of the expression must be separated by blanks. Characters special to the shell must be escaped. Used in Bourne shell scripts for performing simple arithmetic operations.

Example A.19
1   expr 5 + 4 2   expr 5 \* 3 3   num=0     num='expr $num + 1'

EXPLANATION

  1. Prints the sum of 5 + 4

  2. Prints of result of 5 * 3. The asterisk is protected from shell expansion.

  3. After assigning 0 to variable num, the expr command adds 1 to num and result is assigned to num.

fgrep search a file for a character string


fgrep [  bchilnsvx ] [  e special string ]
[  f filename ] [ strings ] [ filename ... ]
 

fgrep (fast grep) searches files for a character string and prints all lines that contain that string. fgrep is different from grep and egrep because it interprets regular expression metacharacters as literals.

Example A.20
1   fgrep '***' * 2   fgrep '[ ] * ? $' filex

EXPLANATION

  1. Displays any line containing three asterisks from each file in the present directory. All characters are treated as themselves; i.e., metacharacters are not special.

  2. Displays any lines in filex containing the string enclosed in quotes.

file determines the type of a file by looking at its contents


file [[  f ffile ] [  cl ] [  m mfile ] filename...
 

file performs a series of tests on each filename in an attempt to determine what it contains. If the contents of the file appear to be ASCII text, file examines the first 512 bytes and tries to guess its language.

Example A.21
1   file bin/ls     /bin/ls:sparc pure dynamically linked executable 2   file go     go:    executable shell script 3   file junk     junk:  English text

EXPLANATION

  1. ls is a binary file dynamically linked when executed.

  2. go is an executable shell script.

  3. junk is a file containing ASCII text.

find finds files


find path name list expression
 

find recursively descends the directory hierarchy for each pathname in the pathname list (i.e., one or more pathnames) seeking files that match options. First argument is the path where the search starts. The rest of the arguments specify some criteria by which to find the files, such as name, size, owner, permissions, etc. Check the UNIX manual pages for different syntax.

Example A.22
1   find . -name \*.c -print 2   find .. -type f -print 3   find . -type d -print 4   find / -size 0 - exec rm "{}" \; 5   find ~ -perm 644 -print 6   find . -type f -size +500c -atime +21 -ok rm -f "{}" \; 7   find . -name core -print 2> /dev/null (Bourne and Korn Shells)     ( find . -name core -print > /dev/tty ) >& /dev/null ( C shell) 8   find / -user ellie xdev -print 9   find ~ -atime +31 -exec mv {} /old/{} \; -print

EXPLANATION

  1. Starting at the present working directory (dot), finds all files ending in .c and prints the full pathname of the file.

  2. Starting at the parent directory (dot dot), finds all files of type file; i.e., files that are not directories.

  3. Starting at the present directory (dot), finds all directory files.

  4. Starting at the root directory, finds all files of size zero and removes them. The {} are used as a place holder for the name of each file as it is found.

  5. Starting at the user's home directory ~ (Korn and C shells), finds all files that have permissions 644 (read and write for the owner, and read permission for the group and others).

  6. Starting at the present working directory, finds files that are over 500 bytes and have not been accessed in the last 21 days and asks if it is okay to remove them.

  7. Starting at the present working directory, finds and displays all files named core and sends errors to /dev/null, the UNIX bit bucket.

  8. Prints all files on the root partition that belong to user ellie.

  9. Moves files that are older than 31 days into a directory, /old, and prints the files as it moves them.

finger displays information about local and remote users


finger [  bfhilmpqsw ] [ username... ]
finger [ l] username@hostname...
 

By default, the finger command displays information about each logged-in user, including login name, full name, terminal name (prepended with a * if write permission is denied), idle time, login time, and location if known.

fmt simple text formatters


fmt [  c ] [  s ] [  w width |  width ] [ inputfile... ]
 

fmt is a simple text formatter that fills and joins lines to produce output lines of (up to) the number of characters specified in the w width option. The default width is 72. fmt concatenates the input files listed as arguments. If none are given, fmt formats text from the standard input.

Example A.23
fmt -c -w45 letter

EXPLANATION

Formats letter. The c switch preserves the indentation of the first two lines within the paragraph and aligns the left margin of each subsequent line with that of the second line. The w switch fills the output line of up to 45 columns.

fold folds long lines


fold [  w width |  width ] [ filename ... ]
 

Fold the contents of the specified filenames, or the standard input if no files are specified, breaking the lines to have maximum width. The default for width is 80. Width should be a multiple of 8 if tabs are present, or the tabs should be expanded.

ftp file transfer program


ftp [  dgintv ] [ hostname ]
 

The ftp command is the user interface to the Internet standard File Transfer Protocol (FTP). ftp transfers files to and from a remote network site. The file transfer program is not limited to UNIX machines.

Example A.24
1   ftp ftp.uu.net 2   ftp -n 127.150.28.56

EXPLANATION

  1. ftp to the machine ftp.uu.net, a large repository run by the UUNET service that handles e-mail and net news for UNIX systems.

  2. Opens a connection to the machine at 127.45.4.1 and does not attempt to auto-login.

getopt(s) parses command line options

The getopts command supersedes getopt. getopts is used to break up options in command lines for easy parsing by shell procedures and to check for legal options.

grep searches a file for a pattern


grep [  bchilnsvw ] limited regular expression
 [ filename ... ]
 

grep searches files for a pattern and prints all lines that contain that pattern. Uses regular expressions metacharacters to match the patterns. egrep has an extended set of metacharacters.

Example A.25
1   grep Tom file1 file2 file3 2   grep -in '^tom savage' *

EXPLANATION

  1. Grep displays all lines in file1, file2, and file3 that contain the pattern Tom.

  2. Grep displays all lines with line numbers from the files in the current working directory that contain tom savage if tom savage is at the beginning of the line, ignoring case.

groups prints group membership of user


groups [ user... ]
 

The command groups prints on standard output the groups to which you or the optionally specified user belong.

id prints the username, user ID, group name and group ID


/usr/bin/id [  a ]
 

id displays your user ID, username, group ID, and group name. If your real ID and your effective ID's do not match, both are printed.

jsh the standard, job control shell


jsh [  acefhiknprstuvx ] [ argument...]
 

The command jsh is an interface to the standard Bourne shell which provides all of the functionality of the Bourne shell and enables job control.

line reads one line

line copies one line (up to a newline) from the standard input and writes it on the standard output. It returns an exit code of one on EOF and always prints at least a newline. It is often used within shell files to read from the user's terminal.

logname gets the name of the user running the process

lp sends output to a printer (AT&T)


lp [  cmsw ] [  ddest ] [  number ] [  ooption ] [  ttitle ] filename ...
cancel [ ids ] [ printers ]
 

lp, cancel sends or cancels requests to a lineprinter.

Example A.26
1   lp -n5 filea fileb 2   lp -dShakespeare filex

EXPLANATION

  1. Send five copies of filea and fileb to the printer.

  2. Specify Shakespeare as the printer where filex will be printed.

lpr sends output to a printer (UCB)


lpr [  Pprinter ] [  #copies ] [  Cclass ] [  Jjob ]
 [  Ttitle ] [  i [ indent ] ] [  1234font ] [  wcols ]
 [  r ] [  m ] [  h ] [  s ] [  filter option ]
 [ filename ... ]
 

lpr creates a printer job in a spooling area for subsequent printing as facilities become available. Each printer job consists of a control job and one or more data files.

Example A.27
1   lpr -#5 filea fileb 2   lpr -PShakespeare filex

EXPLANATION

  1. Send five copies of filea and fileb to the printer.

  2. Specify Shakespeare as the printer where filex will be printed.

lpstat print information about the status of the LP print service (AT&T)

lpq print information about the status of the printer (UCB)

ls lists contents of directory


ls [  abcCdfFgilLmnopqrRstux1 ] [ names ]
 

For each directory argument, ls lists the contents of the directory; for each file argument, ls repeats its name and any other information requested. The output is sorted alphabetically by default. When no argument is given, the current directory is listed.

Example A.28
1   ls -alF 2   ls -d a* 3   ls -i

EXPLANATION

  1. The a lists invisible files (those files beginning with a dot), the l is a long listing showing attributes of the file, the F puts a slash at the end of directory filenames, a * at the end of executable scriptnames, and an @ symbol at the end of symbolically linked files.

  2. If the argument to the d switch is a directory, only the name of the directory is displayed, not its contents.

  3. The i switch causes each filename to be preceded by its inode number.

mail mail, rmail read mail or send mail to users


Sending mail
 mail [  tw ] [  m message_type ] recipient...
 rmail [  tw ] [  m message_type ] recipient...
Reading mail
 mail [  ehpPqr ] [  f filename ]
Forwarding mail
 mail  F recipient...
Debugging
 mail [  x debug_level ] [ other_mail_options ] recipient...
 mail [  T mailsurr_file ] recipient...
 

A recipient is usually a username recognized by login. When recipients are named, mail assumes a message is being sent. It reads from the standard input up to an end-of-file (Ctrl-D), or if reading from a terminal, until it reads a line consisting of just a period. When either of those indicators is received, mail adds the letter to the mailfile for each recipient.

mailx interactive message processing system


mailx [  deHiInNUvV ] [  f [ filename|+folder ]]
 [  T filename ] [  u user ] [ recipient... ]
mailx [  dFinUv ] [  h number ] [  r address ][  s subject ] recipient...
 

The mail utilities listed above provide an interactive interface for sending, receiving, and manipulating mail messages. Basic Networking Utilities must be installed for some of the features to work. Incoming mail is stored in a file called mailbox, and after it is read, is sent to a file called mbox.

make maintains, updates, and regenerates groups of related programs and files


make [  f makefile ] ... [  d ] [  dd ] [  D ]
[  DD ] [  e ] [  i ] [  k ] [  n ] [  p ] [  P ]
[  q ] [  r ] [  s ] [  S ] [  t ] [ target ... ]
[ macro=value ... ]
 

make updates files according to commands listed in a description file, and if the target file is newer than the dependency file of the same name, make will update the target file.

mesg permits or denies messages resulting from the write command


mesg [  n ] [  y ]
 

mesg with argument n forbids messages via write by revoking nonuser write permission on the user's terminal. mesg with argument y reinstates permission. All by itself, mesg reports the current state without changing it.

mkdir creates a directory


mkdir [  p ] dirname ...
 

more browse or page through a text file


more [  cdflrsuw ] [  lines ] [ +linenumber ] [ +/pattern ]
 [ filename ... ]
page [  cdflrsuw ] [  lines ] [ +linenumber ] [ +/pattern ]
 [ filename ... ]
 

more is a filter that displays the contents of a text file on the terminal, one screenful at a time. It normally pauses after each screenful, and prints More at the bottom of the screen.

mv move or rename files


mv [  f ] [  i ] filename1 [ filename2 ...] target
 

The mv command moves a source filename to a target filename. The filename and the target may not have the same name. If target is not a directory, only one file may be specified before it; if it is a directory, more than one file may be specified. If target does not exist, mv creates a file named target. If target exists and is not a directory, its contents are overwritten. If target is a directory the file(s) are moved to that directory.

Example A.29
1   mv file1 newname 2   mv -i test1 test2 train

EXPLANATION

  1. Renames file1 to newname. If newname exists its contents are overwritten.

  2. Moves files test1 and test2 to the train directory. The i switch is for interactive mode, meaning it asks before moving the files.

nawk pattern scanning and processing language


nawk [  F re ] [  v var=value ] [ 'prog' ] [ filename ... ]
nawk [  F re ] [  v var=value ] [  f progfile ][ filename ... ]
 

nawk scans each input filename for lines that match any of a set of patterns. The command string must be enclosed in single quotes (') to protect it from the shell. Awk programs consist of a set of pattern/action statements used to filter specific information from a file, pipe, or stdin.

newgrp log in to a new group


newgrp [ ] [ group ]
 

newgrp logs a user into a new group by changing a user's real and effective group ID. The user remains logged in and the current directory is unchanged. The execution of newgrp always replaces the current shell with a new shell, even if the command terminates with an error (unknown group).

news prints news items


news [  a ] [  n ] [  s ] [ items ]
 

news is used to keep the user informed of current events. By convention, these events are described by files in the directory /var/news. When invoked without arguments, news prints the contents of all current files in /var/news, most recent first, with each preceded by an appropriate header.

nice runs a command at low priority


nice [  increment ] command [ arguments ]
 

/usr/bin/nice executes a command with a lower CPU scheduling priority. The invoking process (generally the user's shell) must be in the time-sharing scheduling class. The command is executed in the time-sharing class. An increment of 10 is the default. The increment value must be in a range between 1 and 19, unless you are the superuser. Also a csh built-in.

nohup makes commands immune to hangups and quits


/usr/bin/nohup command [ arguments ]
 

There are three distinct versions of nohup. nohup is built in to the C shell and is an executable program available in /usr/bin/nohup when using the Bourne shell. The Bourne shell version of nohup executes commands such that they are immune to HUP (hangup) and TERM (terminate) signals. If the standard output is a terminal, it is redirected to the file nohup.out. The standard error is redirected to follow the standard output. The priority is incremented by five. nohup should be invoked from the shell with & in order to prevent it from responding to interrupts or input from the next user.

Example A.30
nohup lookup &

EXPLANATION

The lookup program will run in the background and continue to run until it has completed, even if a the user logs off. Any output generated goes to a file in the current directory called nohup.out.

od octal dump


od [  bcCDdFfOoSsvXx ] [ filename ] [ [ + ] offset [ . ] [ b ] ]
 

od displays filename in one or more formats, as selected by the first argument. If the first argument is missing, o is default; e.g., the file can be displayed in bytes octal, ASCII, decimal, hex, etc.

pack pack, pcat, unpack compresses and expands files


pack [   ] [  f ] name ...
pcat name ...
unpack name ...
 

pack compresses files. Wherever possible (and useful), each input file name is replaced by a packed file name.z with the same access modes, access and modified dates, and owner as those of name. Typically, text files are reduced to 60 75% of their original size. pcat does for packed files what cat does for ordinary files, except that pcat cannot be used as a filter. The specified files are unpacked and written to the standard output. Thus, to view a packed file named name.z, use pcat name.z or just pcat name. Unpack expands files created by pack.

passwd changes the login password and password attributes


passwd [ name ]
passwd [  d |  l ] [  f ] [  n min ] [  w warn ][  x max ] name
passwd  s [  a ]
passwd  s [ name ]
 

The passwd command changes the password or lists password attributes associated with the user's login name. Additionally, privileged users may use passwd to install or change passwords and attributes associated with any login name.

paste merges same lines of several files or subsequent lines of one file


paste filename1 filename2...
paste  d list filename1 filename2...
paste  s [  d list ] filename1 filename2...
 

paste concatenates corresponding lines of the given input files filename1, filename2, etc. It treats each file as a column or columns of a table and pastes them together horizontally (see cut).

Example A.31
1   ls | paste - - - 2   paste -s -d"\t\n" testfile1 testfile2 3   paste file1 file2 

EXPLANATION

  1. Files are listed in three columns and glued together with a Tab.

  2. Combines a pair of lines into a single line using a Tab and newline as the delimiter, i.e., the first pair of lines are glued with a Tab; the next pair are glued by a newline, the next pair by a Tab, etc. The s switch causes subsequent lines from testfile1 to be pasted first and then subsequent lines from testfile2.

  3. A line from file1 is pasted to a line from file2, glued together by a Tab so that the file lines appear as two columns.

pcat (see pack)

pg displays files a page at a time


pg [  number ] [  p string ] [  cefnrs ] [ +linenumber ]
 [ +/pattern/ ] [ filename ... ]
 

The pg command is a filter that allows you to page through filenames one screenful at a time on a terminal. If no filename is specified or if it encounters the file name , pg reads from standard input. Each screenful is followed by a prompt. If the user types a Return, another page is displayed. It allows you to back up and review something that has already passed. (See more.)

pr prints files


pr [[ columns] [ wwidth] [ a]] [ eck] [ ick] [ drtfp]
   [+page] [ nck] [ ooffset] [ llength] [ sseparator]
    [   hheader] [ F] [filename ...]
pr [[ m] [ wwidth]] [ eck] [ ick] [ drtfp] [+page] [ nck]
   [ ooffset] [ llength] [ sseparator] [ hheader] [ F]
   [filename1 filename2 ...]
 

The pr command formats and prints the contents of a file according to different format options. By default, the listing is sent to stdout and is separated into pages, each headed by the page number, the date and time that the file was last modified, and the name of the file. If no options are specified, the default file format is 66 lines with a five-line header and five-line trailer.

Example A.32
pr -2dh "TITLE" file1 file2

EXPLANATION

Prints two columns double sided with header "TITLE" for file1 and file2.

ps reports process status


ps [  acdefjl ] [  g grplist ] [  p proclist ]
 [  s sidlist ] [  t term ] [  u uidlist ]
 

ps prints information about active processes. Without options, ps prints information about processes associated with the controlling terminal. The output contains only the process ID, terminal identifier, cumulative execution time, and the command name. Otherwise, the information that is displayed is controlled by the options. The ps options are not the same for AT&T and Berkeley type versions of UNIX.

Example A.33
1   ps -aux | grep '^linda'      #  ucb 2   ps -ef | grep '^ *linda'     # at&t

EXPLANATION

  1. Prints all processes running and pipes the output to the grep program, and printing only those processes owned by user linda, where linda is at the beginning of each line. (UCB version).

  2. Same as the first example, only the AT&T version.

pwd displays the present working directory name

rcp remote file copy


rcp [  p ] filename1 filename2
rcp [  pr ] filename...directory
 

The rcp command copies files between machines in the following form:


remothostname:path
user@hostname:file
user@hostname.domainname:file
 

Example A.34
1   rcp dolphin:filename /tmp/newfilename 2   rcp filename broncos:newfilename

EXPLANATION

  1. Copy filename from remote machine dolphin to /tmp/newfilename on this machine.

  2. Copy filename from this machine to remote machine broncos and name it newfilename.

rlogin remote login


rlogin [  L ] [  8 ] [  ec ] [  l username ] hostname
 

rlogin establishes a remote login session from your terminal to the remote machine named hostname. Hostnames are listed in the host's database, which may be contained in the /etc/hosts file, the Network Information Service (NIS) hosts map, the Internet domain name server, or a combination of these. Each host has one official name (the first name in the database entry), and optionally one or more nicknames. Either official hostnames or nicknames may be specified in hostname. A list of trusted hostnames can be stored in the machine's file /etc/hosts.equiv.

rm removes files from directories


rm [ f] [ i] filename...
rm  r [ f] [ i] dirname...[filename...]
 

rm removes the entries for one or more files from a directory if the file has write permission. If filename is a symbolic link, the link will be removed, but the file or directory to which it refers will not be deleted. A user does not need write permission on a symbolic link to remove it, provided they have write permissions in the directory.

Example A.35
1   rm file1 file2 2   rm -i * 3   rm -rf dir

EXPLANATION

  1. Removes file1 and file2 from the directory.

  2. Removes all files in the present working directory, but asks first if it is okay.

  3. Recursively removes all files and directories below dir and ignores error messages.

rmdir removes a directory


rmdir [ p] [ s] dirname...
 

Removes a directory if it is empty. With p, parent directories are also removed.

rsh starts a remote shell


rsh [  n ] [  l username ] hostname command
rsh hostname [  n ] [  l username ] command
 

rsh connects to the specified hostname and executes the specified command. rsh copies its standard input to the remote command, the standard output of the remote command to its standard output, and the standard error of the remote command to its standard error. Interrupt, quit, and terminate signals are propagated to the remote command; rsh normally terminates when the remote command does. If a command is not given, then rsh logs you on to the remote host using rlogin.

Example A.36
1   rsh bluebird ps -ef 2   rsh -l john owl ls; echo $PATH;cat .profile

EXPLANATION

  1. Connect to machine bluebird and display all processes running on that machine.

  2. Go to the remote machine owl as user john and execute all three commands.

ruptime shows the host status of local machines


ruptime [  alrtu ]
 

ruptime gives a status line like uptime for each machine on the local network; these are formed from packets broadcast by each host on the network once a minute. Machines for which no status report has been received for five minutes are shown as being down. Normally, the listing is sorted by host name, but this order can be changed by specifying one of ruptime's options.

rwho who is logged in on local machines


rwho [  a ]
 

The rwho command produces output similar to who, but for all machines on your network. However, it does not work through gateways and host must have the directory /var/spool/rwho as well as the rwho daemon running. If no report has been received from a machine for five minutes, rwho assumes the machine is down, and does not report users last known to be logged into that machine. If a user has not typed to the system for a minute or more, rwho reports this idle time. If a user has not typed to the system for an hour or more, the user is omitted from the output of rwho, unless the a flag is given.

script creates a typescript of a terminal session


script [  a ] [ filename ]
 

script makes a typescript of everything printed on your terminal. The typescript is written to a filename. If no filename is given, the typescript is saved in the file called typescript. The script ends when the shell exits or when Ctrl-D is typed.

Example A.37
1   script 2   script myfile

EXPLANATION

  1. Starts up a script session in a new shell. Everything displayed on the terminal is stored in a file called typescript. Must press ^d or exit to end the session.

  2. Starts up a script session in a new shell, storing everything displayed on the terminal in myfile. Must press ^d or exit to end the session.

sed streamlined editor


sed [ n] [ e script] [ f sfilename] [filename ...]
 

sed copies the named filename (standard input default) to the standard output, edited according to a script of command. Does not change the original file.

Example A.38
1   sed 's/Elizabeth/Lizzy/g' file 2   sed '/Dork/d' file 3   sed -n '15,20p' file

EXPLANATION

  1. Substitute all occurrences of Elizabeth with Lizzy in file and display on the terminal screen.

  2. Remove all lines containing Dork and print the remaining lines on the screen.

  3. Print only lines 15 through 20.

size prints section sizes in bytes of object files


size [  f ] [  F ] [  n ] [  o ] [  V ] [  x ] filename...
 

The size command produces segment or section size information in bytes for each loaded section in ELF or COFF object files. size prints out the size of the text, data, and bss (uninitialized data) segments (or sections) and their total.

sleep suspends execution for some number of seconds


sleep time
 

sleep suspends execution for time seconds. It is used to execute a command after a certain amount of time.

Example A.39
1   (sleep 105; command)& 2   (In Script)     while true     do        command        sleep 60     done

EXPLANATION

  1. After 105 seconds, command is executed. Prompt returns immediately.

  2. Enters loop; executes command and sleeps for a minute before entering the loop again.

sort sort and/or merge files


sort [  cmu ] [  ooutput ] [  T directory ] [  ykmem ]
 [  dfiMnr ] [  btx ] [ +pos1 [  pos2 ]] [ filename...]
 

The sort command sorts (ASCII) lines of all the named files together and writes the result on the standard output. Comparisons are based on one or more sort keys extracted from each line of input. By default, there is one sort key, the entire input line, and ordering is lexicographic by bytes in machine collating sequence.

Example A.40
1   sort filename 2   sort -u filename 3   sort -r filename 4   sort +1 -2 filename 5   sort -2n filename 6   sort -t: +2n -3 filename 7   sort -f filename 8   sort -b +1 filename

EXPLANATION

  1. Sorts the lines alphabetically.

  2. Sorts out duplicate entries.

  3. Sorts in reverse.

  4. Sorts starting on field 1 (fields are separated by whitespace and start at field 0), stopping at field 2 rather than sorting to the end of the line.

  5. Sorts the third field numerically.

  6. Sorts numercially starting at field 2 and stopping at field 3, with the colon designated as the field separator ( t: ).

  7. Sorts folding in upper and lowercase letters.

  8. Sorts starting at field 1, removing leading blanks.

spell finds spelling errors


spell [  blvx ] [  d hlist ] [  s hstop ] [ +local_file ] [ filename]...
 

spell collects words from the named filenames and looks them up in a spelling list. Words that neither occur among nor are derivable from (by applying certain inflections, prefixes, and/or suffixes) words in the spelling list are printed on the standard output. If no filenames are named, words are collected from the standard input.

split splits a file into pieces


split [  n ] [ filename [ name ] ]
 

split reads filename and writes it in n line pieces into a set of output files. The first output file is named with aa appended, and so on lexicographically, up to zz (a maximum of 676 files). The maximum length of name is 2 characters less than the maximum filename length allowed by the filesystem. See statvfs. If no output name is given, x is used as the default (output files will be called xaa, xab, and so forth).

Example A.41
1   split -500 filea 2   split -1000 fileb out

EXPLANATION

  1. Splits filea into 500 line files. Files are named xaa, xab, xac, etc.

  2. Splits fileb into 1000 line files named out.aa, out.ab, etc.

strings finds any printable strings in an object or binary file


strings [  a ] [  o ] [  number ] [ filename... ]
 

The strings command looks for ASCII strings in a binary file. A string is any sequence of four or more printing characters ending with a newline or a null character. strings is useful for identifying random object files and many other things.

Example A.42
strings /bin/nawk | head -2

EXPLANATION

Prints any ASCII text in the first two lines of the binary executable /bin/nawk.

stty sets the options for a terminal


stty [  a ] [  g ] [ modes ]
 

stty sets certain terminal I/O options for the device that is the current standard input; without arguments, it reports the settings of certain options.

Example A.43
1   stty erase <Press backspace key> or ^h 2   stty -echo; read secretword; stty echo 3   stty -a (AT&T) or stty -everything (BSD)

EXPLANATION

  1. Sets the backspace key to erase.

  2. Turns off echoing; waits for user input; turns echoing back on.

  3. Lists all possible options to stty.

su become superuser or another user


su [   ] [ username [ arg ... ] ]
 

su allows one to become another user without logging off. The default username is root (superuser). To use su, the appropriate password must be supplied (unless the invoker is already root). If the password is correct, su creates a new shell process that has the real and effective user ID, group IDs, and supplementary group list set to those of the specified username. The new shell will be the shell specified in the shell field of username's password file entry. If no shell is specified, sh (Bourne shell) is used. To return to normal user ID privileges, type Ctrl-D to exit the new shell. The option specifies a complete login.

sum calculates a checksum for a file

sync updates the superblock and sends changed blocks to disk

tabs set tab stops on a terminal

tail displays the tail end of a file.


tail +[ number [ lbc ] [ f ] [ filename ]
tail +[ number [ l ] [ rf ] [ filename ]
 

When a plus sign precedes the number, tail displays blocks, characters, or lines counting from the beginning of the file. If a hyphen precedes the number, tail counts from the end of the file.

Example A.44
1   tail +50 filex 2   tail -20 filex 3   tail filex

EXPLANATION

  1. Displays contents of filex starting at line 50.

  2. Displays the last 20 lines of filex.

  3. Displays the last 10 lines of filex.

talk allows you to talk to another user


talk username [ ttyname ]
 

talk is a visual communications program that copies lines from your terminal to that of another user.

Example A.45
talk joe@cowboys

EXPLANATION

Opens a request to talk to user joe on a machine called cowboys.

tar stores and retrieves files from an archive file, normally a tape device


tar [   ] c|r|t|u|x [ bBefFhilmopvwX0134778 ] [ tarfile ]
[ blocksize ] [ exclude file ] [  I include file ]
filename1 filename2    C directory filenameN 
 

Example A.46
1   tar cvf /dev/diskette 2   tar tvf /dev/fd0 3   tar xvf /dev/fd0

EXPLANATION

  1. Sends all files under the present working directory to tape at device /dev/diskette, and prints the files that are being sent.

  2. Displays the table of contents of what is on tape device /dev/fd0.

  3. Extracts all files from tape and prints which files were extracted.

tee replicates the standard output


tee [  ai ] [ filename ]
 

tee copies the standard input to the standard output and one or more files, as in ls|tee outfile. Output goes to screen and to outfile.

Example A.47
date | tee nowfile

EXPLANATION

The output of the date command is displayed on the screen and also stored in nowfile.

telnet communicates with a remote host

Example A.48
telnet necom.com

EXPLANATION

Opens a session with the remote host necom.com

test evaluates an expression

test evaluates an expression and returns an exit status indicating that the expression is either true (zero) or false (not zero). Used primarily by Bourne and Korn shell for string, numeric, and file testing. The C shell has most of the tests built-in.

Example A.49
1   test 5 gt 6 2   echo $? ( Bourne and Korn Shells)     (Output is 1, meaning the result of the test is not true.)

EXPLANATION

  1. The test command performs an integer test to see if 5 is greater than 6.

  2. The $? variable contains the exit status of the last command. If a nonzero status is reported, the test results are not true; if the return status is zero, the the test result is true.

time displays a summary of time used by this shell and its children

timex times a command; reports process data and system activity


timex [  o ] [  p [  fhkmrt ] ] [  s ] command
 

The given command is executed; the elapsed time, user time, and system time spent in execution are reported in seconds. Optionally, process accounting data for the command and all its children can be listed or summarized, and total system activity during the execution interval can be reported. The output of timex is written on standard error.

touch updates access time and/or modification time of a file


touch [  amc ] [ mmddhhmm [ yy ] ] filename...
 

touch causes the access and modification times of each argument to be updated. The filename is created if it does not exist. If no time is specified the current time is used.

Example A.50
touch a b c

EXPLANATION

Three files, a, b, and c are created. If any of them already exist, the modification time-stamp on the files is updated.

tput initializes a terminal or queries the terminfo database


tput [  Ttype ] capname [ parms...]
tput [  Ttype ] init
tput [  Ttype ] reset
tput [  Ttype ] longname
tput  S <<
 

tput uses the terminfo database to make the values of terminal-dependent capabilities and information available to the shell (see sh), to initialize or reset the terminal, or return the long name of the requested terminal type.

Example A.51
1   tput longname 2   bold='tput smso'     unbold='tput rmso'     echo "${bold}Enter your id: ${offbold}\c"

EXPLANATION

  1. Displays a long name for the terminal from the terminfo database.

  2. Sets the shell variable bold to turn on the highlighting of displayed text. Then sets the shell variable unbold to return to normal text display. The line Enter your id: is highlighted in black with white letters. Further text is displayed normally.

tr translates characters


tr [  cds ] [ string1 [ string2 ] ]
 

tr copies the standard input to the standard output with substitution or deletion of selected characters. Input characters found in string1 are mapped into the corresponding characters of string2. The forward slash can be used with an octal digit to represent the ASCII code. When string2 (with any repetitions of characters) contains fewer characters than string1, characters in string1 with no corresponding character in string2 are not translated. Octal values for characters may be used when preceded with a backslash:


\11   Tab
\12   Newline
\042  Single quote
\047  Double quote
 

Example A.52
1   tr 'A' 'B' < filex 2   tr '[A-Z]' [a-z]' < filex 3   tr -d ' ' < filex 4   tr -s '\11' '\11' < filex 5   tr -s ':' ' ' < filex 6   tr '\047' '\042'

EXPLANATION

  1. Translates As to Bs in filex.

  2. Translates all uppercase letters to lowercase letters.

  3. Deletes all spaces from filex.

  4. Replaces (squeezes) multiple tabs with single tabs in filex.

  5. Squeezes multiple colons into single spaces in filex.

  6. Translates double quotes to single quotes in text coming from standard input.

true provide successful exit status

true does nothing, successfully, meaning that it always returns a zero exit status, indicating success. Used in Bourne and Korn shell programs as a command to start an infinite loop.


while true
do
 command
done
 

tsort topological sort


/usr/ccs/bin/tsort [filename]
 

The tsort command produces, on the standard output, an ordered list of items consistent with a partial ordering of items mentioned in the input filename. If no filename is specified, the standard input is understood. The input consists of pairs of items (nonempty strings) separated by blanks. Pairs of different items indicate ordering. Pairs of identical items indicate presence, but not ordering.
 

tty gets the name of the terminal


tty [  l ] [  s ]
 

tty prints the path name of the user's terminal.

umask sets file-creation mode mask for permissions


umask [ ooo ]
 

The user file-creation mode mask is set to 000. The three octal digits refer to read/write/execute permissions for owner, group, and other, respectively. The value of each specified digit is subtracted from the corresponding ''digit'' specified by the system for the creation of a file. For example, umask 022 removes write permission for group and other (files normally created with mode 777 become mode 755; files created with mode 666 become mode 644). If 000 is omitted, the current value of the mask is printed. umask is recognized and executed by the shell.

Example A.53
1   umask 2   umask 027

EXPLANATION

  1. Displays the current file permission mask.

  2. The directory permissions, 777, minus the umask 027 is 750. The file permissions, 666, minus the umask 027 is 640. When created, directories and files will be assigned the permissions created by umask.

uname prints name of current machine


uname [  amnprsv ]
uname [  S system_name ]
 

uname prints information about the current system on the standard output. If no options are specified, uname prints the current operating system's name. The options print selected information returned by uname and/or sysinfo.

Example A.54
1   uname -n 2   uname -a

EXPLANATION

  1. Prints the name of the host machine.

  2. Prints the machine hardware name, network nodename, operating system release number, the operating system name, and the operating system version same as m, n, r, s, and v.

uncompress restores files to their original state after they have been compressed using the compress command


uncompress [  cFv ] [ file . . . ]
 

Example A.55
uncompress file.Z

EXPLANATION

Restore file.Z back to its original state; i.e., what it was before being compressed.

uniq reports on duplicate lines in a file


uniq [ [  u ] [  d ] [  c ] [ +n ] [  n ] ] [ input [ output ] ]
 

uniq reads the input file, comparing adjacent lines. In the normal case, the second and succeeding copies of repeated lines are removed; the remainder is written on the output file. Input and output should always be different.

Example A.56
1   uniq file1 file2 2   uniq -d -2 file3

EXPLANATION

  1. Removes duplicate adjacent lines from file1 and puts output in file2.

  2. Displays the duplicate lines where the duplicate starts at third field.

units converts quantities expressed in standard scales to other scales

units converts quantities expressed in various standard scales to their equivalents in other scales. It works interactively in this fashion:


You have: inch
You want: cm
 * 2.540000e+00
 / 3.937008e 01
 

unpack expands files created by pack

unpack expands files created by pack. For each filename specified in the command, a search is made for a file called name.z (or just name, if name ends in .z). If this file appears to be a packed file, it is replaced by its expanded version. The new file has the .z suffix stripped from its name, and has the same access modes, access and modification dates, and owner as those of the packed file.

uucp copy files to another system, UNIX-to-UNIX system copy


uucp [  c |  C ] [  d |  f ] [  ggrade ] [  j ] [  m ] [  nuser ] [  r ] [  sfile ] [ 
xdebug_level ]
 source file destination file
 

uucp copies files named by the source-file arguments to the destination-file argument.

uuencode uuencode, uudecode encode a binary file into ASCII text in order to send it through e-mail, or convert it back into its original form


uuencode [ source file ] file label
uudecode [ encoded file ]
 

uuencode converts a binary file into an ASCII-encoded representation that can be sent using mail. The label argument specifies the output filename to use when decoding. If no file is given, stdin is encoded. uudecode reads an encoded file, strips off any leading and trailing lines added by mailer programs, and recreates the original binary data with the filename and the mode and owner specified in the header. The encoded file is an ordinary ASCII text file; it can be edited by any text editor. But it is best only to change the mode or file-label in the header to avoid corrupting the decoded binary.

Example A.57
1   uuencode mybinfile decodedname > uumybinfile.tosend 2   uudecode uumybinfile.tosend

EXPLANATION

  1. The first argument, mybinfile, is the existing file to be encoded. The second argument is the name to be used for the uudecoded file, after mailing the file, and uumybinfile.tosend is the file that is sent through the mail.

  2. This decodes the uuencoded file and creates a filename as given as the second argument to uuencode.

wc counts lines, words, and characters


wc [  lwc ] [ filename ... ]
 

wc counts lines, words, and characters in a file or in the standard input if no filename is given. A word is a string of characters delimited by a space, tab, or newline.

Example A.58
1   wc filex 2   who | wc -l 3   wc -l filex

EXPLANATION

  1. Prints the number of lines, words, and characters in filex.

  2. The output of the who command is piped to wc, displaying the number of lines counted.

  3. Prints the number of lines in filex.

what extracts SCCS version information from a file by printing information found after the @(#) pattern


what [  s] filename
 

what searches each filename for the occurrence of the pattern @(#), which the SCCS get command substitutes for the %Z% keyword, and prints what follows up to a " >, newline, \, or null character.

which locates a command and displays its pathname or alias (UCB)


which [ filename ]
 

which takes a list of names and looks for the files that would be executed had the names been given as commands. Each argument is expanded if it is aliased, and searched for along the user's path. Both aliases and path are taken from the user's .cshrc file. Only .cshrc file is used.

whereis locates the binary, source, and manual page files for a command (UCB)


whereis [  bmsu ] [  BMS directory ...  f ] filename
 

who displays who is logged on the system

write writes a message to another user


write username [ ttyname ]
 

write copies lines from your terminal to another user's terminal.

xargs constructs an argument list(s) and executes a command


xargs [ flags ] [ command [ initial arguments ] ]
 

xargs allows you to transfer contents of files into a command line and dynamically build command lines.

Example A.59
1   ls $1 | xargs -i -t mv $1/{} $2/{} 2   ls | xargs -p -l rm -rf

EXPLANATION

  1. Moves all files from directory $1 to directory $2, and echos each mv command just before executing.

  2. Prompts (-p) the user which files are to be removed one at a time and removes each one.

zcat uncompress a compressed file to standard output. Same as uncompress c


zcat [ file . . . ]
 

Example A.60
zcat book.doc.Z | more

EXPLANATION

Uncompresses book.doc.Z and pipes the output to more.

 

CONTENTS


UNIX Shells by Example
UNIX Shells by Example, 3rd Edition
ISBN: 013066538X
EAN: 2147483647
Year: 2001
Pages: 18
Authors: Ellie Quigley

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net