-
command shell
-
Briefly, the program which presents you with the UNIX prompt and interprets
whatever commands you enter. The type of shell used at the CS Server is
called bash, the Bourne Again SHell. Use man
bash to learn more. You can modify it's behavior by editing the
file called .bash_profile in your home
directory using an editor such as vi
or vim.
-
environment
-
Briefly, the environment is mainly values which are usually set during
the login procedure which are retained in memory during the entire session
and are used by various UNIX processes (programs) to know various important
things. You can display the current environment with the set and
env commands.
-
file and directory names
-
limit of 14 to 255 characters, depending on type of UNIX
The CS Server has a a limit
of 254 characters
-
Filenames (as with most things in UNIX) are case-sensitive, e.g.
Report1 is not the same file as report1.
-
It is best to use only letters, numbers, hyphens, underscore, or a dash
in a filename. Other characters may cause some problems when the filenames
are entered on the command line because the command
shell assigns a special meaning to a few special characters (< >
& ; ! and | are a few) or the characters may not be printable on the
screen. Filenames with the special shell characters can be typed by escaping
the character by typing a backslash before the character. Other odd filenames
(such as names with spaces) are easiest to handle by surrounding the filename
with double-quotes. For example, rm a\>b or rm "a>b"
will both delete the file a>b.
-
UNIX dir and file name conventions
- standard dirs: public_html, etc, bin, lib, tmp, man
- standard files: .login, .bash_profile, .bash_history, .lessrc, .plan,
.whatever
- while filename extensions are not required as an indication of the
type of file as they are in on e.g. MS-DOS, often used anyway.
Some common UNIX file extensions:
-
.html a file viewable by a World Wide Web Browser like MSIE,
Netscape, or Lynx
-
.Z file compressed with compress; uncompress using the command,
uncompress
-
.z, .gz file compressed with gzip; uncompress with gunzip
-
.tar archive file (collections of many files combined into one file
for easy archiving and distribution) created with tar; untar with
tar xvf
-
.txt text file; view with cat or more
-
.uue Uuencoded file; decode with uudecode
-
.zip zip compressed archive file; unarchive with unzip
-
.hqx Macintosh binhex-encoded file; decode after downloading to
a Mac using binhex.
-
.sit Macintosh Stuffit archive file (may also be binhex-encoded
-- see .hqx)
-
.gif, .jpg, .jpeg, .tif, .xbm, + many more image file
-
.mpg, .mpeg movie file
-
.shar sh archive created using shar; unarchive with sh
-
.c, .h, .o, C source code, header files, object files
-
And many, many more ...
-
file and directory permissions
-
With UNIX every file and directory in
the filesystem can be set for who
can read the file, who can write (or edit) the file and who
can execute (or run) the file.
This is signified by an r (for read), w (for write),
and a x (for execute).
You can see these permissions using the ls
-al command.
These permissions going from left to right...
rwxrwxrwx
...are divided into three groups of rwx...
rwxrwxrwx are the permissions granted for the owner
or user,
rwxrwxrwx are the permissions for the group (e.g.
users),
rwxrwxrwx are the permissions granted for the world
(everyone else).
To the left of the rwxrwxrwx are two names, like smith
and then users.
The first name is the owner of the file(s), and is the username
of who owns the file. The second name is the group that the user
belongs to. There is no listing for world since that is simply everyone
else.
You, the owner or user, have complete control over who can see your
file(s), who can write to your file(s), and who can execute your file(s).
The same is true of directories. This is very similar to the attrib
command of MS-DOS, except that the only person who can modify these
files is the owner.
Of particular note is that all .html files must be readable by
the world, the group and of course yourself, the owner.
The command to effect that is chmod +r *.html.
For more information see chmod or
use the man command during a telnet
session for a more through (and somewhat confusing)
explanation.
-
redirection
-
Redirection can be used when the user wishes for the output of a
command to go to a file rather than to the screen or the input to a command
to come from a file rather than entered by the user at the keyboard. Redirection
is achieved through the use of the < and > (and variations
of these) characters.
-
command > filename
-
command >> filename
-
The output from the UNIX command, command, is saved into the file,
filename. Use > to create a new file and write the the output
to it. If a file with the name filename already exists, a warning
is displayed and the output is not saved (if the environment
variable noclobber is not set, the old file will
be overwritten by the new output without any warning). Use >> to
append the output to an already-existing file.
-
command < filename
-
The UNIX command command will read its input from the contents of
the file filename instead of reading user-entered lines from the
keyboard.
To send to output of a command to another command rather than to a file,
see pipes.
-
pipes
-
The vertical bar, |, is the special pipe character which
may be used to cause the output of one UNIX command to be the input to
a second UNIX command. The | is typed in-between the two commands
on one command line.
| pipes stdout to the second command.
|& pipes stdout and stderr to the second command.
-
Examples:
-
ls -a | wc -l
-
ls creates a list of all the files
in the current directory and sends this list into wc
which displays the number of lines (i.e. filenames) in the list.
To send the output of a command to a file rather than another command,
see redirection.
-
processes
-
Briefly, every UNIX command (program) is actually runs on the machine as
a process. Many commands create more than one process which run
simultaneously. To display of listing of the processes currently running,
use the ps command.
-
wildcard characters
-
The characters * and ? may be used in filenames when entering
UNIX commands to avoid entering multiple filenames or long filenames. *
matches zero or more occurrences of any character. ? matches exactly
one occurrence of any character.
-
For example,
-
ls r*
-
will display the names of all the files in the current directory with names
beginning with r.
-
mv ??? /tmp
-
will move all the files with names exactly three characters long to the
/tmp directory.
-
cd /u/j/jt*/pub*/html*/
-
will change directory to /u/j/jtpolk/public_html/htmlcorner
-
grep include *.?
-
will look for the word include in all files with names that end
with a period followed by a single character (e.g. main.c, constants.h,
report.1).
The * and ? are actually a part of the regular expression
syntax that can be used in filename reference.
-
^
-
This symbol matches the start of a line in a file. e.g. grep
^smith file1 shows any lines which start with the letters 'smith'
in file1.
-
$
-
This symbol matches the end of a line in a file. e.g. grep
zzz$ * shows any lines which end with 'zzz' in all the files in
your current directory.