0% found this document useful (0 votes)
203 views8 pages

Lab No - 04 - File Operation and Permission.

This lab report discusses file operations and permissions in Linux. It describes the basic file operations of creating, writing, reading, repositioning, deleting and truncating files. It also explains the three basic file permissions of read, write and execute. The report demonstrates how to implement file operations using commands like ls, cd, mkdir, rmdir and pwd. It shows how to view file permissions using the ls -l and ls -al commands and how to modify permissions with chmod.
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)
203 views8 pages

Lab No - 04 - File Operation and Permission.

This lab report discusses file operations and permissions in Linux. It describes the basic file operations of creating, writing, reading, repositioning, deleting and truncating files. It also explains the three basic file permissions of read, write and execute. The report demonstrates how to implement file operations using commands like ls, cd, mkdir, rmdir and pwd. It shows how to view file permissions using the ls -l and ls -al commands and how to modify permissions with chmod.
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/ 8

Lab-report no : 04

Name of the lab-report: File operation and permission.

Objectives:

1.What is File Operation and File Permission in Linux Operating System?


2.Implementation of File Operation and File Permission.

1.What is File Operation and File Permission in Linux Operating System?

Answer:

File Operations
A file is an abstract data type. For defining a file properly, we need to consider the operations that
can be performed on files. The operating system can provide system calls to create, write, read,
reposition, delete, and truncate files.

There are six basic file operations within an Operating system. These are:

 Creating a file: There are two steps necessary for creating a file. First, space in the file
system must be found for the file. We discuss how to allocate space for the file. Second, an
entry for the new file must be made in the directory.
 Writing a file: To write to a file, you make a system call specify about both the name of the
file along with the information to be written to the file.
 Reading a file: To read from a file, you use a system call which specifies the name of the file
and where within memory the next block of the file should be placed.
 Repositioning inside a file: The directory is then searched for the suitable entry, and the
'current-file-position' pointer is relocating to a given value. Relocating within a file need not
require any actual I/O. This file operation is also termed as 'file seek.'
 Deleting a file: For deleting a file, you have to search the directory for the specific file.
Deleting that file or directory release all file space so that other files can re-use that space.
 Truncating a file: The user may wish for erasing the contents of a file but keep the
attributes same. Rather than deleting the file and then recreate it, this utility allows all
attributes to remain unchanged — except the file length — and let the user add or edit the
file content.

File permissions

Every file and directory in your UNIX/Linux system has following 3 permissions such as -
1) Read
2) Write
3) Execute permission

Read (r): this gives permission to merely open a file or folder and view its contents.

Write (w): this gives permission to overwrite, append-to or delete a file or folder.

Execute (x): this gives permission to "run" a file. For example to run a script or a program.

Implementation of File Operation

1. the ls -command: It shows the contents of a particular directory – both files and directories.

2. ls -R command: We can all also find child files and directories by providing the recursive option.
We will provide the -R option which will list files and folders recursively.
3. ls -a command:All operating systems have hidden files to hide them from use. It is not a
security-related feature. It related to operation and reliability. We can see that files and folders
like .cpan, .npm, .config etc. are listed with the help of -a option.

4. cd command: Change to directory . Here after changing directory I go to Documents directo


5.mkdir command : mkdir command in Linux allows the user to create directories. Here I create
the khalid directory.
6. rmdir command: rmdir command is used remove empty directories from the filesystem in
Linux. The rmdir command removes each and every directory specified in the command line only if
these directories are empty . Here I first create a directory hello and then I remove that file by
using rmdir.

7. pwd command: We can get the current working directory with pwd command.
Implementation of File permission

ls -l command

One can view the permissions by checking the file or directory permissions i your favorite GUI File
Manager or by reviewing the output of the “ls -l” command while in the terminal and while
working in the directory which contains the file or folder.

The permission in the command line is displayed as: _rwxrwxrwx 1 owner:group

ls -al command: command to view all files in a list:


The Permission Groups used are:

u – Owner

g – Group
o – Others
a – All users

The potential Assignment Operators are + (plus) and – (minus); these are used to tell the system
whether to add or remove the specific permissions.

The Permission Types that are used are:

 r – Read
 w – Write
 x – Execute

So for an example, lets say I have a file named file1 that currently has the permissions set to
_rw_rw_rw, which means that the owner, group and all users have read and write permission.
Now we want to remove the read and write permissions from the all users group.

To make this modification you would invoke the command: chmod a-rw file1
To add the permissions above you would invoke the command: chmod a+rw file1

You might also like