Unix Fundamentals - Novice Topics | ||||
Home
About Me Contact Computing Dan Maul Modelling Resume |
Contents:
How do I change my UNIX
password?
To change your login password, use the passwd command; type passwd and then hit enter. You will be prompted for your old password and then you will be asked to enter your new password twice. If both occurrences of the new password are not identical (remember that UNIX passwords are case sensitive) then the change will not be successful.
UNIX
file system basics.
The most important part of any computer system is the data that is stored and manipulated by programs. It is the responsibility of the file system to maintain all of this data in an orderly and reliable fashion. As a user, you need not perform any maintenance of the UNIX file system; this is the responsibility of the system administrator(s). However, a basic understanding of the UNIX file system is important to enable an enriched understanding of other UNIX concepts. The concept of a file in everyday life is fairly straight forward; a collection of papers bundled in a folder. Extending this metaphor to computers, a file is a collection of data stored on hard disk, floppy disk, CD or tape (or whatever the media du jour is). A computer file may be an executable program, a spreadsheet, a word processor document, a game, a picture or whatever it may be. In UNIX, the definition of a file is much broader; a file is any source from which data can be read or any target to which data can be written. Therefore, a UNIX file would include those entities described [as a computer file] above but also includes physical devices such as a keyboard or a hard disk drive. Basically, everything in UNIX is viewed as a file. UNIX has three primary types of files; ordinary (or regular) files, directories and special files. An ordinary or regular file are those that contain programs or data; this conforms to the above description of computer files. For example, when you use a text editor to create a document and/or modify a document, the document is stored in an ordinary file. You may then manipulate this file as you choose (modify, save, copy, move, rename, delete and so on). The next important file type is a directory. A directory is a container that is used to store (and organize) other files and directories. You may create, rename and delete directories as you wish with one caveat; a directory may not be deleted while it still contains any files (or directories). A directory does not really contain files but it contains the information UNIX needs to access those files. The third type of file is a special file or a device file which is an internal representation of a physical device. For example, your hard drive has an associated special file that the operating system uses to access that device. To access the hard drive, the OS opens the special file associated with that device and then reads and writes data to the device as if it were a regular file (it's really a little more complicated than that but at a high level this explanation is adequate). Directories are used to organize files into an orderly hierarchical
system. Imagine the confusion that would reign if all of the files on the
network were stored in one flat location (there are tens of thousands of
files)! To avoid this confusion, we group related files into directories.
Directories may themselves contain other directories. A parent directory
is one that contains other directories while a subdirectory is a
directory that resides inside some other directory; a subdirectory
is often referred to as a child directory.
The UNIX file system can be conceptually viewed as an upside-down tree (or simply a tree for those of you versant in computational theory). The file system has a root directory from which all other directories branch; this root directory is name '/' or slash. Figure 1 illustrates the basic layout of the UNIX filesystem.
The root or '/' directory is the parent of all of the other directories. The /usr directory is a subdirectory or child directory of '/'. At the same time, /usr is itself a parent directory for other subdirectories (such as bin local and admin). Each directory (including '/') may contain files as well as other directories. What is meant by the term pathname? [Top] [Contents] One term you will often see bandied about any discussion of file systems is pathname. The term pathname refers to the fully qualified name of a file wich contains location information. The root or '/' directory is very important when specifying pathnames. For example, the explicit path of a file may be /usr/bin/echo. The '/' character has two different meanings here. At the beginning of the file pathname, '/' refers to the root directory while the '/' character within a pathname acts as a field delimiter. In this case, the file's name is echo and it can be found in the bin directory which is a subdirectory of the usr directory which is itself a subdirectory of the '/' (root) directory. An absolute pathname always contains a leading '/'; an absolute pathname is therefore relative to the '/' directory. The pathname /usr/bin/echo is an example of an absolute pathname. A relative pathname specifies a path relative to the current working directory. For example, if our current working directory was /usr/bin then the pathname echo would sufficiently identify this file. When working with directories, a very important concept is the distinction between a relative and an absolute pathname. To illustrate the difference, refer to the sample directory tree in figure 2.
An absolute pathname specifies the file's path relative to '/'. For example, the absolute pathname of the file resume.shtml (from figure 2) would be /home/jhacker/public_html/resume.shtml. The pathname is absolute with respect to the root of the file system (in fact the leading '/' differentiates an absolute path from a relative path). A relative path is the location of a file or directory relative to the
current working directory. For example, if your current working directory
was /home/jhacker and you wanted to refer to the file
hello_world.c
in the projects/new directory, you could use the relative pathname
projects/new/hello_world.c (note the absence of the leading '/').
If your current working directory was
/home/jhacker/projects/new,
you could refer to the hello_world.c file using its name alone.
What is my current working directory and how do I change it? [Top] [Contents] UNIX allows you to designate one directory at a time as your current working directory. The current working directory is the directory in which you currently reside. To determine your current working directory, use the pwd (print working directory) command (advanced UNIX users will recognize the merrits of echo $cwd). To access a file that is in your current working directory you need only specify the filename; the whole path need not be specified (this is of course assuming that '.' is in your search path - more on this later).
Referring to figure 3, if our current working directory was /home/jhacker, then we would be able to refer to the file doit.c by it's name alone (a fullpathname would not be required here). However, to refer to the file index.shtml in the public_html directory, we would need to use either the relative path public_html/index.html or the absolute path /home/jhacker/public_html/index.html. To change your current working directory, use the cd (change directory) command. The general syntax of this command is:
~ >>cd public_html ~/public_html >> pwd /home/jhacker/public_htmlUNIX provides some handy pathname abbreiviations. The first is '..' which refers to the parent directory. If our current directory is /home/jhacker/public_html, typing cd .. would change our working directory to /home/jhacker; it would take us up one level in the file system tree. We can use the '..' abbreiviation twice. Revisiting our previous example, if our current directory was /home/jhacker/public_html, typing cd ../.. would change our current directory to /home. Other directory names can be used with this mechanism as well. If our working directory is /home/jhacker/projects/new and we want to change to the /home/jhacker/bin directory, we could type cd ../../bin. The second handy abbreviation is '.' which refers to the current working directory. For example, if our current directory was /home/jhacker/public_html, the following three specifications would refer to the same file:
resume.shtml ./resume.shtml The last of the three handy abbreviations is '~' which refers to your home directory. For example, if you are logged in as jhacker, the following commands would both take you to your home directory:
cd ~
How do I list my files?
Listing files can be done using the built in ls
command. Without options, ls
simply lists the entries in your current directory. For example, running
ls
in my Using the -l option provides a long listing which includes file permissions,
ownership, size and last modified time along with the file name.
A neat trick is to pipe the output of ls
-alF through more
(more advanced UNIX users will want to use less
instead). The more utility gives you one screen of output at a time. This
is handy if you are listing a directory that contains a large number of
items. To do this type
ls -alF | more
and then hit any key to advance the input.
The options discussed here represent a small subset of those available
for use with ls. The man
pages on the ls command
are actually fairly readable (which is unusual for the man pages). I recommend
that you have a look at them to determine the full range of options available
for use with
ls (RTFM).
How
do I copy files?
To copy a file, us the cp
command. The general syntax is:
One can copy a file [or files] to a different directory. The general
syntax of this usage is:
For example, the command
The wildcard option can be used when copying files; use '*' for the
source_file
specification and specifiy a directory path for the new_file.
For example, to copy the contents of my
perl directory to the scripts
directory, I would type:
How
do I move and/or rename a file?
Moving and renaming a file are really the same thing. Both actions are
performed using the mv command.
The general syntax of this command is as follows:
To move a file or a group of files to another directory, use the following
syntax:
How
do I delete files?
When deleting files, always exercise extreme caution!! Think before
you type!! When a file is deleted (removed) in UNIX it is gone;
you cannot undelete the file like in DOS. The only way to recover
an accidentally deleted file is to talk to your friendly system administrators
and convince them that a.) the file really is important (it is critical
to the performance of your job - we do not restore gif's of binky the cat)
b.) you really do need to have it restored from the backup tapes c.) you
promise not to do it again. Generally, sys admin types are not fond of
doing tape restorations so please be extremely careful. As most of the
backup tapes are stored off site, and as it usually takes at least a day
to get tapes sent in, an accidentally deleted file will be inaccessable
for a little while. Can you afford to have potentially critical files vanish
for a few days?
To delete a file, use the rm
or remove command. The general syntax is as follows:
As with all file operations, wildcard characters
can be used with the
rm
command. For example, if our current working directory
is ~/faq (refer to the above example), typing the command
The rm command also has
a -r option which recursively deletes an entire subtree. I will
not discuss this option here; I encourage users to RTFM for more information
on the use of this option. I would not advise novice UNIX users to use
the -r option at all (if you screw up with this one you can blow
away a lot of data). If you must use the -r option, be sure to use
it with the -i option as well!!
|