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

Laboratory Exercise 6

This document describes an exercise for a laboratory class on applied operating systems. The exercise focuses on Linux file operations, data refinement commands, and redirectors. Students will perform tasks like creating directories and files, copying and moving files, sorting file contents, filtering duplicate lines, and searching files using commands like cat, sort, grep, and more. The intended learning outcomes are for students to learn how to utilize different file operation commands, data refinement commands, and redirectors to manipulate files in Linux.

Uploaded by

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

Laboratory Exercise 6

This document describes an exercise for a laboratory class on applied operating systems. The exercise focuses on Linux file operations, data refinement commands, and redirectors. Students will perform tasks like creating directories and files, copying and moving files, sorting file contents, filtering duplicate lines, and searching files using commands like cat, sort, grep, and more. The intended learning outcomes are for students to learn how to utilize different file operation commands, data refinement commands, and redirectors to manipulate files in Linux.

Uploaded by

Energy Antelope
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

COLLEGE OF COMPUTER STUDIES

IT0035L
(APPLIED OPERATING SYSTEMS LAORATORY)

EXERCISE

6
LINUX FILE OPERATIONS, DATA REFINEMENT, AND
REDIRECTORS

Student Name / Group


Name:
Name Role
Members (if Group):

Section:
Professor:
I. PROGRAM OUTCOME/S (PO) ADDRESSED BY THE LABORATORY EXERCISE
 Ability to use and apply current technical concepts and practices in the core information
technologies; human computer interaction, information management, programming, networking and
web systems and technologies. [PO: J]

II. COURSE LEARNING OUTCOME/S (CLO) ADDRESSED BY THE LABORATORY EXERCISE


 Perform file and directory creation and manipulation using DOS commands; LINUX installation in
virtual machine, file and directory creation and manipulation, and system administration using LINUX
commands. [CLO: 2]

III. INTENDED LEARNING OUTCOME/S (ILO) OF THE LABORATORY EXERCISE


At the end of this exercise, students must be able to:
 Able to utilize different file operation, data refinement commands, and redirectors in file manipulation.

IV. BACKGROUND INFORMATION


File Operation Commands
The cp command allows copying file/s and directories from one location to another.
Syntax:
cp source destination

The mv command allows to move and rename files


Syntax:
mv oldname newname
mv source destination

The touch command allows creating an empty file. It also allows updating the time stamp on existing file.
Syntax:
touch filename1 filename2

The rm command will delete a file forever.


Syntax:
rm [-option] filename1 filename2 …

Examples:
To delete the file aa:
Syntax: rm aa

To prompt first before removing the file bb:


Syntax: rm –I bb
To remove all files and all sub-directories and their contents:

IT0035L-Applied Operating System Laboratory Page 2 of 9


Syntax: rm -r *

To remove forcefully all files and all sub-directories and their contents:
Syntax: rm -rf *
Caution: Exercise caution when executing the last two commands. Should you exercise either of
them from the root directory (/), your system will definitely crash.

The echo command displays the string or text specified after it. It also used to reference and display the
values of variables. It is commonly used in programs, or shell scripts, were user input is needed.
Syntax:
echo [string]
echo $variablename

Examples:
To re-echo the word “hello” on the command line:
Syntax: echo hello

To display the value of the variable “x”


Syntax: x=hello
Syntax: echo $x

The cmp command checks two files to see if they differ. It does a byte-by-byte comparison of file1 and file2.
If the files differ, cmp outputs the location at which the first difference occurs.
Syntax:
cmp [options] file1 [file2]

The file command determines the file type of a given file. It reads the first few bytes of a file to determine
the file type.
Syntax:
file [filename]

Redirection Standard Input/Output


There are three main redirection symbols >, >>, <
Redirector Symbol >
Syntax: Linux-command > filename
To output Linux-commands result (output of command or shell script) to file. Note that if file already exist, it
will be overwritten else new file is created.

Example:
To send output of ls command
Syntax: ls > myfiles

IT0035L-Applied Operating System Laboratory Page 3 of 9


Note: Now if 'myfiles' file exist in your current directory it will be overwritten without any type of
warning.
Redirector Symbol >>
Syntax: Linux-command >> filename
To output Linux-commands result (output of command or shell script) to END of file. Note that if file exist , it
will be opened and new information/data will be written to END of file, without losing previous
information/data, And if file is not exist, then new file is created.

Example:
To send output of date command to already exist file give command
Syntax: date >> myfiles
Note: Now if 'myfiles' file exist in your current directory it will be overwritten without any type of
warning.

Redirector Symbol <


Syntax: Linux-command < filename
To take input to Linux-command from file instead of keyboard.

Example:
To take input for cat command give
Syntax: cat < myfiles
Note: Now if 'myfiles' file exist in your current directory it will be overwritten without any type of
warning.

| (Pipe Symbol)
A pipe is the same as redirecting standard output.
It is nothing but a temporary storage place where the output of one command is stored and then passed as
the input for second command.
Pipes are used to run more than two commands (multiple commands) from same command line.
Syntax: command1 | command2

Example:
Syntax: cat hello.txt | cat > h.txt
The output from the first command cat hello.txt will be piped or temporarily stored and the stored
value will serve as an input to the next command. Say the output of the command cat hello.txt is hello then
the content of h.txt is also hello

Data Refinement Commands


The sort command sorts and/or merges one or more text files in sequence.
Syntax:
sort filename

IT0035L-Applied Operating System Laboratory Page 4 of 9


The uniq command displays a file, removing all but one copy of successive repeated lines. If the file has
been sorted, uniq ensures that no two lines that it displays are the same.
Syntax:
uniq filename

grep command
• Used for pattern searching.
• Users can use this command to search a set of files for one or more phrases or patterns.
• If the pattern exists, then grep will print all the lines that contain the said pattern.
Syntax: grep pattern <filename>
where:
pattern is the phrase or pattern the user wants to find.
filename is the name of the target file.

V. GRADING SYSTEM / RUBRIC (please see separate sheet)

VI. LABORATORY ACTIVITY

1. Create two directories at your default prompt (logged-in username) using the following folder names:
 F1
 F2
Paste your captured executed command and output below.

2. Under F2 folder, create another subdirectory and named it as F3


Paste your captured executed command and output below.

3. Create a new file named fruits using cat command and write the following texts below:
Mango
Banana
Banana
2Grapes

IT0035L-Applied Operating System Laboratory Page 5 of 9


1Apple
Guava
Watermelon
Pomelo
Pomelo
pomelo
3Papaya
Paste your captured executed command and output below.

4. Display the content of the file fruits using cat command.


Paste your captured executed command and output below.

5. Type sort fruits, what is the output?


Paste your captured executed command and output below.

6. Type sort fruits > sorted_fruits then type cat sorted_fruits. What is the output?
Paste your captured executed command and output below.

7. Type echo “I love fruits!” >> sorted_fruits then type cat sorted_fruits. What is your observation the
output?
Paste your captured executed command and output below.

IT0035L-Applied Operating System Laboratory Page 6 of 9


8. Copy the file sorted_fruits to F1. Display the content of F1.
Answer:

9. Move the file fruits to F2. Display the content of F2

Paste your captured executed command and output below.

10. Sort the file sorted_fruits in reverse order.


Paste your captured executed command and output below.

11. Filter the repeated lines in file sorted_fruits


Paste your captured executed command and output below.

12. Count the number of occurrences of each word in file sorted_fruits


Paste your captured executed command and output below.

13. Display all the duplicate lines in file sorted_fruits


Paste your captured executed command and output below.

IT0035L-Applied Operating System Laboratory Page 7 of 9


14. Using grep command, search for the word Banana in the file sorted_fruits
Paste your captured executed command and output below.

15. Using grep command, search for the word “pomelo” or “Pomelo” in the file sorted_fruits regardless of
the casing of letters
Paste your captured executed command and output below.

16. Using redirector, append the system date to the file sorted_fruits
Paste your captured executed command and output below.

17. Type grep B sorted_fruits | cat > B. What is your observation in the output?
Paste your captured executed command and output below.

18. Using cat command, create a filename A with a string content of LIVE.
Paste your captured executed command and output below.

19. Using cat command, create a filename B with a string content of LOVE.
Paste your captured executed command and output below.

20. Determine the difference between files A and B in terms of bytes.


Paste your captured executed command and output below.

IT0035L-Applied Operating System Laboratory Page 8 of 9


Observation:

Conclusion:

IV. ASSESSMENT

VII. REFERENCES:
 Sobell, M., et al. (2017). A Practical Guide to Linux Commands, Editors, and Shell Programming,
4th Ed. Addison-Wesley Professional
 Cobbaut, P. (2016). Mastering Linux- Networking
 Blum, R., (2015). Linux Command Line and Shell Scripting Bible
 Fox, R., (2015). Linux with operating system concepts
 Dulaney, E., (2014). Linux all in-one for dummies, 5th Ed.Wiley
 Rosen, R. (2014). Linux kernel networking: implementation and theory. Apress

IT0035L-Applied Operating System Laboratory Page 9 of 9

You might also like