|Lesson 2|| File attributes and access permissions|
|Objective||Use the ls Command and its options to list File Ownership and Permissions Information.|
Use ls Command and Options
list File Ownership and Permissions Information
For determining access to a file or directory (or any other resource managed like a file, which under UNIX means essentially everything), the following attributes are crucial:
- Every file has an owner
- Every file has a group.
Every file has a set of access permissions that regulate access to the file on the owner, group, and "everyone" levels.
The interpretation of these access permissions varies according to the type of file (in other words, the permissions may mean something different for a file, directory, or device).
Throughout this course, we will use the term file
instead of file or directory
or other resource
. The ls command with the –alg option lists the files in the current directory, showing the permissions, the owner, and the group of the files. The –a option is necessary to see the "hidden" files whose names begin with a dot. The output takes the following form:
PERMISSIONS LINKS OWNER GROUP SIZE MODTIME NAME
so that, for example, the list
-rw-r--r-- 1 jeremy math 304363 Apr 7 13:21
describes a file with:
- Permissions -rw-r--r--
- One link
- Owner jeremy
- Group math
- Size 304363 bytes
- Modified on April 7 at 1:21 p.m.
- Named Template.gz
We will discuss permissions later in this module and the LINK field later in this course. To see the owner and group of a directory, use
ls –ldg directory_name
because, without the –d option, the ls command will list the directory contents instead of the directory itself.
Displaying file ownership
To display a file's user and group ownership, use the long form of the ls command by including the -l option.
For Solaris use -lg.
$ ls -l
-rwxr-xr-x 1 root system 120 Mar 12 09:32 bronze
-r--r--r-- 1 chavez chem 84 Feb 28 21:43 gold
-rw-rw-r-- 1 chavez physics 12842 Oct 24 12:04 platinum
-rw------- 1 harvey physics 512 Jan 2 16:10 silver
Columns three and four display the user and group owners for the listed files. For example, we can see that the file bronze is owned by user root and group system. The next two files are both owned by user chavez, but they have different group owners; gold is owned by group chem, while platinum is owned by group physics. The last file, silver, is owned by user harvey and group physics.
Who owns new files?
When a new file is created, its user owner is the user who creates it. On most Unix systems, the group owner is the current* group of the user who creates the file. However, on BSD-style systems, the group owner is the same as the group owner of the directory in which the file is created. Of the versions we are considering, FreeBSD and Tru64 Unix operate in the second manner by default. Most current Unix versions, including all of those we are considering, allow a system to selectively use BSD-style group inheritance from the directory group ownership by setting the set group ID (setgid) attribute on the directory.
File Attributes - Quiz
Unix System Administration
The file owner is typically the user who created the file. You can change permissions only on files you own.
A group allows an arbitrary set of users to share files. When a user is a member of the file's group, the user will have that file's group permissions.