You are on page 1of 7

MODULE 03 BASIC FLE ATTRIBUTES

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

The Ls COMMAND WITH OPTION

ls –l :Listing file attributes

 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

Dept of CSE, BrCE 1


MODULE 03 BASIC FLE ATTRIBUTES

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.

File Permissions: The command can be used in two ways:


 In a relative manner by specifying the changes to the current permissions
 In an absolute manner by specifying the final permissions

Dept of CSE, BrCE 2


MODULE 03 BASIC FLE ATTRIBUTES

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)

Dept of CSE, BrCE 3


MODULE 03 BASIC FLE ATTRIBUTES

Using chmod Recursively:

 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,

Dept of CSE, BrCE 4


MODULE 03 BASIC FLE ATTRIBUTES

Changing Ownership:

 The chown command changes the ownership of a file


 Syntax :$chown user filelist
 On other systems, only the owner can change both
 The super user,root,has tha unrestricted capability to change the ownership of any file
But normal users can change only owner of files they own

chown: Changing ownership requires super user permission, so use a command

Dept of CSE, BrCE 5


MODULE 03 BASIC FLE ATTRIBUTES

Changing Group Ownership

 The chgrp command change the group ownership of a file.


 Sytax: $chgrp group filelist

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.

How does the umask command work?

 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.

Dept of CSE, BrCE 6


MODULE 03 BASIC FLE ATTRIBUTES

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)

Dept of CSE, BrCE 7

You might also like