100% found this document useful (1 vote)
505 views13 pages

Unix File Attributes AND Permission

The document discusses UNIX file attributes and permissions, describing commands like ls, chmod, chown and chgrp that are used to view and modify permissions on files and directories. It explains how permissions are represented numerically and how commands like chmod use notation like ugo+/-rwx to grant or deny read, write and execute access for users, groups and others. Default permissions for new files can be set using the umask command.

Uploaded by

Yashavanth Tr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
505 views13 pages

Unix File Attributes AND Permission

The document discusses UNIX file attributes and permissions, describing commands like ls, chmod, chown and chgrp that are used to view and modify permissions on files and directories. It explains how permissions are represented numerically and how commands like chmod use notation like ugo+/-rwx to grant or deny read, write and execute access for users, groups and others. Default permissions for new files can be set using the umask command.

Uploaded by

Yashavanth Tr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIX

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

The assignment expression holds the following information.


1.The information about the category of user{User –u, group –g, others –o, all -a}
2.The information about granting or denial of the permission {the operators +, -
and =}
3.The information about the type of permission {read –r, write –w, execute -x}
chmod : Changing file permissions
 The chmod command enables you to modify the permission
on a file. The syntax of the command is as follow:
chmod [ugoa] [ + - = ] [rwx] filename(s)
 The following options are available to the chmod command:
u applies to user
g applies to group
o applies to other
a applies to all (default: not specified any of these options)
= Instructs to add the specified permission and take away all

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

•Relative permission assignment: An expression like u+x


sets the execute permission to the user.
•Absolute permission assignment: The use of the =
operator in the chmod expression assigns or grant only
specified permission and removes all other permissions.
 e.g. Assume that file1 has access permission is –r_ _r_ _r_ _
then
(1) $chmod +w file1
Gives write permission to all i.e. –rw_rw_rw_
(2) $chmod go+r, go-w file1
Gives a read permission to group and others and take away
their write permission.
(3) $chmod go=r, u=rw file1
This removes all existing permission and replaces them with
read permission for group and others and read & writes
permission for owner of the file file1.
(4) $chmod a+w file1 OR $chmod +w file1
Gives write permission to all (owner, group and others)
(5) $chmod a-w file1 OR $chmod –w file1
Take away write permission from all.
(6) You can also specify the permission with octal numbers.
$chmod 744 file1
This would assign the permission -rwxr_ _r_ _ to file1.
(7) $chmod 777 file1
Assign all permission to owner, group and others i.e. –
rwxrwxrwx.
 chmod works with multiple files also. i.e. you can assign the
same set of permissions to a group of files using a single
chmod command.
e.g. $chmod u+x file1 file2 file3

 It is possible to apply the chmod command recursively to all


files and subdirectories. This is done with the –R (recursive)
option and needs only the directory name or the meta-
character * as argument.
e.g. (1) $chmod –R a+x mydir
(2) $chmod –R a+x *
OR
$chmod –R a+x .
chown and chgrp
 Chown command change the ownership of a file or directory.
Syntax :
chown options new-user file(s)
e.g. user1 is owner of file file1. We can change the owner of the
file as follow:
e.g. chown user2 file <enter>
 similarly, chgrp command changes the group owner of a file. The
general syntax is:
chgrp options new-group file(s)
e.g. chgrp bcasem1 file1
 Like chmod, both chown and chgrp also work the –R option to
perform their operations in a recursive manner. All three
commands place no restrictions whatsoever when used by the
super user.
 In Linux, the chown command can only be used by the super
user. A Linux user can use chgrp, but he can use it only for
changing the group to one to which he also belongs.
DEFAULT FILE PERMISSION : umask Command

$umask
022
$

Regular file : 644


Directories file: 755

When you want to change a default permission.

$umask 042
$umask
042
$

Regular file : 624


Directories file: 735

You might also like