Command Cheats - Cheat sheet for commonly used Unix commands
Version: 0.9
Last Modified: Wed Sep 8 11:28:09 EDT 2004
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.
The general format of each entry is:
A brief description of what the command does. Usually only a sentence or two.
A description of the first option (called -opt1 in this case).
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.
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.
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]
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
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)]
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)]
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)]
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
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)]
Change current directory. No parameters returns to $HOME
directory.
- Return to the directory the shell was last in.
$ cd [directory]
Print full pathname of current directory.
$ pwd
Full-screen visual editor.
$ vi [-options] [file(s)]
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)
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)
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)
Change the owner of files and directories; only root may do this.
$ chown userid file(s)
Copy files from one directory/filename to another.
$ cp old_file new_file
$ cp file(s) directory
Move files from one directory/filename to another.
$ mv old_file new_file
$ mv file(s) directory
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
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
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.