Linux-Ubuntu/C2/Linux-File-Ownership-and-Permissions/English

From Script | Spoken-Tutorial
Revision as of 01:38, 26 January 2026 by Ketkinaina (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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:
  • Manage file ownership and permissions using c h own and c h mod commands.
  • Change file group ownership using chgrp command.
  • Describe i nodes and view i node numbers of the files.
  • Create and verify hard links and symbolic links in Linux.
Slide 3

System Requirements

To record this tutorial, I am using:

Ubuntu O S version 24 point 04

Slide 4

Pre-requisites

https://EduPyramids.org </u>

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.

  1. file-attr.zip
  2. fa-commands.txt

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 each set contains r, and w, means read, and write.

Highlight example1

highlight spoken

Here we can see that the owner of the file example1 is spoken.
Slide 7

chown command

  • The chown command changes the ownership of a file or directory.
  • This is an admin command.
  • Only the root user can change the owner of a file or directory.

chown [options] ownername filename or directoryname

* The c h own command changes the ownership of a file or directory.
  • This is an admin command.
  • Only the root user can change the ownership of a file or directory.
  • Here is the syntax of the c h own command.
Slide 8

chown options

  • -R: change permissions for all files in the current directory and its sub-directories.
  • -c: report changes made to files.
  • -f: prevent chown from displaying error messages.
The c h own command comes with various options like hyphen R, hyphen c, hyphen f and others.
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 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.

Recall that we have given you an assignment in an earlier tutorial to create a user named demo.

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.

Slide 9

Changing File Permissions

ch mod command is used to change the permissions of a file or directory.

The name chmod stands for change mode.

Using chmod we can grant or remove permissions for owner, group and others.

read (r)

write (w)

execute (x)

The command modifies only the permissions, not the file contents or ownership.

ch mod command is used to change the permissions of a file or directory.

The name c h mod stands for change mode.

Using chmod we can add or remove permissions such as: read, write, execute.

These permissions can be changed for owner, group and others.

It does not modify the file contents or change ownership.

Slide 10

Syntax of chmod command

chmod [ugoa][+-=][rwx] file-or-directory

This is the syntax of the c h mod command.
Slide 11

Permissions using three-digit octal number

chmod [0-7][0-7][0-7] file_or_directory

Each digit represents:

1st digit → owner permissions

2nd digit → group permissions

3rd digit → others permissions

Permission values:

r = 4 (read)

w = 2 (write)

x = 1 (execute)

Alternatively, we can set permissions using a three digit octal number.
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 and write 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.

To check type, ls space hyphen l space example2 and press Enter.

Read and execute permissions to the group.

And execute-only permission to others for the file example2.

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 commandch 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 commandch 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

Slide 12

chgrp command

Ch-grp.png

  • ch grp command changes the group ownership of a file or directory.
  • Group members can then access it based on the set permissions.
  • Only the owner of a file or a privileged user can change the group.
Slide 13

Syntax of chgrp command

  • The basic syntax of the ch grp command is:chgrp [options] group file
  • To change the group of a directory and all its contents recursively:chgrp -R group directory
  • Here, group is the new group name, and file or directory is the target.
  • The basic syntax of the ch g r p command is:ch grp options group file.
  • To change the group of a directory and all its contents recursively type:ch grp hyphen R group directory.
  • Here, group is the new group name, and file or directory is the target.
Switch to terminal

Press Clear and press Enter.

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 commandsudo 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 commandl s space hyphen l space example4

press Enter

Observe that the group has changed from spoken to demo

Slide 14

Inode

An i node is a unique number that stores file or directory information.

Files are hard links to i nodes, which the system uses to access data.

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

press Enter.

The number written before the file is the i node number of the file.

The i node number may vary for the users.

Slide 15

Hard Links

A hard link is another name for an existing file.

Both files point to the same i node.

Since they share the same i node, they share the same data on disk.

The file is not copied, only a new filename is created.

Slide 16

Inode and Hard Links

An i node can have multiple directory entries through hard links.

Hard links let multiple filenames point to the same i node.

To create links in Linux, we use the ln command.

Slide 17

Syntax of ln

ln source link

The syntax of ln command to create a hard link is:

ln space source space link

The source is an existing file, and the link is the new filename.

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.

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.

Type the command,

l n space example2 space example l n

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 i node 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 i node number.

File exampleln is the hard link for file example2

Slide 18

Soft Link

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.

ln -s target-filename symbolic-filename The syntax of l n command to create soft links isl n space hyphen s space target hyphen filename space symbolic hyphen filename.
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 and press Enter.

type the command

ls -li example2 examplesoft press Enter

Now, let us display the i node number and list both the files.

Type the command,

l s space hyphen l i space example2 space examplesoft

press Enter.

Observe that the i node number of both the files is different.

examplesoft is a soft link of example2.

Slide 19

Summary

In this tutorial, we have learnt to:

  • Manage file ownership and permissions using chown and chmod commands.
  • Change file group ownership using chgrp command.
  • Describe inodes and view inode numbers of the files.
  • Create and verify hard links and symbolic links in Linux.
With this we come to the end of this tutorial.

Let us summarise.

Slide 20

Assignment

  1. Create a file named sample.txt.
  2. Display its permissions using the ls -l command.
  3. Change the permissions so that only the owner can read and write the file.
  4. Display the inode number of sample.txt.
As an Assignment, please do the following.
Slide 21

Thank you

This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited SINE IIT Bombay.Thank you.

Contributors and Content Editors

Ketkinaina