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

Lab 3 Os (2) - 1

This lab report discusses using Linux shell commands to perform file operations and manage file permissions. The objectives were to learn how to view/edit text files, concatenate files, sort file contents, display specific lines, and assign file permissions. Tasks included creating files, copying files, assigning various permissions using symbolic and numeric notation, appending files, and displaying file contents. The conclusion states the key lessons learned about Linux file commands and permissions.

Uploaded by

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

Lab 3 Os (2) - 1

This lab report discusses using Linux shell commands to perform file operations and manage file permissions. The objectives were to learn how to view/edit text files, concatenate files, sort file contents, display specific lines, and assign file permissions. Tasks included creating files, copying files, assigning various permissions using symbolic and numeric notation, appending files, and displaying file contents. The conclusion states the key lessons learned about Linux file commands and permissions.

Uploaded by

small tech
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

EC-231 Operating Systems

LAB REPORT #02

Submitted by
Name: Farjad Khan
Reg. No. 19-ce-029

Department of Computer Engineering


HITEC University Taxila

Presentation Calculation Observati Total


/ Format/ / Coding on /
Conclusion/ Program
Theory/ Results
Objective/
Title
Total 5 5 5 15
Obtained

___________________________
Lab. Instructor

Kaynat Rana
Experiment # 03
Linux Shell commands for file operations and their rights

Lab Objective: The main objectives of this lab are to understand:


1. How to view or edit a text file in Linux.

2. How we can concatenate two or more files into a single file,

3. How to sort contents of file

4. How to display specific lines of a file

5. How to assign different permissions to the file

using commands in Ubuntu operating system.

Software Used: Virtual box, Ubuntu & GCC Complier

Theory: Permission system on Linux.


Permissions
Every file and directory in your UNIX/Linux system has following 3 permissions
defined for all the 3 owners discussed above.

● Read: This permission give you the authority to open and read a file. Read
permission on a directory gives you the ability to lists its content.
● Write: The write permission gives you the authority to modify the contents
of a file. The write permission on a directory gives you the authority to add,
remove and rename files stored in the directory. Consider a scenario where
you have to write permission on file but do not have write permission on
the directory where the file is stored. You will be able to modify the file
contents. But you will not be able to rename, move or remove the file from
the directory.
● Execute: In Windows, an executable program usually has an extension
".exe" and which you can easily run. In Unix/Linux, you cannot run a
program unless the execute permission is set. If the execute permission is
not set, you might still be able to see/modify the program code(provided
read & write permissions are set), but not run it.

Viewing and editing a Text File

Using touch to create a blank text file: $ touch NewFile.txt.

Using cat to create a new file: $ cat NewFile.txt. ... (write anything in your file
CNTR+D to

save and CTRL+Z to exit

Simply using > to create a blank text file: $ > NewFile.txt.

$ cat [option] [filename]

i. $ cat filename

Purpose: It will display the contents of the file filename.

ii. $ cat > file1

Purpose: “>” is called output redirection operator. It permits user to write


in file1.If

file1 already exists then it over writes the contents of the file1.

E.g. write any word/phrase after giving command $ cat > file1 like “Success
is not a

destination.”

Press [Ctrl+d]

Note: The above command creates the file called file1 if file1 does not exist
and

allow user to write text there. Press Ctrl+d (To save and exit).

iii. $cat >> file1

Purpose: “>>” is use to append data in a file. It does not overwrite text
of file1
rather appends text at the end of file1.

E.g. write any word/phrase after using command $ cat >> file1 like “It’s a

progressive journey. ”

Press [Ctrl+d]

Note: The above command appends data in file1. Here you can find that data is

appended in file1 or not by using command $ cat filename, which will display
all the

content of file1.

$ cat file1

iv. $cat file1 file2 >file3

The above command is used to write contents of the file1 and file 2 into file3

v. $ head [option] Filename

Purpose: “head” displays the top part of a file. By default, it shows the first 10
lines.

head -n allows you to change the number of lines to be shown.

$ head File1: It displays first 10 lines of File1.

$ head –n50 file.txt: Displays the first 50 lines of the file.txt

$head -50 file.txt: Produces the same result as above command and Displays

the first 50 lines of the file.txt

vi. $ tail [option] Filename

Purpose: “tails” displays the bottom portion of a file. By default, it shows the
last 10

lines.

Same as head command.


tail -n allows you to change the number of lines to be shown.

$ tail File1: It displays last 10 lines of File1.

$ tail –n15 file.txt: Displays the last 15 lines of the file.txt

Lab report Tasks:

1. Show Simulation results after performing the following tasks by using suitable
commands in Linux. Also show command/commands used for specific task
a) Create a blank text file on your home directory with your name

b) Make a directory with name student

c) Change the directory to student and copy your text file in this directory
d) Assign no permission to anyone (use numeric method for permission).
e) Verify that above task has done successfully

f) Now try to write in this file. If error occurs, state why?

It is because we have denied all the permissions in the last command


g) Assign permission of write only to user (do it twice by using both symbolic and
numeric methods)

h) Verify that above task has done successfully.


i) Write your introduction in 5 to 7 lines in .txt file

j) Display contents of the file. If error occurs, state why?

Because the read permission has not been granted


k) Assign permission of read only to user (do it twice by using both symbolic and
numeric methods).
l) Verify that above task has done successfully.

m) Display contents of the file

n) Assign permissions of read and execute only to user (do it twice by using both
symbolic and numeric methods).

o) Verify that above task has done successfully


p) Assign permissions of read and write only to user (do it twice by using both
symbolic and numeric methods).

q) Verify that above task has done successfully

r) Assign all permissions to user (do it twice by using both symbolic and numeric
methods).
s) Verify that above task has done successfully
t) Assign permission of read and execute only to group (do it twice by using both
symbolic and numeric methods).
u) Verify that above task has done successfully.

v) Assign all permissions to all users (do it twice by using both symbolic and
numeric methods).
w) Verify that above task has done successfully.
2. Show Simulation results after performing the following tasks by using suitable
commands in Linux. Also show command/commands used for specific task.
a) Create 3 empty text files and name them as students.txt, pstudent.txt and
fstudents.txt.
b) Assign permissions to read only permission to the user (do it twice by using both
symbolic and numeric methods).
c) Enter at least 10 10 different students’ names in pstudent.txt and fstudent.txt. If
any error appears, debug that error for user only.
d) Now create directory named HITEC and assign permissions of read only to user and
group (do it twice by using both symbolic and numeric methods).
e) Copy all files to directory HITEC. If any error appears, debug that error for user and
group only.

f) After that append the file students.txt with first five sorted names from
pstudent.txt and last five sorted names from fstudent.txt
g) Show the contents of sorted names from file students.txt.
h) Change the permissions of file students.txt read only and both other files read and
write only (do it twice by using both symbolic and numeric methods).

i) Now append another student name in student.txt file.

j) Display contents of all the files.


k) Show permissions and all of the file contents of HITEC.

Conclusion:

In this lab I learned about Linux Shell commands for file operations and their rights. I learned
how to view or edit a text file, how we can concatenate two or more files into a single file, to
sort contents of the file, to display specific lines of a file and to assign different permissions
to the file in terminal.

You might also like