You Are Here
REMEMBER: If you are used to Microsoft products, including DOS, then
note that Unix is case sensitive. Password is not the same as
passWord or PASSWORD. If you cannot find a file (and you're
sure it's there), look at what you're typing. You may have
accidently hit the caps lock key, or have made the first
character a capital letter.
Before viewing files or directories in Unix, it is best to know exactly
where you are. The command to find this information is pwd. PWD
is short for present working directory. If you type in pwd
at the command prompt, you will see something like this:
1985UI ~$ The command prompt of computer 1985UI.
1985UI ~$pwd You typed in 'pwd'
/usr/trip/log/ You are in the directory log,
which is in the located in the
directory trip, which is
in the directory usr. Remember,
anything above the last directory is
root.
The pwd command is very useful, especially if you are used to MS-DOS
and its inclusion of the complete path in the command prompt.
What's In Here?
Now that you know where you are, you can use the ls command to find out
what files and subdirectories are located in here with you. If you use ls by
itself, UNIX assumes you want to list everything in your present working
directory. A quick example for you:
1985UI ~$ The command prompt
1985UI ~$ls You typed in 'ls'
access_log error_log These are the files and subdirectories
referer_log trip_log that are located in your current location.
cgi_bin perl
As you can see, ls is akin to the DOS command dir. Just as in DOS,
if you wanted to see what files were located in /usr/trip/, you could type
the following at the command prompt:
In DOS: dir c:\usr\trip
In UNIX: ls /usr/trip/
You would get a simple list of the files and subdirectories. If you were located
deep inside a nest of directories and wanted to see what files were located in
the root directory, you can just type ls / to view what's there.
I Want More Information
Just as in DOS, you can get a more detailed listing by adding 'arguments'. Let
us say that we would like to know more about what is located in the directory
/usr/trip/. All you have to do is add '-l' (dash and L) to the ls command.
For example:
1985UI ~$ls -l /usr/trip/ You typed in 'ls -l /usr/trip/'
Total 10 There are 10 items in this directory (3 hidden)
-rwxrwxrwx root 15233 Jan 08 15:33 access_log
drwxrwxr-x root 8 Jan 01 2000 cgi_bin
-rwxrwxrwx root 1237 Jan 08 15:33 error_log
drwxrwxr-x root 8 Jan 01 2000 perl
-rwxrwxrwx root 133 Jan 08 15:33 referer_log
lrwxrwxr-x root 7 Jan 08 2000 root ->
-rwxrwxrwx root 5211 Jan 08 15:33 trip_log
That's a lot of information! We will dissect the first line for access_log.
The first set of cryptic letters, -rwxrwxrwx, lists the file attributes, or
the read, write and execution status of the file or directory. We will break
this line of alphabet soup down into the following format: ABBBCCCDDD.
A The first character shows what kind of file this is. If this character is a
'-', then it is a normal file. If the first character is a 'd', then
this is a directory. Note that cgi-bin is a directory. If the first
character is an 'l', then the item is a link, or shortcut, to another
directory. Note that root is a link.
BBB The next three characters show the read, write and execute permissions for
the files owner. If the owner had permission to read and execute
the file, but did not have permission to write to this file, a '-' would
replace the middle character (r-x).
CCC The next three characters show the read, write and execute permissions for
the files group. If the group had permission to read and write to
the file, but did not have permission to execute this file, a '-' would
replace the last character (rw-).
DDD The next three characters show the read, write and execute permissions for
everyone else. If a user wasn't the owner or in a group that had
permission to read, write or execute the file, a '-' would replace all
three characters (---). If the owner of the file wanted everyone to be
able to read the file, the last 3 characters would be 'r--'.
After the file attributes, you see the word root. This is the name of the
owner of this file. If Jericho owned the file, root would be replaced with
jericho.
Following the owner's name is the size of the file in bytes. In our example,
access_log is a little over 15 kilobytes in size.
Now we can easily see that the file was created or modified on January 8th at 3:33pm.
In the case of directories, it is common for the time to be replaced with the year the
directory was created.
Now we are at the actual name of the file, directory or link. This may seem a little
backwards from those who are used to MS-DOS commands. Here, you should note the link
root on line number 6. The little '->' is commonly used to indicate that the
file is a link.
Now, remember that there were 10 files in the directory /usr/trip. How can you see
these invisible files? Just add the argument -a for all. Note that you can
chain the arguments together:
1985UI ~$ls -la /usr/trip/ You typed in 'ls -la /usr/trip/' (long list, all)
Total 10 There are 10 items in this directory
drwxr-xr-x root 8 Jan 01 2000 .
drwxr-xr-x root 8 Jan 01 2000 ..
-rwxrwxrwx root 15233 Jan 08 15:33 .logconf
-rwxrwxrwx root 15233 Jan 08 15:33 access_log
drwxrwxr-x root 8 Jan 01 2000 cgi_bin
-rwxrwxrwx root 1237 Jan 08 15:33 error_log
drwxrwxr-x root 8 Jan 01 2000 perl
-rwxrwxrwx root 133 Jan 08 15:33 referer_log
lrwxrwxr-x root 7 Jan 08 2000 root ->
-rwxrwxrwx root 5211 Jan 08 15:33 trip_log
Notice three new directories appeared. In Unix, control and configuration files are
called Dot files. The ls command, by default, hides these files because they're
not used by the user on a regular basis. This helps to unclutter the display when
listing files.
The .logconf file is just a configuration file. In this case, it sets the parameters
for the trip_log program. Normally configuration files are edited for your particular
computer and requirements using a text editor such as vi.
The weird directories called '.' and '..' may be unexpected, even though they do appear
in MS-DOS. The '.' appears in every directory; it just means the current directory. If you
were to type in ls and ls . you would get the same output (a simple listing
of the current directory). The '..' directory appears in every directory except for the
root directory. The '..' just means 'the directory immediately above the one I am
in now'. In MS-DOS, you can use dir .. to see the directory contents of the
directory just above the current one, just as you can type in ls ..
For example:
1985UI ~$ls .. You are in /usr/trip, and you typed in ls ..'
Total 3 There are 3 items in the directory /usr. 2 are hidden.
trip The only things in the directory /usr is a directory
called trip and the two hidden directories (the .
and the ..)
I Want To Go Somewhere Else
The command to change the directory you're in is the same as in MS-DOS: cd. To change
your current directory to a different one:
1985UI ~$cd /home/rpickle You are in /usr/trip, and you typed in where
you want to go: cd /home/rpickle
1985UI ~$pwd You're in the new directory. Type in pwd if you
want to verify it.
/home/rpickle There you have it: you're in the correct directory.
Is There Another Way To Go Somewhere Else?
Yes, there is another way. The commands are called pushd and popd. These
commands make use of the computer stack.
A stack is a computer term for a type of data storage. You can equate a stack to a pile
of reports on your desk. You can work on a report until the boss tells you she needs a
different report worked on. You therefore remove the other report from the stack and place
the one you were working with on top of the stack of reports. You can work on the
important report until you're done, after which you take the earlier report off of the top
of the stack and continue working on it.
If you were working in directory /usr/trip, and needed to pop on over to directory
/usr/config to work on something quickly, you would just type in pushd and
the directory name and path. This puts your current directory on the top of the data
stack for later use, and places you in the new directory. After completing whatever it was
you needed to do, you would then just type in popd by itself, because it would 'pop'
you back in the last directory you were in before this one, because that's the one
at the top of the stack.
Is It Absolutely Relative?
Before we conclude this section of the Newbie's Guide to Unix, we should discuss the
concepts of relative and absolute paths. Relative paths are (surprise)
relative to where you are right now. For example, looking at /usr/trip:
1985UI ~$pwd You type in pwd
/usr/trip/ You're in /usr/trip
1985UI ~$ls -l You typed in 'ls -l'
Total 10 There are 10 items in this directory (3 hidden)
-rwxrwxrwx root 15233 Jan 08 15:33 access_log
drwxrwxr-x root 8 Jan 01 2000 cgi_bin
-rwxrwxrwx root 1237 Jan 08 15:33 error_log
drwxrwxr-x root 8 Jan 01 2000 perl
-rwxrwxrwx root 133 Jan 08 15:33 referer_log
lrwxrwxr-x root 7 Jan 08 2000 root ->
-rwxrwxrwx root 5211 Jan 08 15:33 trip_log
Notice that there's a subdirectory here called perl. If you needed to go into this
directory, you could type cd perl. This is a relative path, because it is
relative to the directory we are in. Unix knows that you want to go to a subdirectory that
is in the same directory you are in now. If you wanted to jump out to /home/rpickle,
you would type cd /home/rpickle. This is an absolute path; it gives the complete
path from root to the desired directory. Note that all relative paths do not use a beginning
'/', and absolute paths use one. This will cause some confusion to newbies. If you are trying
to go to a subdirectory that you know exists, check to see if you've used a '/' where you
shouldn't have.
In the next lesson, we will cover the concept of file ownership, which was touched
on when we discussed the ls -l long listing.
Rancid Pickle
(c) copyright 2000 attrition.org