Lab 3 Os (2) - 1
Lab 3 Os (2) - 1
Submitted by
Name: Farjad Khan
Reg. No. 19-ce-029
___________________________
Lab. Instructor
Kaynat Rana
Experiment # 03
Linux Shell commands for file operations and their rights
● 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.
Using cat to create a new file: $ cat NewFile.txt. ... (write anything in your file
CNTR+D to
i. $ cat filename
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).
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
The above command is used to write contents of the file1 and file 2 into file3
Purpose: “head” displays the top part of a file. By default, it shows the first 10
lines.
$head -50 file.txt: Produces the same result as above command and Displays
Purpose: “tails” displays the bottom portion of a file. By default, it shows the
last 10
lines.
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
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
n) Assign permissions of read and execute only to user (do it twice by using both
symbolic and numeric methods).
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).
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.