NAME

Command Cheats - Cheat sheet for commonly used Unix commands


VERSION

Version: 0.9

Last Modified: Wed Sep 8 11:28:09 EDT 2004


COPYRIGHT

The information contained herein is copyright (c) 1998-2004 by Frank J. Edwards of Edwards & Edwards Consulting. License is granted for personal use only. Within a company environment, individuals may use this information for their consumption only; presenting this summary without this copyright notice and contact information remaining intact is a violation of the copyright.


GENERAL FORMAT

The general format of each entry is:


command

A brief description of what the command does. Usually only a sentence or two.

-opt1

A description of the first option (called -opt1 in this case).

-opt2

The second option being described. And so on...

Hopefully, this strategy will allow you to find what you're looking for quickly. All of the extraneous options that I don't use myself are removed, so you'll see just the more common ones.


DESCRIPTION

All of the commands which take filename parameters may use wildcards in those positions, but remember how to use the shell's single and double quotes to prevent wildcard expansion when parameters contain spaces, tabs, etc.


ps

Process status. Generates a list of all running processes.

    -f  full listing of command lines (use -l on some systems)
    -e  every process on the system
    -u  particular user's processes, i.e. "ps -uroot,fred"
    $ ps [-options]


mail, mailx, Mail

Electronic mail.

To send email, specify user names on the command line, i.e. mail root fred

To read email, don't give any user names, i.e. mail


ls

List directories. List the contents of the given directories.

    -l    long listing
    -a    all hidden files (those that start with a dot) are listed also
    -F    append an attribute character to each filename [see ls(1)]
    $ ls [-options] [directory(s)]


pg

Paginate files. Use h at the colon prompt for the help screen. (See also more)

    -c    clear screen before each page is displayed
    $ pg [-options] [filename(s)]


cat

Read file(s) and send to stdout.

    -v    To see control characters printed as visible sequences.
    -e    To see end-of-line characters as dollar signs.
    -t    To see tab characters as ^I.
    $ cat [filename(s)]


tee

Read stdin and send to stdout. Save a copy of the data in files specified.

    -a    Append to the output file(s) instead of overwriting them.
    $ ls -l | tee file1 file2 | sort | mail root


grep

Globally search for Regular Expression and Print.

    See page 2 (at the bottom of this page) for a summary
    of Regular Expression syntax.
    $ grep 'regexpr' [filename(s)]


cd

Change current directory. No parameters returns to $HOME directory.

    -     Return to the directory the shell was last in.
    $ cd [directory]


pwd

Print full pathname of current directory.

    $ pwd


vi

Full-screen visual editor.

    $ vi [-options] [file(s)]


rm

Remove specified files and/or directories.

    -r    recursive - removes given file/directory and all subdirectories.
    -i    interactive - prompt for each file before removing.
    $ rm [-options] file(s)


chmod

Change the modes (permissions) on files and directories.

    Options allow specification of user, group, or other permission
    fields, whether to add, remove, or specify certain bits, and
    read, write, execute, and setid permission bits.
    $ chmod [ugo][+-=][rwxst] file(s)


chgrp

Change the group id on files and directories; only the file owner and root may do this, and the owner may only specify groups for which they are already a member.

    $ chgrp group file(s)


chown

Change the owner of files and directories; only root may do this.

    $ chown userid file(s)


cp

Copy files from one directory/filename to another.

    $ cp old_file new_file
    $ cp file(s) directory


mv

Move files from one directory/filename to another.

    $ mv old_file new_file
    $ mv file(s) directory


sort

Sorts given files; many options for controlling sort key(s).

    Reads stdin if no files given; writes to stdout if no output
    file given [see sort(1)].
    $ ls -il | sort -n


find

Locates files by recursively searching a directory list.

    -type [bcdflp]   Only particular file type
    -name "pattern"  Only files which match shell wildcard "pattern"
    -print           Print list of names to stdout
    -mtime n         Only files with certain modification times,
                         n < 0: less than n days
                         n > 0: more than n days
                         n = 0: today
    -size n          Only files with size n [see above for ranges]
    -user id         Only files owned by user id (alpha or numeric);
                     ids are separated by commas
    -exec cmd ';'  Execute "cmd" for each filename found
    -ok cmd ';'    Same as -exec, but prompts before executing "cmd".
                     The current filename is substituted for {} within
                     "cmd", ie. -exec ls -l {} ';'
    <exp> -o <exp>   Logical OR of two expressions (default is AND)
    `(' <exp> `)'    Logical grouping of expressions
    ! <exp>          Logical negation of expression


Regular Expressions

    In the following descriptions, an RE is any single character
    unless one of the special metacharacters is used.  The
    metacharacters may be made literal by preceding them with
    a backslash ("\").

  Character   Meaning
     [ ]      Match any single character from given set.  Allows - for
              range, and ^ immediately after open bracket to negate the
              set (same as "[]" in the shell).
      .       Match any single character [same as "?" in the shell]
      *       Match zero or more of preceding RE (".*" RE same as "*"
              in shell)
      $       Match EOL when $ appears at the end of the pattern
      ^       Match BOL when ^ appears at the beginning of the pattern

  Only in egrep, sed, awk, and vi:
      ?       Match zero or one of preceding RE
      +       Match one or more of preceding RE
      |       Logical OR between two REs

  The following only work in sed or vi, not grep.
     \<       Match beginning of word.
     \>       Match end of word.
    \( \)     Creates a subpattern RE.
     \n       Where n is 0 through 9, specifies subpattern n in
              the replacement string.