LINUX BASICS (312001) Experiment No 05: Execute file and Directory manipulation commands
![]() |
LINUX BASICS (312001) Experiment No 05: Execute file and Directory manipulation commands |
In this Linux Basics manual practical number five we are going to learn Execute file and Directory manipulation commands in Linux. Data and programs are stored in files. These are organized in directories. Simply, a directory is just a file that contains other files (or directories). Various operations that can be performed on a file are created, opened, read, written, moved, closed, and renamed.
Program code
1. Create 3 blank files p1 p2 p3 using touch command
Answer:
Bash
touch myfiles/p1 myfiles/p2 myfiles/p3
Questions
1. What are the options of wc command
Answer:
Option | Description |
---|---|
-c or --bytes |
Counts bytes. |
-l or --lines |
Counts lines. (default) |
-m or --chars |
Counts characters (excluding newlines). |
-w or --words |
Counts words. |
--help |
Displays help information and exits. |
--version |
Displays version information and exits. |
-L or --max-line-length |
Prints length of longest line per file. |
--files0-from=F |
Reads input from files listed in file F (NUL-terminated) |
2. What are different options of diff command?
Answer:
3. What is the difference between comm and cmp command
Answer:
Feature | comm command |
cmp command |
---|---|---|
Purpose | Compares two sorted files line by line. | Compares the contents of two files byte by byte. |
Input Requirement | Both files must be pre-sorted in ascending order. | Files don't need to be sorted. |
Output | Shows three lists: lines only in the first file, lines only in the second file, and lines present in both files. | Reports the byte and line number (if applicable) where the first difference occurs. If no difference is found, it exits silently (no output). |
Use Case | Identifying lines unique to each file or common to both. | Checking if two files are identical or finding the first point of difference. |
Example | comm file1.txt file2.txt |
cmp report.txt report.bak |