0% found this document useful (0 votes)
26 views

BLP Unit 3.4

Uploaded by

a28657798
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

BLP Unit 3.4

Uploaded by

a28657798
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

K. K. Wagh Polytechnic, Nashik.

Program: Information Technology (IF)


Semester: II Scheme: K
Course: Linux Basics Course Code: 312001
Unit-3: File Management in Linux
Topic: File and Directory permissions
Presented by:
Mrs. M. P. Nawarkar
Lecturer in Information Technology
File and Directory permissions
Contents
Course Outcome:
CO-3: Manage files and directories in Linux operating
system.

Theory Learning Outcomes:


TLO3.5 Execute basic file attributes.
TLO3.6 Change file and directory permissions.

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


File and Directory permissions
Contents
Contents:
- Basic file attributes
- ls -l: Listing file attributes
- -d option: Listing directory attributes
- File ownership, File permissions
- chmod: Changing file & directory permission
- Changing file ownership
- chown: Changing file owner
- chgrp: Changing group owner

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


File Attributes

- Each file has characteristics like file name, file type, date (on which file was created), etc.
- These characteristics are referred to as ‘File Attributes’.
- The OS associates these attributes with files.
- In different operating systems files may have different attributes.

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


File Attributes

- Name: File name is the name given to the file.


- Identifier: Identifier is a unique number for a file. It identifies files within the file system. It is
not readable to us, unlike file names.
- Type: Type is another attribute of a file which specifies the type of file such as archive file
(.zip), source code file (.c, .java), .docx file, .txt file, etc.
- Location: Specifies the location of the file on the device (The directory path).
- Size: Specifies the current size of the file (in Kb, Mb, Gb, etc.) and possibly the maximum
allowed size of the file.
- Protection: Specifies information about Access control (Permissions about Who can read,
edit, write, and execute the file.) It provides security to sensitive and private information.
- Time, date, and user identification: This information tells us about the date and time on
which the file was created, last modified, created and modified by which user, etc.

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


ls -l: Listing File Attributes

- – l : known as a long format that displays detailed information about files and
directories(shows permissions).
- Example:
- ls – l
- Here, as you can see the list in long list format.
- Columns above indicate specific things:
- Column 1 indicates information regarding file permission.
- Column 2 indicates the number of links to the file.
- Column 3 & 4 indicates the owner and group information.
- Column 5 indicates size of the file in bytes.
- Column 6 shows the date and time on which the file was recently modified.
- Column 7 shows the file or directory name.

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


ls -ld: Listing Directory Attributes

- ls –l can be used to get the details of directories content. But –d option can be used to
display the details of directories. With ls – ld command, we will see the permissions on the
directory itself, not on its contents.

- Example:
- ls – ld

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


File ownership

- Different users in the operating system have ownership and permission to ensure that the
files are secure.
- In Linux, different users use the system:
i) Root User: It is a superuser who has access to all the directories and files in our system
and it can perform any operation. Only the root user can perform changing of permissions
or ownerships of the files that are not owned by them.
ii) Regular User: These users have limited access to files and directories and can only
modify the files that they own.

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


File Permissions

- Every file and directory in your Linux system has following 3 permissions.

i) Read: This permission gives the authority to open and read a file. Read permission on a
directory gives the ability to lists its content.
ii) Write: The write permission gives the authority to modify the contents of a file. The
write permission on a directory gives the authority to add, remove and rename files stored in
the directory.
iii) Execute: In Windows, an executable program usually has an extension “.exe” and which
you can easily run. In Linux, you cannot run a program unless the execute permission is set.

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


chmod command

- chmod command is used to change the access mode of a file.


- The name is an abbreviation of change mode.
- It states that every file and directory has a set of permissions that control the permissions
like who can read, write or execute the file.
- In this the permissions have three categories: read, write, and execute simultaneously
represented by `r`, `w` and `x`.
- These letters combine together to form a specific permission for a group of users.
- Types of users are- user, group and others.
- Chmod can be operated in two ways:
1. Symbolic or Alphabetical Notation
2. Octal or Absolute Notation

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


Symbolic or Alphabetical Notation

- It uses symbols for assigning permissions to the users.


- There are following symbols for users of three categories.
Option Symbols Meaning
Category u Owner of Files and Directories
g Members of the group belonging to the user
o All other system users
a All the users
Permission r r to assign read permission to a file.
w w to assign write permission to a file.
x x to assign execute permission to a file.
Operations + Assigns the permission
- Removes the permission
= Assigns absolute permission

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


Symbolic or Alphabetical Notation

Syntax:
$chmod<Category><Operation><permission><filename>

Example 1:
$chmod ugo+x abc.txt
Above command assigns the execute permission for user, group and others.
Example 2:
$chmod ugo-r x1.txt
Above command removes read permission for user, group and others.

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


Octal or Absolute Notation

- This method uses a number to specify each set of permissions for the file.
- It assigns permission in three digits.
- First digit assign permission for owner, second digit for group and third for others.
- Digits range is 0 to 7.
- Syntax:
$chmod <Three digit octal number><Filename>
$chmod [u g o ] filename

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


Octal or Absolute Notation

- List of Octal numbers:


Number Assignment
0 No Permission
1 Execute Permission
2 Write Permission
4 Read Permission
5(4+1) Read and Execute Permission
6(4+2) Read and Write Permission
7(4+3) Read, Write and Execute Permission
- Example:
$chmod 750 abc
- Above command assigns all permissions for user, read and execute for group and no
permission for others.

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


‘chgrp’ command
- The `chgrp` command is used to change the group ownership of a file or directory.
- You can set the owner by using “chown” command, and the group by the “chgrp” command.
- First we need to have administrator permission to add or delete groups.
- We can login as root for this purpose or use sudo.
- sudo (Super User DO) command is used as a prefix for some commands that only superusers are
allowed to run.
- Syntax:
- chgrp <Groupname><Filename>
- Example1:
- sudo chgrp Super Demo1.txt
- The above command will change the group of file 'Demo1.txt' to Super.
- Example 2:
- sudo chgrp Super Newdirectory
- The above command will change the group ownership of the 'Newdirectory' folder.

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


‘chown’ command
- The `chown` command, short for “change owner,” is a powerful tool that allows users to
change the owner of files and directories.
- Syntax:
chown <new_owner> <File name>
where
chown: The base command.
new_owner: The new owner of the file.
filename: The file or files for which ownership is to be changed.
- Example:
- sudo chown master file1.txt
- In this instance, the command designates the user “master” as the new owner of the file
`file1.txt`.

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik


Thank you

Presented by: Mrs. M. P. Nawarkar, K. K. Wagh Polytechnic, Nashik

You might also like