Laboratory Exercise 6
Laboratory Exercise 6
IT0035L
(APPLIED OPERATING SYSTEMS LAORATORY)
EXERCISE
6
LINUX FILE OPERATIONS, DATA REFINEMENT, AND
REDIRECTORS
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]
The touch command allows creating an empty file. It also allows updating the time stamp on existing file.
Syntax:
touch filename1 filename2
Examples:
To delete the file aa:
Syntax: rm aa
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
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]
Example:
To send output of ls command
Syntax: ls > myfiles
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.
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
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.
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.
3. Create a new file named fruits using cat command and write the following texts below:
Mango
Banana
Banana
2Grapes
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.
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.
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