Professional Documents
Culture Documents
UNIT 3
BASIC FILE ATTRIBUTES
In Unix, there are three main file attributes: read (r), write (w), and execute (x). The read
attribute allows a file to be read, but nothing can be written to or changed in the file. The write
attribute allows a file to be written, but nothing can be written to or changed in the file. The
execute attribute allows a file to be executed, but nothing can be written to or changed in the file.
In Unix-like systems, extended attributes are usually abbreviated as xattr and are usually limited
in size to a value significantly smaller than the maximum file size variants, and Unix, to adjust
the file attributes use the chmod command.0 Unix stores the contents of directories in nodes that
are similar to the nodes used for regular files, but they are specially marked so that they can be
modified only by the operating system. Directories have a full complement of security attributes:
owner, group, and permission bits
Ls command is used to obtain a list of all filenames in the current directory. The output
in UNIX lingo is often referred to as the listing.
Sometimes we combine this option with other options for displaying other attributes,
or ordering the list in a different sequence.
ls look up the files inode to fetch its attributes.
It lists seven attributes of all files in the current directory and they are
The –d option:
Listing Directory Attributes $ls -d This command will not list all subdirectories in the
current directory .
Directories are easily identified in the listing by the first character of the first column,
which here shows d.
The significance of the attributes of a directory differs a good deal from an ordinary file.
To see the attributes of a directory rather than the files contained in it, use ls –ld with
the directory name.
Note that simply using ls –d will not list all subdirectories in the current directory.
Strange though it may seem, ls has no option to list only directories.
Relative Permissions:
Its syntax is: chmod category operation permission filename(s)
chmod chmod only changes the permissions specified in the command line and leaves
the other permissions unchanged.
takes an expression as its argument which contains:
user category (user, group, others)
operation to be performed (assign or remove a permission)
type of permission (read, write, execute)
Category: u – user g – group o – others a - all (ugo)
Operations : + assign - remove = absolute
Permissions: r – read w – write x – execute
Absolute Permissions:
Here, we need not to know the current file permissions. We can set all nine permissions
explicitly.
A string of three octal digits is used as an expression.
The permission can be represented by one octal digit for each category. For each
category, we add octal digits.
If we represent the permissions of each category by one octal digit, this is how the
permission can be represented: Read permission – 4 (octal 100) Write permission – 2
(octal 010) Execute permission – 1 (octal 001)
This makes all the files and subdirectories found in the shell_scripts directory, executable
by all users. When you know the shell meta characters well, you will appreciate that the
doesn‘t match filenames beginning with a dot. The dot is generally a safer but note that
both commands change the permissions of directories also.
Directory Permissions
It is possible that a file can not be accessed even though it has read permission, and can
be removed even when it is write protected. The default permissions of a directory are,
Changing Ownership:
chgrp: This command changes the file‘s group owner. No super user permission is required.
Umask: The umask command in Linux is used to set default permissions for files or
directories the user creates.
The umask command specifies the permissions that the user does not want to be
given out to the newly created file or directory.
umask works by doing a Bitwise AND with the bitwise complement(where the bits
are inverted, i.e. 1 becomes 0 and 0 becomes 1) of the umask.
The bits which are set in the umask value, refer to the permissions, which are not
assigned by default, as these values are subtracted from the maximum permission
for files/directories.
The umask is a four –digit octal number that UNIX uses to determine the file permission for
newly created files
The UNIX system has the following default permission for all the directories
rw-rw-rw-(octal 666)
rwxrwxrwx(octal 777)
Syntax: $umask
Here, the first digit, 0 is called the sticky bit, it is a special security feature.
The next three digits represent the octal values of the umask for a file or directory.
The umask is a four –digit octal number that UNIX uses to determine the file permission
for newly created files
The UNIX system has the following default permission for all the directories
rw-rw-rw-(octal 666)
rwxrwxrwx(octal 777)