
All files in a Unix system can be reached by specifying a path (similar to a relative pathname) starting from the root directory. For example, a file motd in the directory etc in the root directory can be accessed using the name /etc/motd. Pathnames of this form (i.e., starting with the "/") are called absolute pathnames.
|
pwd is a command that prints the absolute pathname of your current working directory. Since you were in your home directory when you typed the command, the output that you see is the absolute pathname of your home directory. Note that the first character in an absolute pathname is a "/". The "/" tells the system to start from the root directory. In contrast, a relative pathname does not start with the "/" character, and hence the system uses the current working directory as the starting point for the pathname. |
Almost all Unix commands that accept file or directory names will work
with absolute and relative pathnames. For instance, you could change directly
to the directory Testdir2 from your home directory. Can you guess
the command to do this?
|
Compare the output to what you got earlier when you typed the command from your home directory. |
|
|
|
Note that the commands fails because the directory is not empty. Can you come up with the command to remove the directory Testdir2 without changing your working directory? |
|
cp is the Unix command for copying files. In the command above, you tell the system to copy the file motd in the directory /etc (note that this is an absolute pathname), to the directory Testdir1 (this is a relative pathname). cp leaves the original file intact. If you list the contents of the directory Testdir1, you'll find that it now has the file motd. You could also use the cp command to make a copy of a file within the same directory. Let us make a backup copy of the file motd that we just copied. We'll call the new copy motd.backup.
The files motd and motd.backup in the directory Testdir1 are now replicas of each other. |
|
The file /etc/motd actually serves a very useful purpose on Unix systems. Unix displays the contents of this file each time you login to the system. It is used by systems administrators to keep users informed of important events. (In fact, motd stands for "message of the day".) The file motd is probably so small that it fits on one screen. If a file is more than one screen in length, more displays the file one screen at a time. It allows you to move to the next screen by pressing the space key. You can press 'q' to quit at any time. To understand how more behaves with a large file, try using it to look at the file /etc/magic. |
|
|
|
Note that the directory Testdir1 no longer contains the file motd. The mv command can also be used to rename files. Let us change the name of the file motd to motd.new.
If a file by the name motd.new already exists, it is overwritten. Let us now delete the file motd.new. Enter the command: rm motd.new |
| Previous | Table of Contents | Continue |