BasicCommands
This is a quick reference guide, mostly made of standard Unix commands . POSIX utilities, every Unix / Linux distribution has these.
POSIX stands for Portable Operating System Interface based on uniX).
For more information about each command, refer to a Unix manual or the man (stands for manual) command. Type man command at a consile/TelNet/SSH/xterm Client Software prompt etc… to get info about using the “man” or “info” command.
at : execute commands at a specified time/date.
awk : a scripting language, especially useful for manipulating text and automation.
Unix legend, who owes us nothing, keeps fixing foundational AWK code
bash : invokes the Bourne Again Shell (standard on most boxes).
batch : execute commands when load permits.
bc : interactive C-like calculator
A calculator program that handles arbitrary precision (very large) numbers. It is useful for doing any kind of calculation on the command-line. Its use is left as an exercise.
Some books refer to is as an integer only calculator, but they are not aware of the scale fucntion
Use scale=5 for five decimal places.
cal : displays a calender, also lets you choose month/year using parameters.
Prints out a nicely formatted calender of the current month, a specified month, or a specified whole year. Check out cal 1752 then see the man page for Sep 1752
calender : invoke a reminder service.
cancel : cancel request to calender.
cat : concatenate files (displays a file without scrolling ability. Simply dumps it to the standard output. Can be useful when chaining multiple applications to do complicated jobs, so one application can use another's output as input). cat <filename> [<filename> …]
Writes the contents of all the files listed to the screen. cat can join a lot of files together with cat <filename> <filename> ... > <newfile>. The file <newfile> will be an end-on-end concatenation of all the files specified.
cd : change the current working directory.
The cd command is used to take you to different directories. Create a directory new with mkdir new. You could create a directory one by doing cd new and then mkdir one, but there is a more direct way of doing this with mkdir new/one. You can then change directly to the one directory with cd new/one. And similarly you can get back to where you were with cd ../… In this way, the / is used to represent directories within directories. The directory one is called a subdirectory of new
Relative vs. Absolute Pathnames
Commands can be given file name arguments in two ways. If you are in the same directory as the file (i.e., the file is in the current directory), then you can just enter the file name on its own (e.g., cp my_file new_file). Otherwise, you can enter the full path name, like cp /home/jack/my_file /home/jack/new_file. Very often administrators use the notation ./my_file to be clear about the distinction, for instance, cp ./my_file ./new_file. The leading ./ makes it clear that both files are relative to the current directory. File names not starting with a / are called relative path names, and otherwise, absolute path names.
chgrp : change group ownership of a file.
chmod : change access patterns (permissions) to files.
chown : change user ownership of files.
clear : clear the screen. (Similar to CLS in DOS)
Erases all the text in the current terminal.
cmp : compare two files. See also diff.
cp : copy files.
cp <file> <newfile> cp <file> [<file> ...] <dir>
or
cp file newfile cp file [file ...] dir
The above lines are called a usage summary. The < and > signs mean that you don't actually type out these characters but replace <file> with a file name of your own. These are also sometimes written in italics like, cp file newfile. In rare cases they are written in capitals like, cp FILE NEWFILE. <file> and <dir> are called parameters. Sometimes they are obviously numeric, like a command that takes <ioport>. [Anyone emailing me to ask why typing in literal, <, i, o, p, o, r, t and > characters did not work will get a rude reply.] These are common conventions used to specify the usage of a command. The [ and ] brackets are also not actually typed but mean that the contents between them are optional. The ellipses … mean that <file> can be given repeatedly, and these also are never actually typed. From now on you will be expected to substitute your own parameters by interpreting the usage summary. You can see that the second of the above lines is actually just saying that one or more file names can be listed with a directory name last.
From the above usage summary it is obvious that there are two ways to use the cp command. If the last name is not a directory, then cp copies that file and renames it to the file name given. If the last name is a directory, then cp copies all the files listed into that directory.
The cp command also takes the -R option, allowing it to copy whole directories. The mv command is used to move files and directories. It really just renames a file to a different directory. Note that with cp you should use the option -p and -d with -R to preserve all attributes of a file and properly reproduce symlinks (discussed later). Hence, always use cp -dpR <dir> <newdir> instead of cp -R <dir> <newdir>
There is also cp –update
cpio : archive and extract files.
cron : clock deamon (executes “batch” and “at” commands).
crontab : schedules commands at regular intervals.
crypt : encrypt , decrypt files using altered DES, standard to Unix passwords (restricted distribution). See Also gpg
csh : invoke the C shell.
csplit : split file into several other files.
cu : call up another unix terminal. See Also minicom
cut : cut selected fields from each line of file.
date : displays the time and date (can also change it if you're root). Prints out the current date and time. Similar to DOS but time is used for calculating program execution time.
dd : convert and copy a file.
df : reports space (free, total etc') on all mounted file systems. Stands for disk free and tells you how much free space is left on your system. The available space usually has the units of kilobytes (1024 bytes) (although on some other UNIX systems this will be 512 bytes or 2048 bytes). The right-most column tells the directory (in combination with any directories below that) under which that much space is available.
diff
: compare two files.
dircmp Directory compare. This command compares directories to see if changes have been made between them. You will often want to see where two trees differ (e.g., check for missing files), possibly on different computers. Run man dircmp (that is, dircmp(1)). (This is a System 5 command and is not present on LINUX. You can, however, compare directories with the Midnight Commander, mc). This can be done by diff -r
du
: report disk usage.
Stands for disk usage and prints out the amount of space occupied by a directory. It recurses into any subdirectories and can print only a summary with du -s <directory>. Also try du –max-depth=1 /var and du -x / on a system with /usr and /home on separate partitions.
dmesg Prints a complete log of all messages printed to the screen during the bootup process. This is useful if you blinked when your machine was initializing. These messages might not yet be meaningful, however. echo Prints a message to the terminal. Try echo 'hello there', echo 10*3+2, echo `10*3+2'. The command echo -e allows interpretation of certain backslash sequences, for example echo -e “\a”, which prints a bell, or in other words, beeps the terminal. echo -n does the same without printing the trailing newline. In other words, it does not cause a wrap to the next line after the text is printed. echo -e -n “\b”, prints a back-space character only, which will erase the last character printed.
ed
: line oriented editor.
exit Logs you out. expr <expression> Calculates the numerical expression expression. Most arithmetic operations that you are accustomed to will work. Try expr 5 + 10 '*' 2. Observe how mathematical precedence is obeyed (i.e., the * is worked out before the +).
egrep
: extended version of grep (searches for extended regular expressions).
fgrep
: same as grep, only it interprets patterns as a list of fixed strings.
expr
: evaluate boolean and arithmetic expression.
false
: return nonzero (false) exit status.
file file <filename> Prints out the type of data contained in a file. file portrait.jpg will tell you that portrait.jpg is a JPEG image data, JFIF standard. The command file detects an enormous amount of file types, across every platform. file works by checking whether the first few bytes of a file match certain tell-tale byte sequences. The byte sequences are called magic numbers. Their complete list is stored in /usr/share/magic. [The word ``magic under UNIX normally refers to byte sequences or numbers that have a specific meaning or implication. So-called magic numbers are invented for source code, file formats, and file systems.]
Try on mpeg files and other doc files. Change then extension and try again.
free Prints out available free memory. You will notice two listings: swap space and physical memory. These are contiguous as far as the user is concerned. The swap space is a continuation of your installed memory that exists on disk. It is obviously slow to access but provides the illusion of much more available RAM and avoids the possibility of ever running out of memory (which can be quite fatal). head [-n <lines>] <filename> Prints the first <lines> lines of a file or 10 lines if the -n option is not given. (See also tail below). hostname [<new-name>] With no options, hostname prints the name of your machine, otherwise it sets the name to <new-name>. kbdrate -r <chars-per-second> -d <repeat-delay> Changes the repeat rate of your keys. Most users will like this rate set to kbdrate -r 32 -d 250 which unfortunately is the fastest the PC can go. With GUI interfaces like KDE this has no effect. You need to set the keyboard settings from the KDE control settings menus.
find
: find matching files and run specified programs on them (optional).
finger
: report user information (operates remotely only if a finger server is running on the remote host).
ftp
: (file transfer protocol) a client for FTP servers.
grep
: search files for regular expression matches.
haltsys
: gracefully shutdown sytem (can only be run by root. halt in Linux).
head
: display first 10 lines of a file.
info
System info Pages
info pages contain some excellent reference and tutorial information in hypertext linked format. Type info on its own to go to the top-level menu of the entire info hierarchy. You can also type info <command> for help on many basic commands. Some packages will, however, not have info pages, and other UNIX systems do not support info at all.
info is an interactive program with keys to navigate and search documentation. Inside info, typing H will invoke the help screen from where you can learn more commands.
join
: display the combination (lines with command field) of two fields.
kill
: send a signal to terminate a process.
ksh
: invoke the korn shell.
line
: read a specific line out of a file (shell script usage).
more Displays a long file by stopping at the end of each page. Run the following: ls -l /bin > bin-ls, and then try more bin-ls. The first command creates a file with the contents of the output of ls. This will be a long file because the directory /bin has a great many entries. The second command views the file. Use the space bar to page through the file. When you get bored, just press . You can also try ls -l /bin | more which will do the same thing in one go. less The GNU version of more, but with extra features. On your system, the two commands may be the same. With less, you can use the arrow keys to page up and down through the file.
ln
: create a link to a file/directory.
logname
: gets your login name.
whoami
: which user you are logged in as at the moment. If you, for example, switch to a different user, logname will show the original username you logged in as, and whoami will show the current user.
lpr
: sends a request to printer.
lprint
: prints on local printer.
lpstat
: reports printer status.
lpq
: same as above.
ls
: lists the contents of directory.
ls [-l, –format=long] [-a, –all] <file> <file> …
ls -al
mail
: send and recieve mail.
man
: displays manual pages.
The command man [<section>|-a] <command> displays help on a particular topic and stands for manual. Every command on the entire system is documented in so-named man pages. In the past few years a new format of documentation, called info, has evolved. This is considered the modern way to document commands, but most system documentation is still available only through man. Very few packages are not documented in man however.
Now, man pages are divided into sections, numbered 1 through 9. Section 1 contains all man pages for system commands like the ones you have been using. Sections 2-7 contain information for programmers and the like, which you will probably not have to refer to just yet. Section 8 contains pages specifically for system administration commands. There are some additional sections labeled with letters; other than these, there are no manual pages besides the sections 1 through 9. The sections are … /man1 User programs … /man2 System calls … /man3 Library calls … /man4 Special files … /man5 File formats … /man6 Games … /man7 Miscellaneous … /man8 System administration … /man9 Kernel documentation
xman provides a simple xwindows interface
mesg
: grant or deny permissions to recieve messages from other users using the write command.
mkdir
: create a new directory .
mknod
: build a special file.
more
: display file one page at a time.
mount
: mount a storage device.
mv
: move or rename a file.
news
: display news item from NNTP servers.
nice
: change priorities of processes.
nohup
: run a command after logout (ignores hangup signals).
nroff
: format files for printing.
nslookup
: retrieve information from DNS servers.
od
: displays a file in 8-based octals.
passwd
: create or change login password.
passwd [<username>]
paste
: merge lines of files.
pr
: format and print file.
ps
: reports status of active processes.
pstat
: report system status.
pwcheck
: check /etc/passwd (default) file.
pwd
: display current working directory.
The command pwd stands for present working directory (also called the current directory) and tells what directory you are currently in. Entering pwd gives some output like /home/<username>.
rm
: remove (erase) files or directories (unrecoverable).
To remove (i.e., erase or delete) a file, use the command rm <filename>. To remove a directory, use the command rmdir <dir>. Practice using these two commands. Note that you cannot remove a directory unless it is empty. To remove a directory as well as any contents it might contain, use the command rm -R <dir>. The -R option specifies to dive into any subdirectories of <dir> and delete their contents. The process whereby a command dives into subdirectories of subdirectories of … is called recursion. -R stands for recursively. This is a very dangerous command. Although you may be used to ``undeleting
files on other systems, on UNIX a deleted file is, at best, extremely difficult to recover.
rmdir
: remove an empty directory.
rsh
: invoke Restricted Bourne Shell.
sed
: the stream editor.
set
: assign value to variable.
setenv
: assign value to enviroment variable.
sh
: invoke Bourne shell.
sleep
: suspend execution of a command for a given period.
sort
: sort and merge files.
spell
: find spelling errors.
split
: split file to smaller files.
stty
: set options for a terminal.
su
: spawns a subshell with a different username, requires other user's password, unless you're root.
sum
: compute checksums and number of blocks for files.
tabs
: set tabs on a terminal.
tail
: display last 10 lines of file.
tar
: a simple compression tool that merges multiple files into a single one, originally made to make backing up materials on backup tapes easier.
tee
: create a tee in a pipe.
telnet
: access remote systems using the telnet protocol.
test
: test various expressions and files.
time
: display elapsed time (execution, process, and system times) for a command.
touch
: change time/date stamps of files.
tr
: substitutes sets of characters.
translate
: translates files to different format.
troff
: format files to phototypester.
true
: return zero (true) exit status.
tset
: set terminal mode.
tty
: report a name of a terminal.
umask
: set file-creation mode (permissions) mask.
umount
: unmount a device.
uname
: display the name of the current system.
uniq
: report any duplicate line in a file.
units
: convert numbers from one unit to another.
unzip
: extract files from zip archive.
uptime
: report system activity.
uucp
: copy files between two unix systems (oldie but still beautiful).
uulog
: report uucp status.
uuname
: list uucp sites known to this site.
uudecode
: decode to binary after “uuencode” transmission.
uuencode
: encode binary file for email transmission.
uustat
: report status of uucp or cancel a job.
uupick
: receive public files sent by uuto.
uuto
: send files to another public Unix system.
uux
: execute command to remote Unix system.
vi
: a screen oriented (visual) editor (cool ,but Vim is better).
wall
: sends message to all users (root only).
wait
: await completion of background process.
wc
: count lines, words, bytes etc' in one or more files.
who
: report active users.
whois
: search for user information.
write
: send a message for another user (see mesg).
zip
: archive file or files in zip format.
nohup <command> &
Runs a command in the background, appending any output the command may produce to the file nohup.out in your home directory. nohup has the useful feature that the command will continue to run even after you have logged out. Uses for nohup will become obvious later.
sleep <seconds>
Pauses for <seconds> seconds. See also usleep.
sort <filename>
Prints a file with lines sorted in alphabetical order. Create a file called telephone with each line containing a short telephone book entry. Then type sort telephone, or sort telephone | less and see what happens. sort takes many interesting options to sort in reverse ( sort -r), to eliminate duplicate entries ( sort -u), to ignore leading whitespace ( sort -b), and so on. See the sort(1) for details.
strings [-n <len>] <filename>
Writes out a binary file, but strips any unreadable characters. Readable groups of characters are placed on separate lines. If you have a binary file that you think may contain something interesting but looks completely garbled when viewed normally, use strings to sift out the interesting stuff: try less /bin/cp and then try strings /bin/cp. By default strings does not print sequences smaller than 4. The -n option can alter this limit.
split …
Splits a file into many separate files. This might have been used when a file was too big to be copied onto a floppy disk and needed to be split into, say, 360-KB pieces. Its sister, csplit, can split files along specified lines of text within the file. The commands are seldom used on their own but are very useful within programs that manipulate text.
tac <filename> [<filename> …]
Writes the contents of all the files listed to the screen, reversing the order of the lines--that is, printing the last line of the file first. tac is cat backwards and behaves similarly.
tail [-f] [-n <lines>] <filename>
Prints the last <lines> lines of a file or 10 lines if the -n option is not given. The -f option means to watch the file for lines being appended to the end of it. (See also head above.)
uname
Prints the name of the UNIX operating system you are currently using. In this case, LINUX.
uniq <filename>
Prints a file with duplicate lines deleted. The file must first be sorted.
usleep <microseconds>
Pauses for <microseconds> microseconds (1/1,000,000 of a second).
wc [-c] [-w] [-l] <filename>
Counts the number of bytes (with -c for character), or words (with -w), or lines (with -l) in a file.
whatis <command>
Gives the first line of the man page corresponding to <command>, unless no such page exists, in which case it prints nothing appropriate.
whoami
Prints your login name.
play [-v <volume>] <filename>
Plays linear audio formats out through your sound card. These formats are .8svx, .aiff, .au, .cdr, .cvs, .dat, .gsm, .hcom, .maud, .sf, .smp, .txw, .vms, .voc, .wav, .wve, .raw, .ub, .sb, .uw, .sw, or .ul files. In other words, it plays almost every type of ``basic'' sound file there is: most often this will be a simple Windows .wav file. Specify <volume> in percent.
rec <filename>
Records from your microphone into a file. ( play and rec are from the same package.)
mpg123 <filename>
Plays audio from MPEG files level 1, 2, or 3. Useful options are -b 1024 (for increasing the buffer size to prevent jumping) and --2to1 (down-samples by a factor of 2 for reducing CPU load). MPEG files contain sound and/or video, stored very compactly using digital signal processing techniques that the commercial software industry seems to think are very sophisticated.
cdplay
Plays a regular music CD. cdp is the interactive version.
aumix
Sets your sound card's volume, gain, recording volume, etc. You can use it interactively or just enter aumix -v <volume> to immediately set the volume in percent. Note that this is a dedicated mixer program and is considered to be an application separate from any that play music. Preferably do not set the volume from within a sound-playing application, even if it claims this feature--you have much better control with aumix.
mikmod –interpolate -hq –renice Y <filename>
Plays Mod files. Mod files are a special type of audio format that stores only the duration and pitch of the notes that constitute a song, along with samples of each musical instrument needed to play the song. This makes for high-quality audio with phenomenally small file size. mikmod supports 669, AMF, DSM, FAR, GDM, IMF, IT, MED, MOD, MTM, S3M, STM, STX, ULT, UNI, and XM audio formats--that is, probably every type in existence. Actually, a lot of excellent listening music is available on the Internet in Mod file format. The most common formats are .it, .mod, .s3m, and .xm. [Original .mod files are the product of Commodore-Amiga computers and had only four tracks. Today's 16 (and more) track Mod files are comparable to any recorded music.]
Terminating Commands
Many commands can be terminated with Control C Other process control methods shall be studies in the rocess management topic.
Compressed Files
Files typically contain a lot of data that one can imagine might be represented with a smaller number of bytes. Take for example the letter you typed out. The word ``the was probably repeated many times. You were probably also using lowercase letters most of the time. The file was by far not a completely random set of bytes, and it repeatedly used spaces as well as using some letters more than others. [English text in fact contains, on average, only about 1.3 useful bits (there are eight bits in a byte) of data per byte.]Because of this the file can be compressed to take up less space. Compression involves representing the same data by using a smaller number of bytes, in such a way that the original data can be reconstructed exactly. Such usually involves finding patterns in the data. The command to compress a file is gzip <filename>, which stands for GNU zip. Run gzip on a file in your home directory and then run ls to see what happened. Now, use more to view the compressed file. To uncompress the file use gzip -d <filename>. Now, use more to view the file again. Many files on the system are stored in compressed format. For example, man pages are often stored compressed and are uncompressed automatically when you read them.
You previously used the command cat to view a file. You can use the command zcat to do the same thing with a compressed file. Gzip a file and then type zcat <filename>. You will see that the contents of the file are written to the screen. Generally, when commands and files have a z in them they have something to do with compression–the letter z stands for zip. You can use zcat <filename> | less to view a compressed file proper. You can also use the command zless <filename>, which does the same as zcat <filename> | less. (Note that your less may actually have the functionality of zless combined.)
A new addition to the arsenal is bzip2. This is a compression program very much like gzip, except that it is slower and compresses 20%-30% better. It is useful for compressing files that will be downloaded from the Internet (to reduce the transfer volume). Files that are compressed with bzip2 have an extension .bz2. Note that the improvement in compression depends very much on the type of data being compressed. Sometimes there will be negligible size reduction at the expense of a huge speed penalty, while occasionally it is well worth it. Files that are frequently compressed and uncompressed should never use bzip2
Searching for Files
You can use the command find to search for files. Change to the root directory, and enter find. It will spew out all the files it can see by recursively descending [Goes into each subdirectory and all its subdirectories, and repeats the command find. ] into all subdirectories. In other words, find, when executed from the root directory, prints all the files on the system. find will work for a long time if you enter it as you have–press Ctrl-C to stop it.
Now change back to your home directory and type find again. You will see all your personal files. You can specify a number of options to find to look for specific files.
find -type d
Shows only directories and not the files they contain.
find -type f
Shows only files and not the directories that contain them, even though it will still descend into all directories.
find -name <filename>
Finds only files that have the name <filename>. For instance, find -name '*.c' will find all files that end in a .c extension ( find -name *.c without the quote characters will not work. You will see why later). find -name Mary_Jones.letter will find the file with the name Mary_Jones.letter.
find -size -<size>
Finds only files that have a size larger (for +) or smaller (for -) than <size> kilobytes, or the same as <size> kilobytes if the sign is not specified.
find <directory> [<directory> …]
Starts find in each of the specified directories.
There are many more options for doing just about any type of search for a file. See find(1) for more details (that is, run man 1 find). Look also at the -exec option which causes find to execute a command for each file it finds, for example:
find /usr -type f -exec ls '-al' '{}' ';'
find has the deficiency of actively reading directories to find files. This process is slow, especially when you start from the root directory. An alternative command is locate <filename>. This searches through a previously created database of all the files on the system and hence finds files instantaneously. Its counterpart updatedb updates the database of files used by locate. On some systems, updatedb runs automatically every day at 04h00.
Try these ( updatedb will take several minutes):
updatedb locate rpm locate deb locate passwd locate HOWTO locate README
Searching Within Files
Very often you will want to search through a number of files to find a particular word or phrase, for example, when a number of files contain lists of telephone numbers with people's names and addresses. The command grep does a line-by-line search through a file and prints only those lines that contain a word that you have specified. grep has the command summary:
grep [options] <pattern> <filename> [<filename> …]
[The words word, string, or pattern are used synonymously in this context, basically meaning a short length of letters and-or numbers that you are trying to find matches for. A pattern can also be a string with kinds of wildcards in it that match different characters, as we shall see later.]
Run grep for the word ``the
to display all lines containing it: grep 'the' Mary_Jones.letter. Now try grep 'the' *.letter.
grep -n <pattern> <filename>
shows the line number in the file where the word was found.
grep -<num> <pattern> <filename>
prints out <num> of the lines that came before and after each of the lines in which the word was found.
grep -A <num> <pattern> <filename>
prints out <num> of the lines that came After each of the lines in which the word was found.
grep -B <num> <pattern> <filename>
prints out <num> of the lines that came Before each of the lines in which the word was found.
grep -v <pattern> <filename>
prints out only those lines that do not contain the word you are searching for. [ You may think that the -v option is no longer doing the same kind of thing that grep is advertised to do: i.e., searching for strings. In fact, UNIX commands often suffer from this--they have such versatility that their functionality often overlaps with that of other commands. One actually never stops learning new and nifty ways of doing things hidden in the dark corners of man pages.]
grep -i <pattern> <filename>
does the same as an ordinary grep but is case insensitive.
Copying to MS-DOS and Windows Formatted Floppy Disks
A package, called the mtools package, enables reading and writing to MS-DOS/Windows floppy disks. These are not standard UNIX commands but are packaged with most LINUX distributions. The commands support Windows ``long file name'' floppy disks. Put an MS-DOS disk in your A: drive. Try
mdir A:
touch myfile mcopy myfile A: mdir A:
Note that there is no such thing as an A: disk under LINUX. Only the mtools package understands A: in order to retain familiarity for MS-DOS users. The complete list of commands is
floppyd mcopy mformat mmount mshowfat mattrib mdel minfo mmove mtoolstest mbadblocks mdeltree mkmanifest mpartition mtype mcat mdir mlabel mrd mzip mcd mdu mmd mren xcopy
Entering info mtools will give detailed help. In general, any MS-DOS command, put into lower case with an m prefixed to it, gives the corresponding LINUX command.
Archives and Backups
Never begin any work before you have a fail-safe method of backing it up.
One of the primary activities of a system administrator is to make backups. It is essential never to underestimate the volatility [Ability to evaporate or become chaotic. ] of information in a computer. Backups of data are therefore continually made. A backup is a duplicate of your files that can be used as a replacement should any or all of the computer be destroyed. The idea is that all of the data in a directory [As usual, meaning a directory and all its subdirectories and all the files in those subdirectories, etc. ] are stored in a separate place–often compressed–and can be retrieved in case of an emergency. When we want to store a number of files in this way, it is useful to be able to pack many files into one file so that we can perform operations on that single file only. When many files are packed together into one, this packed file is called an archive. Usually archives have the extension .tar, which stands for tape archive.
To create an archive of a directory, use the tar command:
tar -c -f <filename> <directory>
Create a directory with a few files in it, and run the tar command to back it up. A file of <filename> will be created. Take careful note of any error messages that tar reports. List the file and check that its size is appropriate for the size of the directory you are archiving. You can also use the verify option (see the man page) of the tar command to check the integrity of <filename>. Now remove the directory, and then restore it with the extract option of the tar command:
tar -x -f <filename>
You should see your directory recreated with all its files intact. A nice option to give to tar is -v. This option lists all the files that are being added to or extracted from the archive as they are processed, and is useful for monitoring the progress of archiving. It is obvious that you can call your archive anything you like, however; the common practice is to call it <directory>.tar, which makes it clear to all exactly what it is. Another important option is -p which preserves detailed attribute information of files.
Once you have your .tar file, you would probably want to compress it with gzip. This will create a file <directory>.tar.gz, which is sometimes called <directory>.tgz for brevity.
A second kind of archiving utility is cpio. cpio is actually more powerful than tar, but is considered to be more cryptic to use. The principles of cpio are quite similar and its use is left as an exercise.
The PATH Where Commands Are Searched For
When you type a command at the shell prompt, it has to be read off disk out of one or other directory. On UNIX, all such executable commands are located in one of about four directories. A file is located in the directory tree according to its type, rather than according to what software package it belongs to. For example, a word processor may have its actual executable stored in a directory with all other executables, while its font files are stored in a directory with other fonts from all other packages.
The shell has a procedure for searching for executables when you type them in. If you type in a command with slashes, like /bin/cp, then the shell tries to run the named program, cp, out of the /bin directory. If you just type cp on its own, then it tries to find the cp command in each of the subdirectories of your PATH. To see what your PATH is, just type
echo $PATH
You will see a colon separated list of four or more directories. Note that the current directory . is not listed. It is important that the current directory not be listed for reasons of security. Hence, to execute a command in the current directory, we hence always ./<command>.
To append, for example, a new directory /opt/gnome/bin to your PATH, do
PATH="$PATH:/opt/gnome/bin"
export PATH
LINUX supports the convenience of doing this in one line:
export PATH="$PATH:/opt/gnome/bin"
There is a further command, which, to check whether a command is locatable from the PATH. Sometimes there are two commands of the same name in different directories of the PATH. [This is more often true of Solaris systems than LINUX.] Typing which <command> locates the one that your shell would execute. Try:
which ls
which cp mv rm which which which cranzgots
which is also useful in shell scripts to tell if there is a command at all, and hence check whether a particular package is installed, for example, which netscape
The – Option
If a file name happens to begin with a - then it would be impossible to use that file name as an argument to a command. To overcome this circumstance, most commands take an option –. This option specifies that no more options follow on the command-line–everything else must be treated as a literal file name. For instance
touch – -stupid_file_name rm – -stupid_file_name
References
http://www.one-serve.com/tools/unix_commands.html
http://rute.2038bug.com/node7.html.gz
http://www.ctssn.com/linux/lesson1.html
http://www.comptechdoc.org/os/linux/usersguide/linux_ugbasics.html
http://www.justlinux.com/nhf/Command_Reference
http://www.bioafrica.net/GDElinux/linututorial1.html
http://www.userlocal.com/helpbasic.php
Man Page viewer
http://www.ctssn.com/man/man.cgi?ls
Tutorial
Full List of Commands
http://techpubs.sgi.com/library/tpl/cgi-bin/browse.cgi?db=man&coll=linux&pth=/man1