Unix File Attributes AND Permission
Unix File Attributes AND Permission
FILE ATTRIBUTES
AND
PERMISSION
ls (list) command
It displays files and directories in current working directory (if not specified).
syntax:
ls [options] argument-list
There are various options used with ls command:
Option Description
-x
Display multi-column output (sort line by line)
-F
Marks executables with *, directories with / and symbolic links with @
-a
shows all files including ., .. and those beginning with dot.
-A
shows all files and those beginning with dot but excluding . and ..
-R
Recursive listing of all files in subdirectories.
-L
Lists all files pointed to by symbolic links.
-l
Long listing showing 7 attributes of a file.
-n
Displays numeric user-id and GUID instead of their names (use with –l option).
Option Description
-t Sorts by last modification time.
-lt Displays listing sorted by last modification time.
-u
Sorts by last access time.
-lut
Displays and sorts by last access time.
-i
Shows inode number.
-r
Sorts files in reverse order.
ls –l gives long listing or detailed information about files or
directories.
-rw-r- -r-- 1 root root 4174 Jan 12 10:45 chap1
The first column shows the type and permission associated
with each file. In this column, the first character indicates the
file type. It has any of the following characters:
Character Meaning
• - Indicates ordinary files
• d Indicates directory files
• c Character special files
• b block special files
• l link file
Then, you see a series of characters that can take the values
r, w, x and –(hyphen) for owner, group and others (three
character for each). In the Unix system, a file can have three
types of permission – read, write and execute. –(hyphen)
indicates that permission is denied.
The second column indicates the number of links(alias)
associated with the file. This is actually the number of filenames
maintained by the system of that file.
The third column shows the owner of the files. When you create
a file, you automatically become its owner.
The fourth column shows the group of owner. When the system
administrator opens user account, he simultaneously assigns the
user to some group.
The fifth column shows the size of file in bytes.
The sixth column indicates the last modification time and date of
the file.
The last column shows the name of the file/directory.
CHANGING THE FILE PERMISSION
•The chmod command is used to change the permission of a file after its creation.
Syntax:
$chmod assignement_expression filename
others, if present.
+ Gives specified permission.
- Takes away specified permission.
r read permission
w write permission
x execute permission
How file permissions are assigned
File permissions, in UNIX, are assigned numerical values from
0 to 7. Individually however they have the following values:
Read permission :4
Write permission :2
Execute permission : 1
Thus, for a file that has a permission field like -rwxrwxrwx, the
permissions are said to be 777(4+2+1) for the owner, group
and others. Similarly, a file with permissions
–rw_rw_rw_ is said to have 666 permission.
A zero (0) value in the permission field is treated as a
complete denied (removal) of the read, write and execute
permission for all (owner, group and others)
RELATIVE AND ABSOLUTE PERMISSION ASSIGNMENT
$umask
022
$
$umask 042
$umask
042
$