0% found this document useful (0 votes)
10 views7 pages

Chmod

Uploaded by

mahatonikita00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

Chmod

Uploaded by

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

File attributes File and directory attributes listing and very brief idea about the attributes, File

ownership, File permissions,

Changing file permissions – relative permission & absolute permission, Changing file ownership,
Changing group ownership, File system and inodes, Hard link, Soft link, Significance of file attribute
for directory, Default permissions of file and directory and using umask, Listing of modification and
access time, Time stamp changing (touch), File locating (find).

Basic File Attributes:

The UNIX file system allows the user to access other files not belonging to them and without
infringing on security. A file has a number of attributes (properties) that are stored in the
inode.

COMMAND to display file attributes:

,•ls–l to display file attributes (properties)

•Listing of a specific directory

•Ownership and group ownership

•Different file permissions

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 file’s inode to fetch its attributes. It lists seven attributes of all files
in the current directory and they are:

•(1)File type and Permissions

1
File type. There are three possibilities for the type. It can either be a
regular file (–), a directory (d) or a link (i).

•(ii)Links

•(iii)Ownership

•(iv)Group ownership

•(v)File size

•(vi)Last Modification date and time

•(vii)File name

The file type and its permissions are associated with each file.

Links indicate the number of file names maintained by the system. This does not mean that
there are so many copies of the file.

File is created by the owner.

Every user is attached to a group owner.

File size in bytes is displayed.

Last modification time is the next field. If you change only the permissions or ownership of
the file, the modification time remains unchanged.

In the last field, it displays the file name.

COMMAND NAME: ls

NAME

ls - list directory contents

SYNOPSIS

ls [OPTION]... [FILE]...

-a will list all the hidden files as well as the normal ones

-i, --inode

print the index number of each file

-r, --reverse

reverse order while sorting

-R, --recursive

2
list subdirectories recursively

-s, --size print the allocated size of each file, in blocks

-S sort by file size, largest first

-t sort by modification time, newest first

-1 list one file per line.

--block-size=SIZE

with -l, scale sizes by SIZE when printing them; e.g., '--block-size=M';

The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units

are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

Kilo(K), mega(M), giga(G), tera(T), peta(P),


exa(E), zetta(Z),yolta(Y).

Example:To create a hidden file use . with filename

debasis@LAPTOP-H3N6JCNE:~/BCA/bca/Example$ vi .a.txt

To display hidden files use ls -a or ls -la command:

debasis@LAPTOP-H3N6JCNE:~/BCA/bca/Example$ ls -la

total 12

-rw--w--w- 1 debasis debasis 15 Jan 15 20:39 .a.txt

-rw-r--r-- 1 debasis debasis 10240 Jan 13 12:14 archiveEx.tar

File Permissions:
Chmod (change mode): permission sets
Chmod (change mode) is one of the most frequently used commands in unix or
linux operating system. The chmod command is used to change the file or
directory access permissions.
To know about the access permissions of a file or directory, use the ls -l
command as shown below:

3
$ ls -l filename.sh
-rwx-rw-r—1 student student 94 Oct 4 03:12 filename.sh

The syntax of chmod command is:

chmod [options] mode/permissions filename

permissions defines the permissions for the owner of the file (the "user"),
members of the group who owns the file (the "group"), and anyone else
("others").

Changing File Permissions:


The chmod command enables you to change the permissions on a file. You must
be superuser or the owner of a file or directory to change its permissions.

You can use the chmod command to set permissions in either of two modes:

 Relative/Symbolic permissions – Use combinations of letters and symbols


to add or remove permissions(with symbols (alphanumeric characters)).In
relative permissions chmod only changes the permissions in the command
line and leaves the other permissions unchanged.

 Absolute permissions – Use numbers to represent file permissions (the


method most commonly used to set permissions). When you change
permissions by using the absolute mode, you represent permissions for
each triplet by an octal mode number(with octal numbers (the
digits 0 through 7).

Relative/Symbolic Mode Representation of Permissions:

The following symbols are used to represent the users, groups and others:

 u : User
 g : Group
 o : Others
 a : All (user, group and others)

The following symbols represent the permissions:

 r : read

4
 w : write
 x : execute

The following symbols represent the permissions grant or revoke:

 + : Additional permissions. Selected permissions are added.


 - : Revoke the permissions. Selected permissions are revoked.
 = : Specific permissions. Only selected permissions are assigned.

Let's say you are the owner of a file named filename.txt, and
you want to set its permissions so that:

1. the user can read, write, and


execute it;

2. members of your group can read


and execute it; and

3. others may only read it.

This command will do the trick:

$ Chmod ugo+rwx filename.txt::w

$ Chmod ug-wx filename.txt


chmod u=rwx,g=rx,o=r filename.txt

This example uses symbolic permissions notation. The letters u, g,


and o stand for "user", "group", and "other". The equals sign
("=") means "set the permissions exactly like this," and the letters
"r", "w", and "x" stand for "read", "write", and "execute",
respectively. The commas separate the different classes of
permissions, and there are no spaces in between them.

Absolute Mode Representation of Permissions:


Here is the equivalent command using octal permissions notation:

5
chmod 754 filename.txt

Here the digits 7, 5, and 4 each individually represent the


permissions for the user, group, and others, in that order. Each digit
is a combination of the numbers 4, 2, 1, and 0:

 7 stands for "read,write and

execute"(1 1 1 =7)

 6 stands for(read,write)

(110=6)

 4 stands for “read”(100=4)

 2 stands for "write",(010=2)

 1 stands for "execute"(001=1),

and

 0 stands for "no

permission."(000=0)

So 7 is the combination of permissions 4+2+1 (read, write, and


execute), 5 is 4+0+1 (read, no write, and execute),
and 4 is 4+0+0 (read, no write, and no execute).

To make a file and run it, use the following commands :

$chmod u+x filename (set file as executable)

$./filename (To execute shell program or Run)

6
UNIX/Linux File Ownership:
Every Linux system have three types of owner:

1. User: A user is the one who created the file. By default, whosoever,
creates the file becomes the owner of the file. A user can create,
delete, or modify the file.
2. Group: A group can contain multiple users. All the users belonging to
a group have same access permission for a file.
3. Other: Any one who has access to the file other
than user and group comes in the category of other. Other has
neither created the file nor is a group member.

COMMAND NAME : id

id - print real and effective user and group IDs

debasis@LAPTOP-H3N6JCNE:~$ id

output:

uid=1000(debasis) gid=1000(debasis)
groups=1000(debasis),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),
29(audio),30(dip),44(video),46(plugdev),117(netdev)

You might also like