Go to the previous, next section.
The command ls (with various switches) will display different items of a file's status. There are many pieces of information located in a file's status. For instance, to view a file's last modification date, do an ls -l on the file. Here is what ls -l returns on our example file `foo':
-rw-r--r-- 1 tot 2437 Sep 8 15:59 foo
This file has been modified on September 8, of the current year (if it is a previous year, the time will be replaced with the year), at 15:59 hours (3:59pm).
To view a file's `last access' date, do a ls -lu on file foo:
-rw-r--r-- 1 tot 2437 Sep 8 16:11 foo
Here, you can see the last access date is September 8, at 16:11 hours. With the ls -l command, you can also obtain the file's permissions. These permissions determine who can read, write and/or execute a given unix file. To understand a file's permissions, you must first understand the concept of owner, group, and other. The owner of a file is usually the person who created it (although it may be changed). The group ownership of a file is a collection of users who group own your file. Finally, other is any other user on the system.
The reason unix has all three is because you may wish to give only the owner (generally yourself) the ability to read and write your file, while allowing the group to only read it, and the rest of the computer's user community, no access to the file at all. So, with a few commands you can protect your files reading, writing, and execution policies between three different domains (owner, group, and other).
When you view the output from a ls -l, you will notice on the far left, there will be dashes and letters. This is the 9-bit access control field of a file's status. The first three bits (starting from the left) represent the owner, the next three (middle) represent the group, and the last three (on the right) represent all others. Moreover, the `r' stands for read, `w' for write, and `x' for execute. So as you can see from doing a ls -lg on foo, produces:
-rw-r--r-- 1 tot staff 2437 Sep 8 15:59 foo
Here, tot (the owner), has read and write privileges, staff (the group) has read privileges, and all others also have read privileges. Consider the following output:
-rwxr-x--x 1 tot staff 2437 Sep 8 15:59 foo
In this case, tot (the owner), has read, write, and execute privileges. The group staff, has read and execute privileges, and all others can only execute it.
A few more words on file status. The `1', just to the left of tot in the above output, shows how many links the file foo has. These links refer to hard links, since a symbolic link really has no explicit association to a file. If you do a ls -l on a symbolic link called say, `boo', pointing to file `foo', it would look like:
lrwxrwxrwx 1 tot staff 3 Sep 8 17:10 boo -> foo
Notice, the `l' (ell) on the far left of the 9-bit permissions field. This signifies, that the file `boo' is a symbolic link. Lastly, where you see the 2437 in the following output from ls -lg:
-rw-r--r-- 1 tot staff 2437 Sep 8 15:59 foo
this is how many bytes the file is using.
There are a few more file status items that I will not discuss here;
however if you wish more information on this, you may want to do a man
on ls
. (man ls)
Go to the previous, next section.