Commands

Commands

> Send standard output to somewhere other than the monitor.

Example: To save the output of a directory listing to the file "myhome.base", use

ls -l > myhome.base

< Read standard input from somewhere other than the keyboard.

Example: To get a list of expressions to evaluate from the file "myexpr.ksh", use

test < myexpr.ksh

2> Redirect standard error as specified. The 2 in this command comes from the UNIX tradition that standard input has a file number 0, standard output 1, and standard error 2.

Example: To send standard error messages to the file error, use

cc -o interest interest.c 2> error

>> Append standard output to the specified file without overwriting the existing contents.

Example: To append Mail directory information to the file "myhome.base", use

dirname $MAIL |xargs ls -l >> myhome.base

| The pipe character is used to link the standard output of one program to the standard input of another program.

Example: To look through all the subdirectories of your current directory for a file named "important.c", use

find . -type f -print | grep "important.c"

In this example, the standard output from the find command (a list of file names) is piped to the standard input of the grep command, which searches for a text string.

tee

[OPTION] [FILE]

Copy standard input to standard output and to any file(s) given as arguments. Useful for saving a copy of stuff being written to the screen. So named because it's like the T joint in plumbing.

Example: To grep through the output of a lengthy find and also save a copy of the find results for possible later perusal:

find / -type f -print | tee find.results | grep "important.file"

-a, --append

Append any output to the specified files rather than overwriting.

-i,--ignore-interrupt

Ignore any interrupts sent.

script

[-a] [file]

Record what is happening on the terminal and save it into a file. By default, the file is "typescript" in your current working directory, but you can specify any one you like. Exit with CTRL-D.

Example: To record the output of multiple commands in the file "home"

script homework.220

<Type a bunch of commands>

<Press Ctrl-C>

-a

Append any subsequent information to the existing script file do not overwrite.

xargs

[-0prtx] [-e[eof-str]] [-i[replace-str]] [-l[maxlines]] [-n max-args] [-s max-chars][-P max-procs] [--null] [--eof[=eof-str]] [--replace[=replace-str]] [--max-lines[=max-lines]] [--interactive] [--maxchars=max-chars] [--verbose] [--exit] [--max-procs=maxprocs] [--max-args=max-args] [--no-run-if-empty] [-version] [--help] [command [initial-arguments]]

Read arguments from standard input, construct a command line using those arguments and arguments provided on its own command line, and execute the constructed commands.

Example: Suppose you have some time on your hands and you want to grep through every file in the /usr/local filesystem for the string "datum". First, generate a list of the files using the find command; then pipe the results of that find to grep via the xargs command. (If you don't use xargs, grep will look only at the names of the files for the string "datum", and not look in the files themselves.) In other words, use

find /usr/local -type f -print | xargs grep "datum"

--null, -0

Input files are terminated by Null rather than the end-of-file character.

--eof[=eof-str],-e[eof-str]

Treat the specified string as the end-of-file marker.

--help

Display a listing of the possible arguments to xargs.

--replace[=replace-str],-i[replace-str]

Replace occurrences of replace-str in the initial arguments with names read from standard input.

--max-lines[=max-lines],-l[max-lines]

Limit commands to at most max-lines nonblank lines per command (default 1).

--max-args=max-args,-nmax-args

Limit commands to at most max-args.

--interactive, -p

Prompt the user before executing a generated command line.

--no-run-if-empty, -r

If the generated command line is empty, don't run it.

--msax-chars=max-chars,-smax-chars

Specify a maximum length for a command line.

--verbose, -t

Before executing the command, display it to standard output.

--version

Output the version number and exit.

--exit, -x

Exit if the size specified by -s is exceeded.

--max-procs=max-procs,-Pmax-procs

Specify an upper limit of processes to be simultaneously executed.

 



Linux Desk Reference
Linux Desk Reference (2nd Edition)
ISBN: 0130619892
EAN: 2147483647
Year: 2000
Pages: 174
Authors: Scott Hawkins

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