Unix/Linux commands Quick reference

Quick Reference: Unix Commands and options

The following format is used for commands:
Italic indicates a variable that you supply
Bold indicates exactly what you type
[ ] Square brackets indicate that the thing which they surround is optionally typed. The square brackets themselves are not to be typed.

To display a command description from the Unix Manual and can be used to get more information on each command. Type following on shell prompt to see the manual:
man command
Example: man ls to find more about the command ls

If you are not sure of the exact command name, you can use man with the -k option to help you find the command you need. To see one line summaries of each reference page that contains the keyword you specify, enter: man -k keyword

Command

Action

Example

Creates a temporary name (alias) for a Unix command. When you type alias-name, string is substituted and run in its place. Typically, you put alias commands in your .cshrc file. Aliases can be self-referential without causing infinite recursion, e.g.:
alias rm ‘rm -i’
alias alias_name string
To remove an alias unalias name
ansiprint Prints a file to a printer connected to your computer. ansiprint file
apropos Find a list of manual pages about a keyword. apropos keyword
Ar Create and maintain library archives
archie search the Archie database for a file on a FTP site archie file
asa Text Processing: Interpret carriage-control characters
assets Displays your account resources, use, and threshold.
At Process Management: Execute commands at a later time
awk Text Processing: Pattern scanning and processing language. awk is most commonly used to extract numbered fields from lines of text. For example, the following command prints the third word on each line: awk also supports more complicated scripting – see the manual page. awk '{print $5}' [file]

basename File system: Return non-directory portion of a pathname
batch Process Management: Schedule commands to be executed in a batch queue
Bc A simple calculator; Arbitrary-precision arithmetic language. Uses integer arithmetic by default. For floating-point arithmetic, type “bc -l”.
Process Management: Places or runs job in the background.
break Shell programming: Exit from for, while, or until loop
cal Display a calendar of the current month.
Display a calendar of the given month and year. Note that the year must be fully qualified, for example, “2003” and not “03.” cal month year
File system: Concatenate and displays specified files cat file
Overwrites the file2 with the content of file1 cat file1>file2
Append file1 to the end of file2 cat file1>>file2
Creates a file, typing some text, and finishing by pressing ctrl-d at the start of a line. cat  > file1
Cc Compile a C program
Cd File system: Changes current directory to a different directory. cd directory
To change back to your home directory: cd
Directory abbreviations:

~ Home directory

.. Parent directory

. Current working directory

cflow C Programming : Generate a C-language flowgraph
chfn change your “Real Name” as seen on finger
chgrp File system: Change the file group ownership. Makes file belong to the group user. NOTE: You must be the owner of the file/directory or be root chgrp user file
chmod File system: Change the file modes/attributes/permissions NOTE: You must be the owner of the file/directory or be root chmod code file
chmod code directory
To keep a file private chmod 600 file
To give everyone read permission: chmod 664 file
chown File system: Change the file ownership NOTE: You must be the owner of the file/directory or be root chown new_own file
Makes cliff(new_own) the owner of dir and everything in its directory tree. NOTE: You must be the owner of the file/directory or be root chown -R cliff dir
chsh change the shell you log into
cksum File system: Write file checksums and sizes
clear Clears terminal screen clear
cmp File system: Compare two files
comm Text Processing: Select or reject lines common to two files
command Shell programming: Execute a simple command command
Shell programming: Executes command1 in background Command1&
compress File system: Reduces the size of a file and adds .Z to the file’s name. compress file
To restore a compressed file: uncompress file.Z
continue Shell programming: Continue for, while, or until loop
Cp File system: Makes a copy of a file. cp file1 file2
To copy a file into a different directory: cp file directory
To inquire before overwriting an existing file: cp -i file1 file2
To copy a directory and, recursively, its subdirectories cp -r dir1 dir2
To retain timestamp while copying cp -p
crontab Schedule periodic background work
csplit Text Processing: Split files based on context
ctags C Programming: Create a tags file
cut Shell programming: Cut out selected fields of each line of a file
cxref C Programming: Generate a C-language program cross-reference table
date Display the current local date and time. date
Dd File system: Convert and copy a file
delta Make a delta (change) to an SCCS file
Df File system: Report free disk space available on the system
print list of disks and current capacity (in kilobytes) df -k
Text Processing: Compares two files and displays the differences. Here, shows differences between file1 and file2 diff file1 file2
dirname File system: Return the directory portion of a pathname
dos2unix strips CR’s out of dos text files dos2unix <file> <new_file>
dot Shell programming: Execute commands in the current environment
Du File system: Estimate file space usage du
Print size (in kilobytes) of current directory (“.”). Variations:
du -sk * prints sizes (in kilobytes) of all files and sub-directories
du -sk file prints size (in kilobytes) of file

du -sk dir prints sum of size (in kilobytes) of dir and its contents

du -sk
dvips Print .dvi files (i.e. files produced by LaTeX). You can use dviselect to print only selected pages. dvips filename
echo Shell programming: Displays a line of text or

Write arguments to standard output. Note that the shell will expand variables in the line, e.g. ” echo $user ” will print the contents of the variable user. Use single quotes (e.g. ” echo '$user' “) if you want to prevent this.

echo text
Example: This command find out what shell you are using by the command echo $SHELL
Ed Text Processing: The standard text editor
elm Another email program
emacs Text editor: Edit a file using the emacs editor. Not all systems will have emacs. It’s Extremely versatile. In emacs, press ctrl-h, t for a tutorial. emacs filename
env Set the environment for command invocation
eval Shell programming: Construct command by concatenating arguments
Ex Text Processing: Text editor
exec Shell programming: Execute commands and open, close, or copy file descriptors
exit Shell programming: Exits from the current shell. Similar to logout, but can also be used in shell scripts.
expand Text Processing: Convert tabs to spaces
export Set the export attribute for variables
expr Shell programming: Evaluate arguments as an expression. Give it expressions on the command line. Make sure to put spaces around the numbers, e.g.
expr ‘2 + 2’
exprexpression

false Shell programming: Return false value
Fc Process the command history list
Ff Find files anywhere on the system. This can be extremely useful if you’ve forgotten in which directory you put a file, but do remember the name. In fact, if you use ff -p you don’t even need the full name, just the beginning. This can also be useful for finding other things on the system, e.g. documentation.
Process Management: Restarts a suspended job in the foreground.
File File system: Determine file type file files
find File system: Find the loation of file.1 in the directory and sub-directories. Variations:
find . -name “*pattern” -print finds all files that end with pattern.
find . -name file.1 -exec rm ‘{}’ ‘;’ removes all files named file.1.
find . -name file.1 -print
finger Displays user information at the specified computer. finger userid@computer
To change your finger entry information: chfn
fold Text Processing: Filter for folding lines
fort77 C Programming: FORTRAN compiler
ftp Starts the file transfer program with a remote computer insecurely. This method does not use encryption, so there is a risk of your password and other data being spied on. It should be avoided wherever scp is available. ftp host_address
fuser Process Management: List process IDs of all processes that have one or more files open
gcc Compiles C source into a file named ‘a.out’. It compiles a C program with the GNU C-compiler gcc file.c
gencat Generate a formatted message catalog
genscript Converts plain text files into postscript for printing, and gives you some options for formatting. Consider making an alias like alias ecop ‘genscript -2 -r !* | lpr -h -Pvalkyr’ to print two pages on one piece of paper.
getconf Get configuration values
getopts Shell programming: Parse utility options
gopher A Gopher database browser
Finds lines in a file matching a character pattern. grep comes in several varieties (grep, egrep, and fgrep) and has a lot of very flexible options. Check out the man pages if this sounds good to you. grep -icvn pattern file
-i Ignores case

-c Lists count of lines that contain pattern

-v Lists all lines except those with pattern

-n Lists line number for each found pattern

gzip Compress the specified files. This turns filename into filename.gz, which is smaller.
Text files compress very well, but with binary data files you might not save much disk space
gzip file...

Uncompress the specified files.The opposite of the gzip command. gunzip file...
To  look at a gzipped file without actually having to gunzip it (same as gunzip -c). You can even print it directly, using gzcat filename | lpr gzcat filename
hash Remember or report utility locations
Text Processing: Displays the first ten lines of a file. head file
To display the first n number of lines head -n file
help Displays an online help note. help note
To display a list of help notes: help -l
history Displays a list of your most recent commands. history
To repeat the nth command from the list. (for example, type “!m” to repeat the last command that began with “m”) ! n
To repeat your most recent command !!
hostname Show the name of the machine
iconv Text Processing: Codeset conversion
Id Return user identity
ipcrm Remove a message queue, semaphore set, or shared memory segment identifier
ipcs Report interprocess communication facilities status
Irc connect to Internet Relay Chat
Process Management: Displays active jobs and their corresponding job numbers jobs
To start a job in the background: job &
To return a job to the foreground by the job number fg %number
To send a running job to the background: <Control>z bg
join Text Processing: Relational database operator
Process Management: Terminates a process by its process identification number. kill pid
Remove suspended process #1 kill %1
To use the strongest form of the kill command: kill -9 pid
less Shows file a page at a time. Like more, but you can use Page-Up too. Not on all systems less filename
Lex C Programming: Generate programs for lexical tasks
link File system: Call link function
Ln File system: Link files
Make symbolic links; make a link file2, which points to file1 ln -s file1 file2
locale Get locale-specific information
localedef Define locale environment
logger Shell programming: Log messages
login Logs in the system or starts a computer session
logname Return the user’s login name
Ends your computer session; logs off the system
Lpr Text Processing: Show list of available printers and questions to direct your printing of a file to a particular printer lpr
If you put several filenames after lpr, this will typically send several files in a single print job. The -Pprinter option sends the job to the specified printer. If you do not specify a -Pprinter option, then lpr will use the contents of the PRINTER environment variable. You may wish to setup a default printer by putting a line like the following into your .login file: setenv PRINTER mylocalprinter lpr files

lpr -Pprinter files

lprm Remove print job from the printer queue. You can find the job number by using lpq. Theoretically you also have to specify a printer name, but this isn’t necessary as long as you use your default printer in the department. lprm -Pprinter job_numbers

Lpq Show the queue of jobs for a given printer or default printer in case -Pprinter is not specified. e.g. to get the job number needed for removal, or to see how many other files will be printed before yours will come out lpq -Pprinter

ls File system: Lists the files and subdirectories in your current directory. ls -Fltra
-l     Lists long format

-t     Lists by modification time

-r     Lists in reverse order

-F     Lists file type with special character

-a     Lists all files including dot (.) files

lynx Starts a text-only web browser session at UW home page. It’s a textual World Wide Web browser lynx
Starts a Web browser session at a specific Web address. lynx url
mailx Process messages
make Maintain, update, and regenerate groups of programs; compiles source code
Displays Unix Manual entry for a command. man command
To search Manual Index for a keyword or topic: man -k keyword
Mc “midnight commander” – Interactive file explorer. Provides an alternative to many typed commands. NB not installed on many systems
mesg Displays your talk and write message access status. mesg
To set your message status to yes or no: mesg y (or n)
mkdir File system: Creates a new directory within your current directory. mkdir directory
mkfifo File system: Make FIFO special file
more Text Processing: Displays a file one screen at a time. views a file, pausing every screenful. If no files are specified on the command line, then more displays standard input. For example, if you want to list a lot of files a screen at a time, type: ls | more
Press space to go forward one screen, enter to go forward one line.
more file
Use <Spacebar> to scroll forward and q to quit.
Mv File system: Moves a file to a different directory. mv file directory

mv files directory

Moves a directory to a second directory. mv directory1 directory2
To rename file1 as file2: mv file1 file2
To rename directory1 as directory2: mv directory1 directory2
To inquire before overwriting an existing file: mv -i file1 file2
netscape Graphical web browser and Email Program: Mainly used for web browsing, it can also be used for sending and receiving email
newgrp Change to a new group
nice Process Management: Invoke a utility with an altered nice value to change priority of job
Nl Text Processing: Line numbering filter
Nm C Programming: Write the name list of an object file
nohup Process Management: Invoke a utility immune to hang-ups; it continue a job even after logout
Od Dump files in various formats
osview display the operating system statistics osview
paste Text Processing: Merge corresponding or subsequent lines of files
Starts program to change account password. You’ll have to type your old password before you type a new one.
You won’t see the password when you type it, but you type it twice to make sure. Choose a password which can’t be easily guessed, and keep it secret.
patch Text Processing: Apply changes to files
pathchk File system: Check pathnames
pico Easy-to-use text editor: Starts the Pico text editor with a file,but not very powerful! The same as you get with the pine mailer. pico file
pine It’s an easy to use mail program. Starts the Pine® electronic mail program.
Pr Text Processing: Print files
printenv Show content of an environment variable. If variable is not typed, printenv will list all the environment variables. printenv [variable]
printf Shell programming: Write formatted output
Prs Print an SCCS file
Ps Process Management: Displays processes and their corresponding process identification numbers.
Display expanded list of all processes and typically show everybody’s processes. ps -ef
pushd Add entry to directory stack Use this to go temporarily to another directory. pushd directory
Type popd when you want to go back to the directory you were in when you typed pushd; means to remove entry from directory stack popd
pwd File system: Displays absolute pathname of current directory. i.e. show the directory that you are in (present working directory)
qalter Batch Utilities: Alter batch job
qdel Batch Utilities: Delete batch jobs
qhold Batch Utilities: Hold batch jobs
qmove Batch Utilities: Move batch jobs
qmsg Batch Utilities: Send message to batch jobs
qrerun Batch Utilities: Rerun batch jobs
qrls Batch Utilities: Release batch jobs
qselect Batch Utilities: Select batch jobs
qsig Batch Utilities: Signal batch jobs
qstat Batch Utilities: Show status of batch jobs
qsub Batch Utilities: Submit a script
quota Finding out your available disk space quota. Show how your disk usage compares with your permitted maximum. Your disk usage may exceed your “quota” for a short “grace period” (typically a week), but it may never exceed your “limit”. If the grace period runs out, you will have to delete files before you can create any more.
You may have to type “quota -v” to get full information.
quota -v
Rcp Copy files between machines (insecurely). Usage is analogous to scp.

This method does not use encryption, so there is a risk of your password and other data being spied on. It should be avoided wherever scp is available

rcp [username@]machine:file file
read Shell programming: Read a line from standard input
readonly Set the readonly attribute for variables
renice Process Management: Set nice values of running processes. Your command will have less impact on other users. number typically ranges from 0 to 19. process can either be a “PID” number as reported by ps or top, or “%jobnumber” as reported by jobs. renice number process
return Shell programming: Return from a function
File system: Permanently deletes a file. rm file
To verify prior to removal rm -I file
To remove directory, subdirectories with files recursively rm -r directory
To forcibly remove directory content recursively without having write permission on it rm -rf directory
rmdir File system: Deletes an empty directory. rmdir directory
To verify prior to removal rmdir -i directory
Rz Recieve a file (to the unix system) using zmodem
scp Copy files between machines (securely) The syntax would copy a file from a remote machine to the local machine. To do the converse, use: scp file [username@]machine:file
Omit the “username@” bit if your username on the other machine is the same as on the local machine.
scp [username@]machine:file file
sed Text Processing: Stream editor. It is most commonly used to perform search-and-replace operations on text. The following command globally replaces pattern with replacement. It also supports more complicated scripting – see the manual page sed 's/pattern/replacement/g' [file]

set Set or unset options and positional parameters. The value of shell variables can be accessed as “$variable”. Shell variables are seen only by the shell, and are not passed to commands. set variable=value

setenv List environmental variables. setenv
Set an environment variable

The value of environment variables can be accessed as “$variable“. Block capitals are conventionally used for names of environment variables. Environment variables are passed from the shell to commands, and may affect the behavior of commands (e.g. $PRINTER affects lpr).

setenv variable value
sftp Secure file transfer protocol
Sh Shell programming: Shell, the standard command language interpreter
shift Shell programming: Shift positional parameters
sleep Shell programming: Suspend execution for an interval
sort Text Processing: Sort, merge, or sequence check text files. Order the lines in a file or files alphabetically (this command does not alter the file or files — it merely displays the sorted output to the screen) sort files

Displays contents of files sorted alphabetically in reverse order. sort -r files
Displays contents of files sorted numerically (puts 2 before 10 instead of after). sort -n files
Checks the spelling in a file. spell file
split Split files into pieces
ssh Connect to another machine ssh hostname
staffdir Displays the Online UW Staff Directory. staffdir lastname, firstname
To display all fields: staffdir -full lastname, firstname
strings C Programming: Find printable strings in files
strip C Programming: Remove unnecessary information from executable files
stty Set the options for a terminal
Sz Send a file (to you) using zmodem
tabs Set terminal tabs
tail Text Processing: Copy the last ten lines of a file tail file
Text Processing: To display the last n number of lines tail -n file
Text Processing: It skips initial n number of lines and displays rest Tail +n file
talk Initiate a conversation with another user (end conversation with Control-C); talk works only between machines of the same architecture. This feature disabled on many systems. talk user[@machine]
Tar The tar command stands for “tape archive”. It is the “standard” way to read and write archives (collections of files and whole directory trees. It combines multiple files into one or vice-versa; store an image of dir.1 and it’s contents in file file.1 tar -cvf dir.1.tar dir.1
Extracts (x) files from the default tape drive while listing (v = verbose) the file names to the screen tar -xv dir.1.tar
tee Shell programming: Duplicate standard input
telnet Starts a telnet session with a remote computer. telnet host_address
test Shell programming: Evaluate expression
time Process Management: Time a simple command
times Process Management: Write process times
Tin, trn Read Usenet newsgroups
top Display the current, most computer-intensive commands. Press “q” to quit from the display top
touch File system: Change file access and modification times
tput Change terminal characteristics
Tr Text Processing: Translate characters
trap Process Management: Trap signals
tree Draw a tree-like recursive directory listing. Not installed on many systems
true Shell programming: Return true value
tsort Text Processing: Topological sort
Tty Return user’s terminal name
type Displays how a name would be interpreted if used as a command
ulimit Set or report file size limit
umask Get or set the file mode creation mask means change permissions on new files
unalias Remove alias definitions
uname Return system name
uncompress Expand compressed data
unexpand Text Processing: Convert spaces to tabs
unget Undo a previous get of an SCCS file
uniq Text Processing: Report or filter out repeated lines in a file
unix2dos adds CR’s to unix text files unix2dos <file> <new_file>
unlink File system: Call the unlink function
unset Unset values and attributes of variables and functions
uucp System-to-system copy
uudecode Decode a binary file
uuencode Encode a binary file
uustat uucp status inquiry and job control
uux Process Management: Remote command execution
val Validate SCCS files
Text Processing: Starts the vi text editor with a file. vi file
Displays a list of who is on system and what they are doing. Especially useful: the ‘idle’ part. This allows you to see whether they’re actually sitting there typing away at their keyboards right at the moment.
wait Process Management: Await process completion
Wc Text Processing: counts lines, words, and characters in file file. Variations:
wc -l counts lines in file file
wc -w counts words in file file
wc -c counts characters in file file
wc -lwc file
what Identify SCCS files
where Find out the places where a command program is installed on the system. This uses your search path ($PATH) to know where to look. If the program is installed in more than one place, the first one listed is the one which is run when you type the command. where command
which List location of executable command. It’s same as where command, but only lists the first occurrence of the command. which command
who Display a list of users currently logged into system who
Display list current user in that window whoami or who am i
write Write to another user’s terminal, (user) is a email address; <ctrl-c> to end write user
xargs Shell programming: Construct argument lists and invoke utility
xcal Graphical calculator application. Fairly intuitive to use. Type sums, or press the calculator buttons with the mouse
xemacs

Alternative version of emacs. The “normal” emacs is the GNU version. This is a slightly different version which you may or may not prefer.
xhost Permit another machine to open windows on the display. This command is insecure, because it makes no distinction between users on the remote machine. It should not be used when ssh is in use. xhost machine
xman Graphical interface to manual pages
yacc C Programming: Yet another compiler compiler
zcat Text Processing: Expand and concatenate data zcat file
Zip zip the file
Jun 24th, 2009 | Posted by Tushar Thakker | In Linux/Unix/Solaris, Shell scripting, Unix administration
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>