0 Some Cool Commands.

alias

Create an alias, aliases allow a string to be substituted for a word when it is used as the first word of a simple command.

SYNTAX
alias [-p] [name[=value] ...]

unalias [-a] [name ... ]
If arguments are supplied, an alias is defined for each name whose value is given.

If no value is given, `alias' will print the current value of the alias.

Without arguments or with the `-p' option, alias prints the list of aliases on the standard output in a form that allows them to be reused as input.

`unalias' will remove each name from the list of aliases. If `-a' is supplied, all aliases are removed.

`alias' and `unalias' are BASH built-ins.

The first word of each simple command, if unquoted, is checked to see if it has an alias. If so, that word is replaced by the text of the alias. The alias name and the replacement text may contain any valid shell input, including shell metacharacters, with the exception that the alias name may not contain `='.

The first word of the replacement text is tested for aliases, but a word that is identical to an alias being expanded is not expanded a second time. This means that one may alias ls to "ls -F", for instance, and Bash does not try to recursively expand the replacement text.

If the last character of the alias value is a space or tab character, then the next command word following the alias is also checked for alias expansion.

There is no mechanism for using arguments in the replacement text, as in csh. If arguments are needed, a shell function should be used . Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt .

The rules concerning the definition and use of aliases are somewhat confusing. Bash always reads at least one complete line of input before executing any of the commands on that line. Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition appearing on the same line as another command does not take effect until the next line of input is read. The commands following the alias definition on that line are not affected by the new alias. This behavior is also an issue when functions are executed. Aliases are expanded when a function definition is read, not when the function is executed, because a function definition is itself a compound command. As a consequence, aliases defined in a function are not available until after that function is executed. To be safe, always put alias definitions on a separate line, and do not use alias in compound commands.

For almost every purpose, shell functions are preferred over aliases.

Examples

alias ls='ls -F'

Now issuing the command 'ls' will actually run 'ls -F'

Making an alias permanent:
Use your favorite text editor to create a .bash_aliases file, and type the alias commands into the file.
.bash_aliases will run at login (or you can just execute it with ..bash_aliases )
___________________________________________________________________

break

Exit from a for, while, until, or select loop

SYNTAX
break [n]
If n is supplied, the nth enclosing loop is exited. n must be greater than or equal to 1.

The return status is zero unless n is not greater than or equal to 1.

Example

for myloop in 1 2 3 4 5
do
echo -n "$myloop"
if [ "$myloop" -eq 3 ]
then
break # This line will break out of the loop
fi
done
break is a POSIX `special' builtin
____________________________________________________________

builtin

Run a shell builtin, passing it args, and return its exit status.

SYNTAX
builtin [shell-builtin [args]]
This is useful when defining a shell function with the same name as a shell builtin, retaining the functionality of the builtin within the function.


For example, to write a function to replace `cd' that writes the hostname and current directory
to an xterm title bar:
cd()

{

builtin cd "$@" && xtitle "$HOST: $PWD"

}
The return status is non-zero if shell-builtin is not a shell builtin command.
____________________________________________________________
cal

Display a calendar

SYNTAX
cal [-mjy] [[month] year]

options:

-m Display monday as the first day of the week.

-j Display julian dates (days one-based, numbered from January 1).

-y Display a calendar for the current year.

A single parameter specifies the 4 digit year (1 - 9999) to be displayed.

Two parameters denote the Month (1 - 12) and Year (1 - 9999).

If arguments are not specified, the current month is displayed.

A year starts on 01 Jan.
____________________________________________________________
case

Conditionally perform a command, case will selectively execute the command-list corresponding to the first pattern that matches word.


SYNTAX
case word in [ [(] pattern [| pattern]...) command-list ;;]... esac
The `|' is used to separate multiple patterns, and the `)' operator terminates a pattern list. A list of patterns and an associated command-list is known as a clause. Each clause must be terminated with `;;'.

The word undergoes tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal before matching is attempted. Each pattern undergoes tilde expansion, parameter expansion, command substitution, and arithmetic expansion. There may be an arbitrary number of case clauses, each terminated by a `;;'. The first pattern that matches determines the command-list that is executed.

Here is an example using case in a script that could be used to describe one interesting feature of an animal:
echo -n "Enter the name of an animal: "
read ANIMAL
echo -n "The $ANIMAL has "
case $ANIMAL in
horse | dog | cat) echo -n "four";;
man | kangaroo ) echo -n "two";;
*) echo -n "an unknown number of";;
esac
echo " legs."
The return status is zero if no pattern is matched. Otherwise, the return status is the exit status of the command-list executed.
____________________________________________________________
chroot

Run a command with a different root directory
'chroot' runs a command with a specified root directory. On many systems, only the super-user can do this.


SYNTAX
chroot NEWROOT [COMMAND [ARGS]...]

chroot OPTION
Ordinarily, filenames are looked up starting at the root of the directory structure, i.e. '/'

'chroot' changes the root to the directory NEWROOT (which must exist) and then runs COMMAND with optional ARGS.

If COMMAND is not specified, the default is the value of the `SHELL' environment variable or `/bin/sh' if not set, invoked with the `-i' option.

The only options are `--help' and `--version'
____________________________________________________________
cksum

Print CRC checksum and byte counts

Computes a cyclic redundancy check (CRC) checksum for each given FILE, or standard input if none are given or for a FILE of `-'.


SYNTAX
cksum [Option]... [File]...

cksum prints the CRC checksum for each file along with the number of bytes in the file, and the filename unless no arguments were given.

cksum is typically used to ensure that files transferred by unreliable means (e.g., netnews) have not been corrupted, by comparing the cksum output for the received files with the cksum output for the original files (typically given in the distribution).

The CRC algorithm is specified by the POSIX.2 standard. It is not compatible with the BSD or System V sum algorithms; it is more robust.

The only options are `--help' and `--version'.

____________________________________________________________
cmp

Compare two files, and if they differ, tells the first byte and line number where they differ.

You can use the `cmp' command to show the offsets and line numbers where two files differ. `cmp' can also show all the characters that differ between the two files, side by side.


SYNTAX
cmp options... FromFile [ToFile]

OPTIONS
Multiple single letter options (unless they take an argument) can be combined into a single command line word:
so `-cl' is equivalent to `-c -l'.

`-c'
Print the differing characters. Display control characters as a `^' followed by a letter of the alphabet and precede characters that have the high bit set with `M-' (which stands for "meta").

`--ignore-initial=BYTES'
Ignore any differences in the the first BYTES bytes of the input files. Treat files with fewer than BYTES bytes as if they are empty.

`-l'
Print the (decimal) offsets and (octal) values of all differing bytes.

`--print-chars'
Print the differing characters. Display control characters as a `^' followed by a letter of the alphabet and precede characters that have the high bit set with `M-' (which stands for "meta").

`--quiet'
`-s'
`--silent'
Do not print anything; only return an exit status indicating whether the files differ.

`--verbose'
Print the (decimal) offsets and (octal) values of all differing bytes.

`-v'
`--version'
Output the version number of `cmp'.

The file name `-' is always the standard input. `cmp' also uses the standard input if one file name is omitted.

An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble.

Example

$ cmp tnsnames.ora tnsnames.old

Notes
`cmp' reports the differences between two files character by character, instead of line by line. As a result, it is more useful than `diff' for comparing binary files. For text files, `cmp' is useful mainly when you want to know only whether two files are identical.

For files that are identical, `cmp' produces no output. When the files differ, by default, `cmp' outputs the byte offset and line number where the first difference occurs. You can use the `-s' option to suppress that information, so that `cmp' produces no output and reports whether the files differ using only its exit status.
Unlike `diff', `cmp' cannot compare directories; it can only compare two files.

____________________________________________________________
dc

Desk calculator

SYNTAX
dc

OPTIONS

-e EXPR --expression=EXPR Evaluate EXPR as DC commands.

-f FILE --file=FILE Read and evaluate DC commands from FILE.

-h --help Print a usage message summarizing the command-line options, then
exit.

-V --version Print the version information for this program, then exit.

To exit, use `q'.
DESCRIPTION
The desk calculator works with postfix notation; rather like many HP Calculators.
Basic arithmetic uses the standard + - / * symbols but entered after the digits

so entering:

100
0.5
*
p

will return 50
____________________________________________________________
dd

Dump Data - convert and copy a file (use for RAW storage)

SYNTAX
dd [OPTION]...

DESCRIPTION
The numeric-valued options below (BYTES and BLOCKS) can be followed by a multiplier: `b'=512, `c'=1, `w'=2, `xM'=M, or any of the standard block size suffixes like `k'=1024 (*note Block size::).

`if=FILE'
input file : Read from FILE instead of standard input.

`of=FILE'
output file : Write to FILE instead of standard output. Unless `conv=notrunc' is given, `dd' truncates FILE to zero bytes (or the size specified with `seek=').

`ibs=BYTES'
Read BYTES bytes at a time.

`obs=BYTES'
Write BYTES bytes at a time.

`bs=BYTES'
Both read and write BYTES bytes at a time. This overrides `ibs' and `obs'.

`cbs=BYTES'
Convert BYTES bytes at a time.

`skip=BLOCKS'
Skip BLOCKS `ibs'-byte blocks in the input file before copying.

`seek=BLOCKS'
Skip BLOCKS `obs'-byte blocks in the output file before copying.

`count=BLOCKS'
Copy BLOCKS `ibs'-byte blocks from the input file, instead of everything until the end of the file.

`conv=CONVERSION[,CONVERSION]...'
Convert the file as specified by the CONVERSION argument(s). (No spaces around any comma(s).)

Conversions:

`ascii'
Convert EBCDIC to ASCII.

`ebcdic'
Convert ASCII to EBCDIC.

`ibm'
Convert ASCII to alternate EBCDIC.

`block'
For each line in the input, output `cbs' bytes, replacing the input newline with a space and padding with spaces as necessary.

`unblock'
Replace trailing spaces in each `cbs'-sized input block with a newline.

`lcase'
Change uppercase letters to lowercase.

`ucase'
Change lowercase letters to uppercase.

`swab'
Swap every pair of input bytes. GNU `dd', unlike others, works when an odd number of bytes are read--the last byte is simply copied (since there is nothing to swap it with).

`noerror'
Continue after read errors.

`notrunc'
Do not truncate the output file.

`sync'
Pad every input block to size of `ibs' with trailing zero
bytes.
____________________________________________________________
diff

Display the differences between two files, or each corresponding file in two directories.
Each set of differences is called a "diff" or "patch". For files that are identical, `diff' normally produces no output; for binary (non-text) files, `diff' normally reports only that they are different.

SYNTAX
diff [options] from-file to-file
OPTIONS
Multiple single letter options (unless they take an argument) can be combined into a single command line word: so `-ac' is equivalent to `-a -c'.

-lines Show lines lines of context. This option is obsolete.

-a Treat all files as text and compare them line-by-
line, even if they do not seem to be text.

-b Ignore changes in amount of white space.

-B Ignore changes that just insert or delete blank
lines.

--brief
Report only whether the files differ, not the
details of the differences.

-c Use the context output format.

-C lines --context[=lines]
Use the context output format, showing lines (an integer) lines of context, or three if lines is not given. For proper operation, patch typically needs at least two lines of context.

--changed-group-format=format
Use format to output a line group containing differing lines from both files in if-then-else foRmat.

-d Change the algorithm to perhaps find a smaller set of changes. This makes diff slower (sometimes much slower).

-D name Make merged if-then-else format output, conditional on the preprocessor macro name.

-e
--ed Make output that is a valid ed script.

--exclude=pattern
When comparing directories, ignore files and subdirectories whose basenames match pattern.

--exclude-from=file
When comparing directories, ignore files and subdirectories whose basenames match any pattern contained in file.

--expand-tabs
Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files.

-f Make output that looks vaguely like an ed script but has changes in the order they appear in the file.

-F regexp
In context and unified format, for each hunk of differences, show some of the last preceding line that matches regexp.

--forward-ed
Make output that looks vaguely like an ed script but has changes in the order they appear in the file.

-h This option currently has no effect; it is present for Unix compatibility.

-H Use heuristics to speed handling of large files that have numerous scattered small changes.

--horizon-lines=lines
Do not discard the last lines lines of the common prefix and the first lines lines of the common suffix.

-i Ignore changes in case; consider upper- and lower-case letters equivalent.

-I regexp Ignore changes that just insert or delete lines that match regexp.

--ifdef=name
Make merged if-then-else format output, conditional
on the preprocessor macro name.

--ignore-all-space
Ignore white space when comparing lines.

--ignore-blank-lines
Ignore changes that just insert or delete blank lines.

--ignore-case
Ignore changes in case; consider upper- and lower-case to be the same.

--ignore-matching-lines=regexp
Ignore changes that just insert or delete lines that match regexp.

--ignore-space-change
Ignore changes in amount of white space.

--initial-tab
Output a tab rather than a space before the text of a line in normal or context format. This causes the alignment of tabs in the line to look normal.

-l Pass the output through pr to paginate it.

-L label
--label=label
Use label instead of the file name in the context format and unified format headers.

--left-column
Print only the left column of two common lines in side by side format.

--line-format=format
Use format to output all input lines in in-then-else format.

--minimal
Change the algorithm to perhaps find a smaller set of changes. This makes diff slower (sometimes much slower).

-n Output RCS-format diffs; like -f except that each command specifies the number of lines affected.

-N
--new-file
In directory comparison, if a file is found in only one directory, treat it as present but empty in the other directory.

--new-group-format=format
Use format to output a group of lines taken from just the second file in if-then-else format.

--new-line-format=format
Use format to output a line taken from just the second file in if-then-else format.

--old-group-format=format
Use format to output a group of lines taken from just the first file in if-then-else format.

--old-line-format=format
Use format to output a line taken from just the first file in if-then-else format.

-p Show which C function each change is in.

-P When comparing directories, if a file appears only in the second directory of the two, treat it as present but empty in the other.

--paginate
Pass the output through pr to paginate it.

-q Report only whether the files differ, not the details of the differences.

-r When comparing directories, recursively compare any subdirectories found.

--rcs Output RCS-format diffs; like -f except that each command specifies the number of lines affected.

--recursive
When comparing directories, recursively compare any subdirectories found.

--report-identical-files
-s Report when two files are the same.

-S file
When comparing directories, start with the file file. This is used for resuming an aborted comparison.

--sdiff-merge-assist
Print extra information to help sdiff. sdiff uses this option when it runs diff. This option is not intended for users to use directly.

--show-c-function
Show which C function each change is in.

--show-function-line=regexp
In context and unified format, for each hunk of differences, show some of the last preceding line that matches regexp.

--side-by-side
Use the side by side output format.

--speed-large-files
Use heuristics to speed handling of large files that have numerous scattered small changes.

--starting-file=file
When comparing directories, start with the file file. This is used for resuming an aborted comparison.

--suppress-common-lines
Do not print common lines in side by side format.

-t Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files.

-T Output a tab rather than a space before the text of a line in normal or context format. This causes the alignment of tabs in the line to look normal.

--text Treat all files as text and compare them line-by-line, even if they do not appear to be text.

-u Use the unified output format.

--unchanged-group-format=format
Use format to output a group of common lines taken from both files in if-then-else format.

--unchanged-line-format=format
Use format to output a line common to both files in if-then-else format.

--unidirectional-new-file
When comparing directories, if a file appears only in the second directory of the two, treat it as present but empty in the other.

-U lines
--unified[=lines]
Use the unified output format, showing lines (an integer) lines of context, or three if lines is not given. For proper operation, patch typically needs at least two lines of context.

-v
--version
Output the version number of diff.

-w Ignore white space when comparing lines.

-W columns
--width=columns
Use an output width of columns in side by side format.

-x pattern
When comparing directories, ignore files and subdirectories whose basenames match pattern.

-X file
When comparing directories, ignore files and subdirectories whose basenames match any pattern contained in file.

-y Use the side by side output format.
In the simplest case, diff compares the contents of the two files from-file and to-file. A file name of - stands for text read from the standard input.

If from-file is a directory and to-file is not, diff compares the file in from-file whose file name is that of to-file, and vice versa. The non-directory file must not be -.

If both from-file and to-file are directories, diff compares corresponding files in both directories, in alphabetical order; this comparison is not recursive unless the -r or --recursive option is given.

GNU `diff' can show whether files are different without detailing the differences.
It also provides ways to suppress certain kinds of differences that are not important to you.

Most commonly, such differences are changes in the amount of white space between words or lines. `diff' also provides ways to suppress differences in alphabetic case or in lines that match a regular expression that you provide.

These options can accumulate; for example, you can ignore changes in both white space and alphabetic case.

End -of-Line markers
In operating systems that distinguish between text and binary files, `diff' normally reads and writes all data as text.

Use the `--binary' option to force `diff' to read and write binary data instead. This option has no effect on a Posix-compliant system like GNU or traditional Unix. However, many personal computer operating systems represent the end of a line with a carriage return followed by a newline.

On such systems, `diff' normally ignores these carriage returns on input and generates them at the end of each output line, but with the `--binary' option `diff' treats each carriage return as just another input character, and does not generate a carriage return at the end of each output line.

This can be useful when dealing with non-text files that are meant to be interchanged with Posix-compliant systems.

Suppressing Differences in Blank and Tab Spacing
The `-b' and `--ignore-space-change' options ignore white space at line end, and considers all other sequences of one or more white space characters to be equivalent.
With these options, `diff' considers the following two lines to be equivalent, where `$' denotes the line end:

Here lyeth muche rychnesse in lytell space. -- John Heywood$
Here lyeth muche rychnesse in lytell space. -- John Heywood $

The `-w' and `--ignore-all-space' options are stronger than `-b'. They ignore difference even if one file has white space where the other file has none. "White space" characters include tab, newline, vertical tab, form feed, carriage return, and space; some locales may define additional characters to be white space.
With these options, `diff' considers the following two lines to be equivalent, where `$' denotes the line end and `^M' denotes a carriage return:

Here lyeth muche rychnesse in lytell space.-- John Heywood$
He relyeth much erychnes seinly tells pace. --John Heywood

GNU `diff' can treat lowercase letters as equivalent to their uppercase counterparts, so that, for example, it considers `Funky Stuff', `funky STUFF', and `fUNKy stuFf' to all be the same.
To request this, use the `-i' or `--ignore-case' option.

Suppressing Lines Matching a Regular Expression
To ignore insertions and deletions of lines that match a regular expression, use the `-I REGEXP' or `--ignore-matching-lines=REGEXP' option.
You should escape regular expressions that contain shell metacharacters to prevent the shell from expanding them.

For example, `diff -I '^[0-9]'' ignores all changes to lines beginning with a digit.

However, `-I' only ignores the insertion or deletion of lines that contain the regular expression if every changed line in the hunk--every insertion and every deletion--matches the regular expression.

In other words, for each nonignorable change, `diff' prints the complete set of changes in its vicinity, including the ignorable ones. You can specify more than one regular expression for lines to ignore by using more than one `-I' option. `diff' tries to match each line against each regular expression, starting with the last one given.

Summarizing Which Files Differ
When you only want to find out whether files are different, and you don't care what the differences are, you can use the summary output format.
In this format, instead of showing the differences between the files, `diff' simply reports whether files differ.
The `-q' and `--brief' options select this output format.
This format is especially useful when comparing the contents of two directories. It is also much faster than doing the normal line by line comparisons, because `diff' can stop analyzing the files as soon as it knows that there are any differences.
You can also get a brief indication of whether two files differ by using `cmp'.

Using diff to patch a file
To show context around the differing lines GNU `diff' provides these output formats

Normal Format: An output format that shows each hunk of differences without any surrounding context
Context Format:: An output format that shows surrounding lines.
Unified Format:: A more compact output format that shows context.

`patch' can apply diffs by searching in the files for the lines of context around the differing lines; if those lines are actually a few lines away from where the diff says they are, `patch' can adjust the line numbers accordingly and still apply the diff correctly.

For more on patching files and producing commands that direct the `ed' text editor to edit a file - see `info diff'

____________________________________________________________
crontab (cron table)

Schedule a command to run at a later time

SYNTAX
crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }

Key
-l List - display the current crontab entries.

-r Remove the current crontab.

-e Edit the current crontab using the editor specified by the
VISUAL or EDITOR environment variables.
After you exit from the editor, the modified crontab will be installed automatically.

Crontab is the program used to install, deinstall or list the tables used to drive the cron daemon in Vixie Cron.
Each user can have their own crontab, and though these are files in /var, they are not intended to be edited directly.

If the -u option is given, it specifies the name of the user whose crontab is to be tweaked. If this option is not given, crontab examines "your" crontab, i.e., the crontab of the person executing the command. Note that su can confuse crontab and that if you are running inside of su you should always use the -u option for safety's sake.

cron file is used to install a new crontab from some named file or standard input if the pseudo-filename `-' is given.

Each line in the cron table follows the following format: 7 fields left to right

Field Meaning
1 Minute (0-59)
2 Hour (2-24)
3 Day of month (1-31)
4 Month (1-12, Jan, Feb, ...)
5 Day of week (0-6) 0=Sunday, 1=Monday ...
or Sun, Mon, Tue, Wed, Thur, Fri
6 User that the command will run as
7 Command to execute

There are several ways of specifying multiple values in a field:

• The comma (',') operator specifies a list of values, for example: "1,3,4,7,8"
• The dash ('-') operator specifies a range of values, for example: "1-6", which is equivalent to "1,2,3,4,5,6"
• The asterisk ('*') operator specifies all possible values for a field. e.g. every hour or every day.

There is also an operator which some extended versions of cron support, the slash ('/') operator, which can be used to skip a given number of values. For example, "*/3" in the hour time field is equivalent to "0,3,6,9,12,15,18,21"; "*" specifies 'every hour' but the "/3" means that only the first, fourth, seventh...and such values given by "*" are used.

Cron will email to the user all output of the commands it runs, to silence this, redirect the output to a log file or to /dev/null

Example

Run /usr/bin/somecommand at 12.59 every day and supress the output (redirect to null)

59 12 * * * simon /usr/bin/somecommand >> /dev/null 2>&1

Permissions
If the allow file exists, then you must be listed therein in order to be allowed to use this command. If the allow file does not exist but the deny file does exist, then you must not be listed in the deny file in order to use this command. If neither of these files exists, then depending on site-dependent configuration parameters, only the super user will be allowed to use this command, or all users will be able to use this command.

____________________________________________________________
dircolors

Color setup for `ls', outputs a sequence of shell commands to set up the terminal for color output from `ls' (and `dir', etc.).

SYNTAX

eval `dircolors [options]... [file]`

If FILE is specified, `dircolors' reads it to determine which colors to use for which file types and extensions. Otherwise, a precompiled
database is used. For details on the format of these files, run `dircolors --print-database'.

The output is a shell command to set the `LS_COLORS' environment variable. You can specify the shell syntax to use on the command line, or `dircolors' will guess it from the value of the `SHELL' environment variable.

OPTIONS

`-b'
`--sh'
`--bourne-shell'
Output Bourne shell commands. This is the default if the `SHELL' environment variable is set and does not end with `csh' or `tcsh'.

`-c'
`--csh'
`--c-shell'
Output C shell commands. This is the default if `SHELL' ends with `csh' or `tcsh'.

`-p'
`--print-database'
Print the (compiled-in) default color configuration database. This output is itself a valid configuration file, and is fairly descriptive of the possibilities.
____________________________________________________________
dirs

Display the list of currently remembered directories.

SYNTAX
dirs [+N | -N] [-clpv]

OPTIONS
+N Displays the Nth directory (counting from the left of the list
printed by dirs when invoked without options), starting with
zero.

-N Displays the Nth directory (counting from the right of the list
printed by dirs when invoked without options), starting with
zero.

-c Clears the directory stack by deleting all of the elements.

-l Produces a longer listing; the default listing format uses a tilde to denote
the home directory.

-p Causes dirs to print the directory stack with one entry per
line.
-v Causes dirs to print the directory stack with one entry per
line, prefixing each entry with its index in the stack.
Description
Equivalent to `ls -C -b'; that is,by default files are listed in columns, sorted vertically, and special characters are represented by backslash escape sequences.

____________________________________________________________
du

Estimate file space usage, reports the amount of disk space used by the specified files and for each subdirectory.


SYNTAX
du [options]... [file]...

With no arguments, `du' reports the disk space for the current directory. Normally the disk space is printed in units of 1024 bytes, but this can be overridden

OPTIONS

`-a'
`--all'
Show counts for all files, not just directories.

`-b'
`--bytes'
Print sizes in bytes, overriding the default block size (*note Block size::).

`-c'
`--total'
Print a grand total of all arguments after all arguments have been processed. This can be used to find out the total disk usage of a given set of files or directories.

`-D'
`--dereference-args'
Dereference symbolic links that are command line arguments. Does not affect other symbolic links. This is helpful for finding out the disk usage of directories, such as `/usr/tmp', which are often symbolic links.

`-h'
`--human-readable'
Append a size letter such as `M' for megabytes to each size. Powers of 1024 are used, not 1000; `M' stands for 1,048,576 bytes. Use the `-H' or `--si' option if you prefer powers of 1000.

`-H'
`--si'
Append a size letter such as `M' for megabytes to each size. (SI is the International System of Units, which defines these letters as prefixes.) Powers of 1000 are used, not 1024; `M' stands for
1,000,000 bytes. Use the `-h' or `--human-readable' option if you
prefer powers of 1024.

`-k'
`--kilobytes'
Print sizes in 1024-byte blocks, overriding the default block size
(*note Block size::).

`-l'
`--count-links'
Count the size of all files, even if they have appeared already
(as a hard link).

`-L'
`--dereference'
Dereference symbolic links (show the disk space used by the file or directory that the link points to instead of the space used by the link).

`--max-depth=DEPTH'
Show the total for each directory (and file if -all) that is at most MAX_DEPTH levels down from the root of the hierarchy. The root is at level 0, so `du --max-depth=0' is equivalent to `du -s'.

`-m'
`--megabytes'
Print sizes in megabyte (that is, 1,048,576-byte) blocks.

`-s'
`--summarize'
Display only a total for each argument.

`-S'
`--separate-dirs'
Report the size of each directory separately, not including the sizes of subdirectories.

`-x'
`--one-file-system'
Skip directories that are on different filesystems from the one that the argument being processed is on.

`--exclude=PAT'
When recursing, skip subdirectories or files matching PAT. For example, `du --exclude='*.o'' excludes files whose names end in `.o'.

`-X FILE'
`--exclude-from=FILE'
Like `--exclude', except take the patterns to exclude from FILE, one per line. If FILE is `-', take the patterns from standard input.

On BSD systems, `du' reports sizes that are half the correct values for files that are NFS-mounted from HP-UX systems. On HP-UX systems, it reports sizes that are twice the correct values for files that are NFS-mounted from BSD systems. This is due to a flaw in HP-UX; it also affects the HP-UX `du' program.
____________________________________________________________
echo

Display message on screen, writes each given STRING to standard output, with a space between each and a newline after the last one.

SYNTAX
echo [options]... [string]...

OPTIONS

`-n'
Do not output the trailing newline.

`-E'
Disable the interpretation of the following backslash-escaped characters

`-e'
Enable interpretation of the following backslash-escaped
characters in each STRING:

`\a' alert (bell)

`\b' backspace

`\c' suppress trailing newline

`\e' escape `\f' form feed

`\n' new line

`\r' carriage return

`\t' horizontal tab

`\v' vertical tab

`\\' backslash

`\NNN'
the character whose ASCII code is NNN (octal); if NNN is not
a valid octal number, it is printed literally.

`\xnnn' the character whose ASCII code is the hexadecimal value nnn (one to three digits)
echo is a BASH built-in command
____________________________________________________________
factor

Print prime factors

SYNTAX
factor [number]...

factor option

If no number is specified on the command line, `factor' reads numbers from standard input, delimited by newlines, tabs, or spaces.

Example:

factor 369

output:

369
3
3
41

____________________________________________________________
find

Search a folder hierarchy for filename(s) that meet a desired criteria.

SYNTAX
find [path...] [expression]

find searches the directory tree rooted at each given file name by evaluating the given expression from left to right, according to the rules of precedence (see section OPERATORS), until the outcome is known (the left hand side is false for and operations, true for or), at which point find moves on to the next file name.

The first argument that begins with - ( ) , or ! is taken to be the beginning of the expression; any arguments before it are paths to search, and any arguments after it are the rest of the expression. If no paths are given, the current directory is used. If no expression is given, the expression `-print' is used.

find exits with status 0 if all files are processed successfully, greater than 0 if errors occur.

EXPRESSIONS
The expression is made up of options (which affect overall operation rather than the processing of a specific file,
and always return true), tests (which return a true or false value), and actions (which have side effects and
return a true or false value), all separated by operators. -and is assumed where the operator is omitted. If the
expression contains no actions other than -prune, -print is performed on all files for which the expression is
true.

OPTIONS
All options always return true. They always take effect, rather than being processed only when their place in the
expression is reached. Therefore, for clarity, it is best to place them at the beginning of the expression.

-daystart
Measure times (for -amin, -atime, -cmin, -ctime,-mmin,
and -mtime) from the beginning of today
rather than from 24 hours ago.

-depth
Process each directory's contents before the directory itself.

-follow
Dereference symbolic links. Implies -noleaf.

-help, --help
Print a summary of the command-line usage of find and exit.

-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the command line arguments. `-maxdepth 0' means only apply the tests and actions to the command line arguments.

mindepth levels
Do not apply any tests or actions at levels less than levels (a non-negative integer). `-mindepth 1' means process all files except the command line arguments.

mount Don't descend directories on other filesystems. An alternate name for -xdev, for compatibility with some other versions of find.

noleaf
Do not optimize by assuming that directories contain 2 fewer subdirectories than their hard link count. This option is needed when searching filesystems that do not follow the Unix directory- link convention, such as CD-ROM or MS-DOS filesys tems or AFS volume mount points. Each directory on a normal Unix filesystem has at least 2 hard links: its name and its `.' entry. Additionally, its subdirectories (if any) each have a `..' entry linked to that directory. When find is examining a directory, after it has statted 2 fewer subdirectories than the directory's link count, it knows that the rest of the entries in the directory are non-
directories (`leaf' files in the directory tree).
If only the files' names need to be examined, there is no need to stat them; this gives a significant increase in search speed.

-version, --version
Print the find version number and exit.

-xdev Don't descend directories on other filesystems.

TESTS
Numeric arguments can be specified as

+n for greater than n,

-n for less than n,

n for exactly n.

-amin n
File was last accessed n minutes ago.

-anewer file
File was last accessed more recently than file was modified. -anewer is affected by -follow only if-follow comes before -anewer on the command line.

-atime n
File was last accessed n*24 hours ago.

-cmin n
File's status was last changed n minutes ago.

-cnewer file
File's status was last changed more recently than file was modified. -cnewer is affected by -follow only if -follow comes before -cnewer on the command line.
-ctime n
File's status was last changed n*24 hours ago.

-empty File is empty and is either a regular file or a directory.

-false Always false.

-fstype type
File is on a filesystem of type type. The valid filesystem types vary among different versions of Unix; an incomplete list of filesystem types that are accepted on some version of Unix or another is:
ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K. You can use -printf with the %F directive to see the types of your filesystems.

-gid n File's numeric group ID is n.

-group gname
File belongs to group gname (numeric group ID
allowed).

-ilname pattern
Like -lname, but the match is case insensitive.

-iname pattern
Like -name, but the match is case insensitive. For example, the patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo', `fOo', etc.

-inum n
File has inode number n.

-ipath pattern
Like -path, but the match is case insensitive.

-iregex pattern
Like -regex, but the match is case insensitive.

-links n
File has n links.

-lname pattern
File is a symbolic link whose contents match shell pattern pattern. The metacharacters do not treat `/' or `.' specially.

-mmin n
File's data was last modified n minutes ago.

-mtime n
File's data was last modified n*24 hours ago.

-name pattern
Base of file name (the path with the leading directories removed) matches shell pattern pattern. The metacharacters (`*', `?', and `[]') do not match a `.' at the start of the base name. To ignore a directory and the files under it, use -prune; see an example in the description of -path.

-newer file
File was modified more recently than file. -newer is affected by -follow only if -follow comes before -newer on the command line.

-nouser
No user corresponds to file's numeric user ID.

-nogroup
No group corresponds to file's numeric group ID.

-path pattern
____________________________________________________________

____________________________________________________________
traceroute

Print the route packets take to network host.

SYNTAX
traceroute [options] host [packetsize]

OPTIONS

-d Turn on socket-level debugging.

-g addr Enable the IP LSRR (Loose Source Record Route) option in addition to the TTL tests, to ask how someone at IP address addr can reach a particular target.

-l Include the time-to-live value for each packet received.

-m max_ttl Set maximum time-to-live used in outgoing probe packets to max-ttl hops. Default is 30 hops.

-n Show numerical addresses; do not look up hostnames.
(Useful if DNS is not functioning properly.)

-p port Set base UDP port number used for probe packets to port.
Default is (decimal) 33434.

-q n Set number of probe packets for each time-to-live setting to the value n.
Default is 3.

-r Bypass normal routing tables and send directly to a host on an
attached network.

-s src_addr
Use src_addr as the IP address that will serve as the source address
in outgoing probe packets.

-t tos Set the type-of-service in probe packets to tos (default 0).
The value must be a decimal integer in the range 0 to 255.

-v Verbose-received ICMP packets (other than TIME_EXCEEDED and PORT_UNREACHABLE)
will be listed.

-w wait Set time to wait for a response to an outgoing probe packet to wait
seconds (default is 3 seconds).

____________________________________________________________
units

Convert units from one scale to another. The units are defined in an external data file. You can use the extensive data file that comes with this program, or you can provide your own data file to suit your needs. You can use the program interactively with prompts, or you can use it from the command line.

SYNTAX
units options [FROM-UNIT [TO-UNIT]]

OPTIONS

`-c'
`--check'
Check that all units and prefixes defined in the units file reduce to primitive units. The program will print a list of all units that cannot be reduced.

`--check-verbose'
Like the `-check' option, this option prints a list of units that cannot be reduced. But to help find unit definitions that cause endless loops, it lists the units as they are checked. If `units'
hangs, then the last unit to be printed has a bad definition.

`-o format'
`--output-format format'
Use the specified format for numeric output. Format is the same as that for the printf function in the ANSI C standard. For example, if you want more precision you might use `-o %.15g'.

`-f filename'
`--file filename'
Use filename as the units data file rather than the default units data file `units.dat'.

`-h'
`--help'
Print out a summary of the options for `units'.

`-q'
`--quiet'
`--silent'
Suppress prompting of the user for units and the display of statistics about the number of units loaded.

`-s'
`--strict'
Suppress conversion of units to their reciprocal units.

`-v'
`--verbose'
Give slightly more verbose output when converting units. When combined with the `-c' option this gives the same effect as `--check-verbose'.

`-V'
`--version'
Print program version number, tell whether the readline library has been included, and give the location of the default units data file.
To invoke units for interactive use, type `units' at your shell prompt. The program will print something like this:
1161 units, 53 prefixes
You have:

At the `You have:' prompt, type the quantity and units that you are converting *from*. For example, if you want to convert ten meters to feet, type `10 meters'. Next, `units' will print `You want:'. You should type the type of units you want to convert *to*. To convert to feet, you would type `feet'.

The answer will be displayed in two ways. The first line of output, which is marked with a `*' to indicate multiplication, gives the result of the conversion you have asked for. The second line of output, which is marked with a `/' to indicate division, gives the inverse of the conversion factor. If you convert 10 meters to feet, `units' will print

* 32.808399
/ 0.03048

which tells you that 10 meters equals about 32.8 feet. The second number gives the conversion in the reverse direction.

The `units' program can perform units conversions non-interactively from the command line. To do this, type the command, type the original units expression, and type the new units you want. You will probably need to protect the units expressions from interpretation by the shell using single quote characters.
If you type

units '2 liters' 'quarts'

then `units' will print

* 2.1133764
/ 0.47317647

and then exit. The output tells you that 2 liters is about 2.1 quarts, or alternatively that a quart is about 0.47 times 2 liters.

Unit expressions

In order to enter more complicated units or fractions, you will need to use operations such as powers, products and division. Powers of units can be specified using the `^' character as shown in the following example, or by simple concatenation: `cm3' is equivalent to `cm^3'. If the exponent is more than one digit, the `^' is required.

You have: cm^3
You want: gallons
* 0.00026417205
/ 3785.4118

You have: arabicfoot-arabictradepound-force
You want: ft lbf
* 0.7296
/ 1.370614

Multiplication of units can be specified by using spaces, a hyphen (`-') or an asterisk (`*'). Division of units is indicated by the
slash (`/').

You have: furlongs/fortnight
You want: m/s
* 0.00016630986
/ 6012.8727

Multiplication has a higher precedence than division and is evaluated left to right, so `m/s * s/day' is equivalent to `m / s s day' and has dimensions of length per time cubed. In effect, the first `/' character marks the beginning of the denominator of your unit. In particular, this means that writing `1/2 meter' refers to a unit of reciprocal length equivalent to .5/meter, which is probably not what you would intend if you entered that expression. To indicate division
of numbers, use the vertical dash (`|'). No spaces area permitted on either side of the vertical dash character.

You have: 1|2 inch
You want: cm
* 1.27
/ 0.78740157

Prefixes are defined separately from base units. In order to get centimeters, the units database defines `centi-' and `c-' as prefixes. Prefixes can appear alone with no unit following them. An exponent applies only to the immediately preceding unit and its prefix so that
`cm^3' or `centimeter^3' refer to cubic centimeters but `centi-meter^3' refers to hundredths of cubic meters. Only one prefix is permitted per unit, so `micromicrofarad' will fail, but `micro-microfarad' will work.

For `units', numbers are just another kind of unit. They can appear as many times as you like and in any order in a unit expression. For example, to find the volume of a box which is 2 ft by 3 ft by 12 ft in steres, you could do the following:

You have: 2 ft 3 ft 12 ft
You want: stere
* 2.038813
/ 0.49048148

You have: $ 5 / yard
You want: cents / inch
* 13.888889
/ 0.072

And the second example shows how the dollar sign in the units conversion can precede the five. Be careful: `units' will interpret `$5' with no space as equivalent to dollars^5.

Outside of the SI system, it is often desirable to add values of different units together. Sums of conformable units are written with the `+' character.

You have: 2 hours + 23 minutes + 32 seconds
You want: seconds
* 8612
/ 0.00011611705

You have: 12 ft + 3 in
You want: cm
* 373.38
/ 0.0026782366

You have: 2 btu + 450 ft-lbf
You want: btu
* 2.5782804
/ 0.38785542

The expressions which are added together must reduce to identical expressions in primitive units, or an error message will be displayed:

You have: 12 printerspoint + 4 heredium
Illegal sum of non-conformable units:
12 printerspoint reduces to 0.0042175176 m
4 heredium reduces to 20145.828 m^2

Because `-' is used for products, it cannot also be used to form differences of units. If a `-' appears before numerical digits as the very first character on the input line or if it appears immediately after a `+' then the number will be evaluated as a negative number. So you can compute 20 degrees minus 12 minutes by entering `20 degrees+-12 arcmin'. The `+' character is sometimes used in exponents like `3.43e+8'. Exponents of this form cannot be used when forming sums of units, but they may be used otherwise.

Unit definitions

The conversion information is read from a units data file which is called `units.dat' and is probably located in the `/usr/local/share' directory. If you invoke `units' with the `-V' option, it will print the location of this file. The default file includes definitions for all familiar units, abbreviations and metric prefixes. It also includes many obscure or archaic units.

Many constants of nature are defined, including these:
pi ratio of circumference to diameter
c speed of light
e charge on an electron
force acceleration of gravity
mole Avogadro's number
water pressure per unit height of water
Hg pressure per unit height of mercury
au astronomical unit
k Boltzman's constant
mu0 permeability of vacuum
epsilon0 permitivity of vacuum
G Gravitational constant
mach speed of sound

The database includes atomic masses for all of the elements and numerous other constants. Also included are the densities of various ingredients used in baking so that `2 cups flour_sifted' can be converted to `grams'. This is not an exhaustive list. Consult the units data file to see the complete list, or to see the definitions that are used.

The unit `pound' is a unit of mass. To get force, multiply by the force conversion unit `force' or use the shorthand `lbf'. (Note that `g' is already taken as the standard abbreviation for the gram.) The unit `ounce' is also a unit of mass. The fluid ounce is `fluidounce' or `floz'. British capacity units that differ from their US counterparts, such as the British Imperial gallon, are prefixed with `br'. Currency is prefixed with its country name: `belgiumfranc', `britainpound'.

The US Survey foot, yard, and mile can be obtained by using the `US' prefix. These units differ slightly from the international length units. They were in use until 1959, but for geographic surveys, they are still used. The acre is officially defined in terms of the US
Survey foot. If you want an acre defined according to the international foot, use `intacre'. The difference between these units is about 4 parts per million. The British also used a slightly
different length measure before 1959. These can be obtained with the prefix `UK'.

When searching for a unit, if the specified string does not appear exactly as a unit name, then the `units' program will try to remove a trailing `s' or a trailing `es'. If that fails, `units' will check for a prefix. All of the standard metric prefixes are defined.

To find out what units and prefixes are available, read the standard units data file.

All of the units and prefixes that `units' can convert are defined in the units data file.

____________________________________________________________
useradd

Create new user accounts or update default account information.
Unless invoked with the -D option, user must be given. useradd will create new entries in system files. Home directories and initial files may also be created as needed.

SYNTAX
useradd [options] [user]

OPTIONS
-c comment Comment field.

-d dir Home directory.
The default is to use user as the directory name
under the home directory specified with the -D option.

-e date Account expiration date.
date is in the format MM/DD/YYYY.
Two-digit year fields are also accepted.
The value is stored as the number of days since January 1, 1970.
This option requires the use of shadow passwords.

-f days Permanently disable account this many days after the password has expired.
A value of -1 disables this feature.
This option requires the use of shadow passwords.

-g group Initial group name or ID number.
If a different default group has not been specified using the -D option, the default group is 1.

-G groups Supplementary groups given by name or number in a comma-separated
list with no whitespace.

-k [dir] Copy default files to user's home directory.
Meaningful only when used with the -m option.
Default files are copied from /etc/skel/ unless an alternate dir is specified.

-m Make user's home directory if it does not exist.
The default is not to make the home directory.

-o Override. Accept a nonunique uid with the -u option. (Probably a bad idea.)

-s shell Login shell.

-u uid Numerical user ID. The value must be unique unless the -o option is used.
The default value is the smallest ID value greater than 99 and greater
than every other uid.

-D [options] Set or display defaults. If options are specified, set them.
If no options are specified, display current defaults. The options are:

-b dir Home directory prefix to be used in creating home directories.
If the -d option is not used when creating an account, the
user name will be appended to dir.

-e date Expire date. Requires the use of shadow passwords.

-f days Number of days after a password expires to disable an account.
Requires the use of shadow passwords.

-g group Initial group name or ID number.

-s shell Default login shell.

____________________________________________________________
users

Print login names of users currently logged in, print on a single line a blank-separated list of user names of users currently logged in to the current host.

SYNTAX
users [file]

With no file argument, `users' extracts its information from the file `/var/run/utmp'.

If a file argument is given, `users' uses that file instead. A common choice is `/var/run/wtmp'.

The only options are `--help' and `--version'.
Each user name corresponds to a login session, so if a user has more than one login session, that user's name will appear the same number of times in the output.


____________________________________________________________
env
Display, set, or remove environment variables, Run a command in a modified environment.


SYNTAX
env [OPTION]... [NAME=VALUE]... [COMMAND [ARGS]...]

OPTIONS

-u NAME
--unset=NAME Remove variable NAME from the environment, if it was in the environment.

-
-i --ignore-environment Start with an empty environment, ignoring the inherited enviornment. Arguments of the form `VARIABLE=VALUE' set the environment variable VARIABLE to value VALUE. VALUE may be empty (`VARIABLE='). Setting a variable to an empty value is different from unsetting it.

The first remaining argument specifies the program name to invoke; it is searched for according to the `PATH' environment variable. Any remaining arguments are passed as arguments to that program.

If no command name is specified following the environment specifications, the resulting environment is printed. This is like specifying a command name of `printenv'.

____________________________________________________________
watch

Execute a program periodically, showing output full screen

SYNTAX
watch [options] command command_options

Options

-n --interval=n Specify an interval to run command

-d --differences[=cumulative]] Highlight the differences between successive updates

-h --help Display Help

-v --version Display version
watch runs command repeatedly, displaying its output (the first screenfull). This allows you to watch the program output change over time. By default, the program is run every 2 seconds.

The --cumulative option makes highlighting "sticky", presenting a running display of all positions that have ever changed.

watch will run until interrupted.

Note that command is given to "sh -c" which means that you may need to use extra quoting to get the desired effect.

POSIX option processing is used (i.e., option processing stops at the first non-option argument). This means that command_options don't get interpreted by watch itself.

EXAMPLES
To watch for mail, you might do

watch -n 60 from

To watch the contents of a directory change, you could use

watch -d ls -l

If you're only interested in files owned by user joe, you
might use

watch -d 'ls -l | fgrep joe'

To see the effects of quoting, try these out

watch echo $$

watch echo '$$'

watch echo "'"'$$'"'"

You can watch for your administrator to install the latest
kernel with

watch uname -r

(Just kidding.)

Bugs
Upon terminal resize, the screen will not be correctly repainted until the next scheduled update. All differences highlighting is lost on that update as well.
Non-printing characters are stripped from program output. Use "cat -v" as part of the command pipeline if you want to see them.
____________________________________________________________
Date
By default, date pads numeric fields with zeroes. GNU date recognizes the following modifiers between `%' and a numeric directive.

`-' (hyphen) do not pad the field; useful if the output is intended for human consumption.

`_' (underscore) pad the field with spaces; useful if you need a fixed number of characters in the output, but zeroes are too distracting.

The - and _ are GNU extensions.

Here is an example illustrating the differences:

date +%d/%m -d "Feb 1"
=> 01/02
date +%-d/%-m -d "Feb 1"
=> 1/2
date +%_d/%_m -d "Feb 1"
=> 1/ 2

Setting the time
----------------
If given an argument that does not start with `+', `date' sets the system clock to the time and date specified by that argument (as described below). You must have appropriate privileges to set the system clock. The `--date' and `--set' options may not be used with such an argument. The `--universal' option may be used with such an argument to indicate that the specified time and date are relative to Coordinated Universal Time rather than to the local time zone.

The argument must consist entirely of digits, which have the following meaning:

MM month
DD day within month
HH hour
MM minute
CC first two digits of year (optional)
YY last two digits of year (optional)
SS second (optional)

The `--set' option also sets the system clock; see the next section.

Examples of `date'

* To print the date of the day before yesterday:
date --date='2 days ago'

* To print the date of the day three months and one day hence:
date --date='3 months 1 day'

* To print the day of year of Christmas in the current year:
date --date='25 Dec' +%j

* To print the current full month name and the day of the month:
date '+%B %d'

But this may not be what you want because for the first nine days of the month, the `%d' expands to a zero-padded two-digit field, for example `date -d 1may '+%B %d'' will print `May 01'.

* Print a date without the leading zero for one-digit days of the month, you can use the (GNU extension) `-' modifier to suppress The padding altogether.
date -d=1may '+%B %-d'

* Print the current date and time in the format required by many non-GNU versions of `date' when setting the system clock:
date +%m%d%H%M%Y.%S

* Set the system date and time
date --set="2002-6-29 11:59 AM"

* Set the system clock forward by two minutes:
date --set='+2 minutes'

* Print the date in the format specified by RFC-822, use `date
--rfc'. I just did and saw this:

Mon, 25 Mar 1996 23:34:17 -0600

* To convert a date string to the number of seconds since the epoch (which is 1970-01-01 00:00:00 UTC), use the `--date' option with The `%s' format. That can be useful in sorting and/or graphing and/or comparing data by date. The following command outputs the
number of the seconds since the epoch for the time one second later than the epoch, but in time zone five hours later (Cambridge, Massachusetts), thus a total of five hours and one second after the epoch:

date --date='1970-01-01 00:00:01 UTC +5 hours' +%s
18001

Suppose you had _not_ specified time zone information in the example above. Then, date would have used your computer's idea of the time zone when interpreting the string. Here's what you would get if you were in Greenwich, England:

# local time zone used
date --date='1970-01-01 00:00:01' +%s
1

* If you're sorting or graphing dated data, your raw date values may be represented as seconds since the epoch. But few people can look at the date `946684800' and casually note "Oh, that's the first second of the year 2000."

date --date='2000-01-01 UTC' +%s
946684800

To convert such an unwieldy number of seconds back to a more readable form, use a command like this:

date -d '1970-01-01 946684800 sec' +"%Y-%m-%d %T %z"
2000-01-01 00:00:00 +0000

Read more

Popular Posts

Linux Gazette