Essential Unix Commands
Essential Unix Commands
These are ten commands that you really need to know in order to get started with UNIX.
They are probably similar to commands you already know for another operating system.
10. mpage <opt> mpage -8 file1 Print 8 pages on a single sheet and
<file> | lpr send to printer (the font will be
small!)
3. alias alias lls="ls -alF" Create new command "lls" for long
format of ls
Unix Commands
Command/Syntax What it will do
awk/nawk [options] file scan for patterns in a file and process the results
cat [options] file concatenate (list) a file
cd [directory] change directory
chgrp [options] group file change the group of the file
chmod [options] file change file or directory access permissions
chown [options] owner file change the ownership of a file; can only be done by the superuser
chsh (passwd -e/-s)
change the user's login shell (often only by the superuser)
username login_shell
compare two files and list where differences occur (text or binary
cmp [options] file1 file2
files)
compress [options] file compress file and save it as file.Z
copy file1 into file2; file2 shouldn't already exist. This command
cp [options] file1 file2
creates or overwrites file2.
cut (options) [file(s)] cut specified field(s)/character(s) from lines in file(s)
date [options] report the current date and time
dd [if=infile] [of=outfile] copy a file, converting between ASCII and EBCDIC or swapping
[operand=value] byte order, as specified
diff [options] file1 file2 compare the two files and display the differences (text files only)
df [options] [resource] report the summary of disk blocks and inodes free and in use
du [options] [directory or
report amount of disk space in use
file]
echo [text string] echo the text string to stdout
ed or ex [options] file Unix line editors
emacs [options] file full-screen editor
expr arguments evaluate the arguments. Used to do arithmetic, etc. in the shell.
file [options] file classify the file type
find directory [options]
find files matching a type or pattern
[actions]
finger [options]
report information about users on local and remote machines
user[@hostname]
ftp [options] host transfer file(s) using file transfer protocol
grep [options] 'search string'
argument
egrep [options] 'search search the argument (in this case probably a file) for all
string' argument occurrences of the search string, and list them.
fgrep [options] 'search
string' argument
gzip [options] file
gunzip [options] file compress or uncompress a file. Compressed files are stored with
a .gz ending
zcat [options] file
head [-number] file display the first 10 (or number of) lines of a file
hostname display or set (super-user only) the name of the current machine
kill [options] [-SIGNAL] send a signal to the process with the process id number (pid#) or
[pid#] [%job] job control number (%n). The default signal is to kill the process.
ln [options] source_file
link the source_file to the target
target
lpq [options] show the status of print jobs
lpstat [options]
lpr [options] file
print to defined printer
lp [options] file
lprm [options]
remove a print job from the print queue
cancel [options]
ls [options] [directory or
list directory contents or file permissions
file]
mail [options] [user]
simple email utility available on Unix systems. Type a period as
mailx [options] [user] the first character on a new line to send message out, question
Mail [options] [user] mark for help.
man [options] command show the manual (man) page for a command
mkdir [options] directory make a directory
more [options] file
less [options] file page through a text file
pg [options] file
mv [options] file1 file2 move file1 into file2
octal dump a binary file, in octal, ASCII, hex, decimal, or
od [options] file
character mode.
passwd [options] set or change your password
paste [options] file paste field(s) onto the lines in file
pr [options] file filter the file and print it on the terminal
ps [options] show status of active processes
pwd print working (current) directory
rcp [options] hostname remotely copy files from this machine to another machine
rlogin [options] hostname login remotely to another machine
remove (delete) a file or directory (-r recursively deletes the
rm [options] file
directory and its contents) (-i prompts before removing files)
rmdir [options] directory remove a directory
rsh [options] hostname remote shell to run on another machine
saves everything that appears on the screen to file until exit is
script file
executed
stream editor for editing files from a script or from the command
sed [options] file
line
sort [options] file sort the lines of the file according to the options chosen
source file read commands from the file and execute them in the current
. file shell. source: C shell, .: Bourne shell.
report any sequence of 4 or more printable characters ending in
strings [options] file <NL> or <NULL>. Usually used to search binary files for ASCII
strings.
stty [options] set or display terminal control options
tail [options] file display the last few lines (or parts) of a file
tar key[options] [file(s)] tape archiver--refer to man pages for details on creating, listing,
and retrieving from archive files. Tar files can be stored on tape
or disk.
tee [options] file copy stdout to one or more files
telnet [host [port]] communicate with another host using telnet protocol
touch [options] [date] file create an empty file, or update the access time of an existing file
translate the characters in string1 from stdin into those in string2
tr [options] string1 string2
in stdout
uncompress file.Z uncompress file.Z and save it as a file
uniq [options] file remove repeated lines in a file
uudecode [file] decode a uuencoded file, recreating the original file
encode binary file to 7-bit ASCII, useful when sending via email,
uuencode [file] new_name
to be decoded as new_name at destination
vi [options] file visual, full-screen editor
wc [options] [file(s)] display word (or character or line) count for file(s)
report the binary, source, and man page locations for the
whereis [options] command
command named
which command reports the path to the command or the shell alias in use
who or w report who is logged in and what processes are running
concatenate (list) uncompressed file to screen, leaving file
zcat file.Z
compressed on disk
grep pvm_pack *.cpp will look for occurrences of the string "pvm_pack" in all
files ending in ".cpp".
grep "My name is" * will look in all files in a directory trying to find the
string "My name is".
With the use of the > for sending output to a file, a user can easily covert from screen
display programs to ones that save the output without major changes in rewriting
code. It is also very convenien for grabbing the output from various UNIX
commands, too.
myprogram > myoutfile
This takes the output of "myprogram" and sends it a file called
"myoutfile".
Pipes
The vertical bar "|" is called the pipe symbol, and it is designed for linking
commands together to make them more powerful. The way it works is that
the output from one command is sent as input to the next, thus creating a
new command.
The Basics of vi
There are essentially three Modes in vi, the Insert Mode where one is typing in
new text, the Edit Mode where one is modifying text that is already there, and
the Command Mode where one is interacting with the operating system with
actions like reading and writing files.
Most of the commands require just a simple letter or two, but be careful to note that vi is case
sensitive, and capital letters do different things from lower case letters. It is not necessary to
learn all of these commands, but eventually they will become second nature. The basic
operations needed to create a file are related to each of those modes, so let's look at them
separately.
• INSERT Mode - For adding text to a file
The three most common ways to enter the Insert Mode are:
Letter Action
• EDIT Mode
- Generally for moving the cursor and deleting stuff.
In the Edit Mode, the keys do not type letters, but do other actions such as
cursor movement, deletions, copying lines, etc.
Modifying Text
Puts the yanked text on the line below the cursor (lower
p
case p)
Letter Action