Linux-Ubuntu/C2/Linux-File-Ownership-and-Permissions/English
Title of the Script: Linux File Ownership and Permissions
Authors: Edupyramids
Keywords: Linux, File Ownership, File Permissions, chown, chmod, chgrp, Inodes, Hard link, Soft link, Symbolic link, Terminal commands, Linux file system, edupyramids, video tutorial.
| Visual Cue | Narration |
| Slide 1
Title Slide |
Welcome to this spoken tutorial on Linux File Ownership and Permissions. |
| Slide 2
Learning Objectives |
In this tutorial, we will learn to:
|
| Slide 3
System Requirements |
To record this tutorial, I am using:
Ubuntu O S version 24 point 04 |
| Slide 4
Pre-requisites |
To follow this tutorial,
learners should have Ubuntu version 24 point 04. For the prerequisite Linux tutorials please visit this website. |
| Slide 5
Code Files The following code file is required to practice this tutorial.
This file is provided in the Code Files link of this tutorial page. |
The following code files are required to practice this tutorial.
These files are provided in the Code Files link of this tutorial page. |
| Slide 6
File Attributes File-attributes.png |
File attributes are properties linked to a file.
Attributes define ownership and permissions. They include file type, size, and time details. They show who owns the file and who can access it. File attributes are viewed using the l s hyphen l command. |
| Switch to terminal
Type cd Desktop/file-attr Press Enter Highlight the output /Desktop/file-attr$d |
Let us move to the code files folder file hyphen attr
provided along with the tutorial. I have downloaded it to my Desktop. Now switch to the terminal. Type c d space Desktop slash file hyphen a t t r and press Enter. Notice that the prompt path has changed. |
| Type
ls -l example1 and press Enter Highlight the output point to the first character |
Let us type
l s space hyphen l space example1 and press Enter. Observe the output. The first character in the output shows the file type. If it is a hyphen, it denotes a regular file. If it is l , it denotes a symbolic link. If it is d, it denotes a directory. We see a hyphen here since example1 is a regular file. |
| highlight the next 9 characters | The next nine characters show permissions.
First three denote owner permissions, Next three denote group permissions, Last three denote others permissions. Here r, w, x means read, write and execute. |
| Highlight example1
highlight spoken |
Here we can see that the owner of the file example1 is spoken. |
| Slide 7
chown command
|
* The c h own command changes the ownership of a file or directory.
|
| Now we will look at some examples. | |
| Type
sudo chown demo example1 press Enter. |
Let us change the owner of the file example1.
Type sudo space ch own space demo space example1 press Enter. |
| Type the sudo password if prompted. | Type the sudo password if prompted again. |
| Type
ls -l example1 press Enter Highlight the output |
Let us see the file attributes of example1.
Type l s space hyphen l space example1 and press Enter. Observe that the new owner of the file is demo. This works only if the user named demo exists. Otherwise we will get an invalid user error. If the user does not exist, please create the user. |
| Type
mkdir pond and press Enter. Type the command ls -l press Enter Highlight the pond directory details highlight examples 1 to 5. |
Now, we will see how to change the owner of a directory.
For that we will create a directory first. Type m k dir space pond and press Enter. To check, type l s space hyphen l and press Enter. It displays a directory named pond and all the existing files examples. Here we can see the owner of the directory pond is spoken |
| Type
sudo chown -R demo pond |
Let us change the owner of the directory pond to demo.
Type the following command and press Enter Enter the sudo password, if required and press Enter again. |
| Press Ctrl+L keys together.
Type ls -l and press Enter. |
I will clear the screen by pressing Ctrl + L keys together for our convenience.
Now type,l s space hyphen l and press Enter. Here we can see the new owner of the directory pond is demo. |
| Press Clear and press Enter. | Now, we will look at some examples of ch mod.
Let me clear the screen. |
| Typechmod u+x example2
press Enter |
To add execute permission to the owner of the file example2 type:ch mod space u plus x space example2 and press Enter.
This will add the execute permission to the owner of the file example2. |
| type
ls -l example2 press Enter highlight the permissions in the output |
To check that, type
l s space hyphen l space example2 and press Enter to see the changes. It has assigned read, write, and execute permissions to the owner. read-only permissions to the group. And read-only permission to others, for the file example2. |
| Type
chmod 751 example2 press Enter type ls -l example2 and press Enter Highlight the output |
Now type the command,
ch mod space 751 space example2 press Enter. This command gives the owner read, write, and execute permissions.
And execute-only permission to others for the file example2. To check type, ls space hyphen l space example2 and press Enter. |
| type chmod a=r example2
and press Enter |
To assign read-only permission to example2 for everyone, type the following command:
ch mod space a equal to r space example2 and press Enter. |
| type ls -l example2
press Enter Highlight the output |
Now type the command,
l s space hyphen l space example2 and press Enter. Observe that the file example2 has read-only permission for all users. |
| Type chmod g+w example3
and press Enter |
Let’s add the write permissions to the group for file example3.
Type the command ch mod space g plus w space example3 and press Enter. |
| Typels -l example3
press Enter Highlight the output |
Now type,l s space hyphen l space example3
press Enter. Note that the write permission has been added to the group. |
| Type chmod a-w example3
press Enter |
To remove the write permissions for all, type the command ch mod space a hyphen w space example3
press Enter. |
| Type
ls -l example3 press Enter Highlight the output |
Now type, l s space hyphen l space example3
press Enter. Observe that write permission for all has been removed |
| type
ls -l example4 press Enter Highlight the permissions in the output |
Let's look at some examples of ch grp commands.
Type the command, l s space hyphen l space example4 and press Enter. Here we can see the group permission is given for the user spoken. |
| Type sudo chgrp demo example4
press Enter |
To change the group permission, type the command sudo space ch grp space demo space example4 press Enter.
Enter the sudo password, if required. |
| Type
ls -l example4 press Enter Highlight the permissions in the output |
Now type the command l s space hyphen l space example4
press Enter Observe that the group has changed from spoken to demo |
| Switch to the terminal
type the command ls -i example5 press Enter Highlight the number in the output |
We can use l s space hyphen i command to see the i node number of a file.
type the command, l s space hyphen i space example5 An inode is a unique number that stores file or directory information.
The number written before the file is the inode number of the file. The i node number may vary for the users.
|
| Type: clear
and press enter ln example2 exampleln press Enter Point to the command. |
Now we will look at some examples of hard links.
Let me clear the screen again. To create links in Linux, we use the ln command. Type the command, l n space example2 space example l n. Both files point to the same i node and share the same data. Any change made to one file will reflect in the other file. A hard link is another name for an existing file. Both files point to the same inode. Since they share the same inode, they share the same data on disk. The file is not copied, only a new filename is created. press Enter. This command creates a hard link named exampleln to the file example2 . |
| Type ls -i example2 exampleln
press Enter Highlight to the output |
To display the inode number of both the files, type the commandl s space hyphen i space example2 space exampleln
and press Enter. The output shows that both files have the same inode number. File exampleln is the hard link for file example2. |
| Now we will look at some examples of soft links. | |
| type ln -s example2 examplesoft press Enter | To create a soft link, type the command
l n space hyphen s space example2 space examplesoft A soft link or a symbolic link is a special type of file. It holds a reference to another file or directory. This reference is an absolute or relative path and press Enter. |
| type the command
ls -li example2 examplesoft press Enter |
Now, let us display the inode number and list both the files.
Type the command, l s space hyphen l i space example2 space examplesoft and press Enter. Observe that the inode number of both the files is different. examplesoft is a soft link of example2. |
| Slide 8
Summary In this tutorial, we have learnt to:
|
With this we come to the end of this tutorial.
Let us summarise. |
| Slide 9
Assignment
|
As an Assignment, please do the following. |
| Slide 10
Thank you |
This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited, SINE, IIT Bombay.Thank you. |