Unix Summary
A Survival Guide
Module Q02cd

Contents
Audience and Objectives
About this document...
When reading this document in a browser, clicking the graphic separator will return you to the Table of Contents
Quick Reference

NOTE: Most concepts are explained in more detail below
the quick reference
Unix Conventions:
- All Unix commands are activated by typing the commands and pressing the
<Enter> key.
- Unix is case-sensitive: commands and file names can be different
if spelled with upper- and lower-case letters. For example, command ls
cannot be capitalized as LS,and file name index.html is different
from Index.Html.
- Spaces are the primary separators in Unix commands. One or more space must
follow each command word, and file names are delimited by spaces. Therefore,
file names may not contain spaces.
The Unix Prompt
To let you know it is ready to accept your commands, Unix displays a"prompt"
on the screen. This prompt can be set to be just about anything. It may be:
- A single character. $ and % are the most popular.
- Your system and login ID, or part of it. For example, orchard:krieg%

Getting and Interpreting File and Directory Listings
Listing a Directory:
- Simple:
- ls
- File:
- ls filename.typ
- All files with the same ending:
- ls *xy123
- All files with the same beginning:
- ls name*
- Files the same except for one letter:
- ls nam?.ending
- All files in a specific directory
- ls /user/jones/public_html/*
- Detailed:
- ls -l
- List hidden files too:
- ls -a
- Send listing to printer:
- ls > lpr
- Putting features together:
- ls -al /user/jones/public_html/*.gif > lpr
Interpreting a Simple Directory Listing:
orchard:krieg% lsMail mailing-lists peg_acpt.uuPEG_ACPT.TXT modflow.doc pegasus.txt TEST msen_mail public_htmldecomout.htm na13he_1.doc science.htm?desrvcri.doc netfind.txt searchou.htmlynx_bookmarks.html nw1 sigmachist.txt pasguide.txt soapmail peg_acpt.txt williams.doc
The Details...
Files are listed by name, in columns. They are in alphabetical order by column.
Notice that since Unix is case-sensitive, files beginning with capital letters
are sorted to the top of the list. Notice also that directories are not distinguished
from files.
Interpreting a Full Listing
(This is an excerpt from a terminal session. Bold shows what
the user typed; Normal shows what the system prints; comments and explanations
are in italics.)
orchard:krieg% ls -l total 286 (total number of disk "blocks" used)drwx------ 2 krieg 512 Jun 7 1995 Mail-rw-rw---- 1 krieg 2050 Feb 1 20:47 PEG_ACPT.TXT-rw-rw---- 1 krieg 49 Feb 5 13:24 TEST-rw-r--r-- 1 krieg 537 Feb 13 14:27 decomout.htm-rw-r----- 1 krieg 16384 Feb 9 13:26 desrvcri.doc-rw-r----- 1 krieg 1075 Nov 12 16:37 lynx_bookmarks.html-rw-r----- 1 krieg 9784 Mar 12 14:33 machist.txtdrwx------ 2 krieg 1024 Mar 19 14:10 maildrwxr-x--x 2 krieg 512 Sep 24 07:10 mailing-lists-rw-r--r-- 1 krieg 66048 Jan 30 18:09 modflow.docdrwx------ 2 krieg 512 Apr 22 1995 msen_mail-rw-r--r-- 1 krieg 64000 Feb 14 14:10 na13he_1.doc-rw-r----- 1 krieg 71779 Feb 9 11:50 netfind.txt-rw-r----- 1 krieg 551 Feb 12 16:47 nw1-rw-r----- 1 krieg 723 Jan 30 18:01 pasguide.txt-rw-r----- 1 krieg 0 Feb 1 20:47 peg_acpt.txt-rw-r----- 1 krieg 4118 Feb 1 20:43 peg_acpt.uu-rw-r----- 1 krieg 599 Feb 5 13:18 pegasus.txtdrwxr-x--x 2 krieg 3584 Mar 16 14:44 public_html-rw-rw-rw- 1 krieg 16663 Dec 6 22:05 science.htm?-rw-r--r-- 1 krieg 544 Feb 13 14:27 searchou.htm-rwx------ 1 krieg 415 Jul 25 1995 sig-rw-r----- 1 krieg 10460 Feb 21 16:41 soap-rw-r----- 1 krieg 8192 Feb 10 16:33 williams.doc-Mode---Links-Owner-------Size-----Date------File Name----
The MODE printed under the -l option contains 10 characters interpreted
as follows. If the first character is:
- d
- entry is a directory;
- -
- entry is a plain file.
The next 9 characters are interpreted as three sets of three bits each.
- The first set refers to owner permissions;
- The next refers to permissions to others in the same user-group;and
- The last refers to all others.
Within each set the three characters indicate permission respectively to read,
to write, or to execute the file as a program. For a directory, "execute"
permission is interpreted to mean permission to search the directory. The permissions
are indicated as follows:
- r
- the file is readable;
- w
- the file is writeable;
- x
- the file is executable;
- -
- the indicated permission is not granted.
The SIZE is listed in bytes. (A byte is enough space to hold one character.)
The DATE is month, day, and time the file was modified(using 24-hour
clock). If the file was modified more than 6 months ago, the ls command will
give the year instead of the time.
The FILE NAME is listed in alphabetical order, though other list orders
can be generated using command modifiers.
For more information about the ls command, when you are using a Unix
machine, type
man ls
to see the manual for this command.

Using "Metacharacters:" File Name Substitution
Unix commands that deal with files allow you to specify files by name, or to
approximate names by using "metacharacters"("wldcards")
that match several file names.
File name substitution can be used with just about any commands that deal with
files: ls, cat, more, chmod, rm, and many others.
- Matching any group of characters:
- * (star, or asterisk) matches any group of letters in the file name
- Matching any single characters:
- ? (question mark) matches any single letter in the file name.
- Matching specific characters:
- [ ] brackets can enclose groups of letters or ranges of letters to
be matched.
Examples:
- more *
- Show contents of all files in the current directory
- ls *.html
- List all files ending with .html
- ls prog1*
- List all files beginning with prog1 regardless of what they end with
- ls *.*
- List all files containing the period (dot) character anywhere in them
- ls chapt?
- List all files beginning with chapt and containing exactly one more
letter. This will match chapt0 chapt1 chaptx
but will not match chapt chapt10 chapt.txt - rm chapt[0123]
- Remove (delete) files matching chapt0 chapt1 chapt2 chapt3
and no others - rm chapt[0-3]
- Same as above - this is just an abbreviation
- ls [a-z]*
- List all files whose first character is a lower-case alphabetic letter.
- ls *[a-df-z]
- List all files ending with any lower-case alphabetic character excepte

Changing Default Directory
Like most operating systems, Unix has a hierarchical directory structure. (See
Background...Directory Structure below.) You can
change the default (working) directory to save the effort of typing the full
"path name." (The path is the list of all directories between the
root and the target directory.)
- Change directory:
- cd directory_name
- Print working directory name:
- pwd
Example:
(This is an excerpt from a terminal session. Bold shows what
the user typed; Normal shows what the system prints; comments and explanations
are in italics.)
orchard:krieg% pwd (Where are we?)/usr/local/users/krieg (My home directory!)orchard:krieg% cd / (Change to the root directory)/ (This system prints the working directory when you change)orchard:krieg% pwd (I print working directory anyway)/orchard:krieg% ls (Check the file listing...)bin dev lost+found sys boot etc mnt tmpbuild export pcfs usrcdrom kadb root varconduit lib sbin vmunixorchard:krieg% cd etc (Change to another directory)/etcorchard:krieg% ls?? inetd.conf rc.nfs... (Listing too long to show all)hosts.equiv rc.ip xinetd.confifconfig rc.local xtaborchard:krieg% cd .. (Change to next directory up)/ (It's the root)orchard:krieg% cd usr (Now we'll work our way back home)/usr orchard:krieg% cd local/usr/localorchard:krieg% ls orchard:krieg% cd users/usr/local/users orchard:krieg% cd krieg/usr/local/users/kriegorchard:krieg% ls (I list my home directory)Mail msen_mail siglynx_bookmarks.html nw1 soapmail pasguide.txtmailing-lists public_html orchard:krieg% cd public_html (Now I change to a subdirectory)/usr/local/users/krieg/public_html orchard:krieg%

Handling Files: Copying, Moving, Deleting, and Renaming
- Copy from default to archive directory
- cp file.txt archive
(file.txt now exists in two directories) - Move from default to archive directory
- mv file.txt archive
(file.txt now exists in only in the archive directory) - Copy from archive to default directory
- cp archive/file.txt
- Copy all files in a directory to default
- copy archive/*
- Remove (Delete) one file
- rm file.txt
- Remove all files in a directory
- rm archive/*
- Delete all files in the current directory whose name begins with the letter
q
- rm q*
- Rename a file.abc to be file.xyz
- mv file.abc file.xyz
- Rename all files ending .abc
- mv *.abc *.xyz
Background Concepts

Unix Disk Concepts
Computers using Unix have access to files stored on one or more disk. Here
are some facts about how Unix handles its disks:
- Everything attached to a Unix computer is considered to be a kind of file:
- Files are a kind of file;
- Directories are a kind of file;
- Disk drives are a kind of file;
- Terminals are a kind of file;
- Modems are a kind of file;
- Even memory is a kind of file!
- Ordinarily, most users don't have to copy from one disk to another. In the
event that you do, you need to be aware that:
- All devices, including all disk drives, are listed in the subdirectory /dev
- You'll need to ask a system administrator or someone familiar with the system you are using, what the names of the different disk drives are - they vary from one system to another.
- If you want to transfer files to a different computer entirely - for example, from a Unix archive computer to the diskette on your own computer - you would use the "file transfer protocol," ftp . (See module NA30c, "How to Get Files Using Internet".)

Directories
A directory is a part of a disk whose files can be handled as a separate
group. What the Macintosh calls "folders"are the "directories"
of Unix. This concept is useful because disks can hold such large numbers of
files that, without some way of organizing them into groups, it would be nearly
impossible to deal with them rationally. Also, directories provide a space where
files can be kept private from other users.

Directory background
- Every computer system has at least one directory: the root directory.
- The root directory can contain a large number of other directories,as well as files.
- A directory contained in another directory is called a subdirectory.
- Subdirectories can contain a large number of other directories,as well as files.
- Unix subdirectories can contain devices such as disk drive sand modems as
well as files.
-
Because of this, directories form a structure like the branches of a tree. This is sometimes called a "hierarchical" structure.

Unix Directory Rules
- On Unix computers, the root is symbolized by a slash at the beginning of
a list of files. For example,
/etc/passwd
means that the directory etc is located in the root directory.
- Unix subdirectories must have names that follow the same rules as Unix files
(see below)
- When they are used in commands, directory names are separatedfrom one another and from file names by the forward slash /character. Ex:
/etc/passwd
In this example, / is the root, etc is a subdirectory,and
passwd is probably the name of a file - but it could be a directory
instead. Unix leaves this ambiguous.
- The complete listing of drive and all the directories needed to reach a file
is called a "path". A long "path"is:
/usr/local/users/krieg/soap - Special directory names:
. is the symbol for the current directory
.. is the symbol for the "parent" directory.The parent of
krieg is users, because krieg is listed (contained) in
users.
/ is the symbol for the "root" directory.

Default Directory
Since we have to type all Unix commands, any way of shortening commands is
helpful. One such technique is by defining a default directory - a (sub)directory
which Unix assumes you want to use. That way, you don't have to type it out
every time you refer to its files. You can think of Unix as always "looking
at"the default directory.
- The default directory can be shown using the pwd command.For example:
orchard:krieg% pwd
/conduit/netscape.com/windows
The default directory is changed by giving the cd command.You can cd
to any directory in the current directory, or if you list the entire path, you
can cd to any directory on the system.
Return to Contents of this document

Unix File Name Rules
Unix file names are restricted by several rules - mainly constraining their
length and the characters they can have in them. Here are the basics:
Parts
- Overall:
- Unix file names can be as long as you like (just about).
- Name:
- Every file must have a name. Names are useful for explaining what the contents
are about. Examples:
a
taxes
budget94
96income
slurp
Characters
- Unix is sensitive to case. ABC.DOC is different fromabc.doc
and from Abc.Doc.
- You can combine letters and numbers in any order. These are all OK:
123abc.xyz
def567.9yz
34.8
- Some special characters are OK to use, but others are not . Generally, the
characters that have a special meaning in Unix commands are not OK
in names.
OK ~ + : , @ = # % ^ _ - . You can have as many periods(dots) in
a name as you like, but if a period is the first letter the file is
considered to be "hidden".)
Not allowed * | \ [ ] : " ' ` < , > ? /{ } space

Other Helpful Unix References
Audience:
This is for people who have at least learned how to turn
on a computer, and need to know how to do just enough with the Unix operating
system to do basic work. (This is relevant to most versions of Unix).
Objectives:
By consulting this reference guide, you will be able
to...
- Understand the concept of hierarchical directories
- Understand the concept of the "directory"
- Identify and change the current directory
- Give legal Unix names to files
- Identify the information given in a Unix directory listing
- Identify the metacharacters used in Unix file commands
- Do directory listings with the following characteristics:
- Normal
- Detailed
- Using metacharacters
- Copy files from one directory to another
- Remove files
- Move files

About this document...
Module Q02cu: Unix Summary: A Survival Guide
- Author:
- Laurence J.
Krieg
- Institution:
- Department of
Computer Information Systems, Washtenaw
Community College
- History:
- Original version: 19 March 1996; Latest update
Friday, 16-Apr-2004 19:54:36 EDT
- Copyright:
- Copyright © 1996, 2004 Laurence J. Krieg, Washtenaw
Community College
Instructors: You may point to this file in your Web-based materials.
Students: you may make a copy for your personal use.
All other uses: contact the author, Laurence
J. Krieg for permission.