0% found this document useful (0 votes)
1 views3 pages

TP 6

The document outlines tasks for processing text streams and basic file management using various command-line tools. It includes instructions for concatenating files, viewing and manipulating file contents, calculating hash values, and managing directories and files. The tasks cover a wide range of operations including sorting, filtering, and modifying text, as well as creating, copying, moving, and deleting files and directories.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views3 pages

TP 6

The document outlines tasks for processing text streams and basic file management using various command-line tools. It includes instructions for concatenating files, viewing and manipulating file contents, calculating hash values, and managing directories and files. The tasks cover a wide range of operations including sorting, filtering, and modifying text, as well as creating, copying, moving, and deleting files and directories.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

TP6 – Process text streams and basic file management

Task 1: Process text streams with filters


1. Concatenate the contents of testfile1 and testfile2 and redirects the output to testfile3
using the command cat and the redirect operator.
2. Open the file "/etc/passwd" for viewing using the less command. You can then use the
arrow keys to scroll up and down through the file or use the spacebar to scroll down one
page at a time. Note that the "/etc/passwd" file is a system file that contains information
about user accounts on the system.
3. Displays the first 10 lines of the file "/etc/passwd" and then the first 20 lines.
4. Displays the last 20 lines of the file "/etc/passwd".
5. To monitor changes to the "dpkg.log" file in real-time, you can open a terminal window
and run the command tail -f /var/log/dpkg.log. In another terminal window, you can
install htop using the command sudo apt install htop. Note that the "dpkg.log" file
displays the logs for package installations, updates, and removals.
6. Number all lines in a testfile, including empty lines using the command nl.
7. The wc (Word Count) command is used to display the number of lines, words, and bytes
in a file. Display only the number of words in the "/etc/passwd" file and then display
only the number of lines in the "/etc/passwd" file.
8. The od (Octal Dump) command stands for octal dump, as its primary use is to display
files in octal format. However, it can also be used to display files in hexadecimal or
ASCII format, depending on the options used. Display in ASCII format the
"/etc/passwd" file, display contents in octal format, display contents in hexadecimal
format.
9. MD (Message Digest) is a cryptographic hash function that takes an input (message)
and produces a fixed-sized output (hash value) of a specific length. MD5 is a specific
implementation of the MD algorithm that produces a 128-bit hash value. The MD5 hash
value can be used to verify the integrity of a file, as even a small change in the input file
will result in a different hash value. Create a file named passwdfile in the current
directory and copies the contents of the /etc/passwd file to it. Then, calculate the MD5
hash value of the passwdfile using the command md5sum and saves it to a file named
hashpasswd. Make some changes to the passwdfile file and verifiy its integrity by
comparing its MD5 hash value with the hash value stored in the hashpasswd file using
the command md5sum.
10. SHA256 and SHA512 are cryptographic hash functions like MD5, they produce a fixed-
size output of a specific length: SHA256 produces a 256-bit hash value, while SHA512
produces a 512-bit hash value. To use the sha256sum or sha512sum command, you
must install the hashalot package (sudo apt install hashalot). Verify the integrity of the
passwdfile file using SHA256 and SHA512 hash functions.
11. Create a new file testfile with the following content:
17,November,1981,Thomas,Employee
2,January,1985,Mike,Employee
22,May,1992,Johen,Employee
Sort the contents of testfile in ascending numerical order and then sort the contents of
testfile by the third field of each line, assuming that the fields are separated by commas.
12. The tr (translate) command is used to translate characters. Take the contents of the file
testfile, replace all commas with semicolons, and output the result.
13. Take the contents of the testfile file, delete all commas, and output the result.
14. Take the contents of the testfile file, convert all lowercase letters to uppercase letters,
and output the result.
15. Take the contents of testfile, convert all lowercase letters to uppercase letters, replace
all commas with semicolons, and output the result.
16. Use the cut command to extract the fourth field from each line in the testfile file, where
fields are separated by commas.
17. Extract the first, second, and fourth fields from each line in the testfile file.
18. Merge lines from the two following files pastefile1 and pastefile2 side by side,
separating the corresponding lines with a tab.
Pastefile1 Pastfile2
01 January
02 February
03 March
19. Merge lines from two files pastefile1 and pastefile2 side by side, separating the
corresponding lines with a comma instead of a tab.
20. Merge lines from two files pastefile1 and pastefile2 sequentially, separating them with
commas. The output must be as the following:
01,02,03
January,February,March
21. Display the unique lines in the following uniqfile. If a line is repeated multiple times, it
will only appear once in the output.
Uniqfile
This a test
This a test
This a test
Add another test
Add another test
This a test
Add another test
Add another test
22. Display the number of occurrences of each unique line in the uniqfile. The number that
precedes each line in the output indicates how many times that line appears in the file.
23. Group consecutive identical lines and display each group only once.
24. Replace all occurrences of "Employee" with "Lawyer" in the file testfile and displays
the result in the standard output using the sed (stream editor) command.
25. Similar to the previous one, except that the result is redirected to a file named streamfile
instead of being displayed in the standard output.
26. Replace all occurrences of "Employee" with "Lawyer" in the testfile, but modify the file
tesfile directly instead of displaying the result in the standard output or redirecting it to
a new file.
27. Split the file named passwdfile (created in Step 9) into smaller files of 1000 bytes each.
The resulting files will have names like xaa, xab, xac, and so on. The original file will
not be modified.
Task 2: Basic file management
1. Create three new directories in the current directory called "test0", "test1" and
"test2" using the mkdir command.
2. Create a new directory called test3 with two more subdirectories inside called test4
and test5, resulting in the path test3/test4/test5 using the command mkdir with the
-p option.
3. Change the current working directory to "test0" and create the file testfile0.
4. Change the current working directory to "test1" and create the file testfile1.
5. Change the current working directory to "test2" and create the file testfile2.
6. Change the current working directory to "test0" and copy the file tesfile0 from the
directory "test0" to the "/tmp" directory.
7. Change the current working directory to user's home directory and copy the file
tesfile0 from the "/tmp" directory to the current directory. If there is already a file
with the same name in the current directory, the command will prompt for
confirmation before overwriting it.
8. Change the current working directory to "test1" and copy the file tesfile1 from the
directory "test1" to the "/tmp" directory preserving the original file's attributes, such
as permissions and timestamps.
9. Copy the contents of the "Documents" directory (located one level up in the
directory tree) to the "test1" directory (the current directory).
10. Change the current working directory to the user's home directory and move the file
testfile2 from the "test2" directory to the current working directory.
11. Move the entire "/tmp" directory and all of its contents to the current working
directory and then move it back in its original place.
12. Rename the file testfile2 to tesfilerename in the current working directory and then
restore its original name.
13. Create a new file tesfile.txt and then set the timestamp of the file testfile.txt to April
4th, 2020 at 12:34:21 PM. Write the word "hello" into the file.
14. Determine the type of the file testfile.txt and testfile2 by using the command file.
15. Use the command rmdir to remove the directory named "test3", why will the
command fail?
16. Use the command rmdir -p test3/test4/test5 to remove the directory "test5" inside
"test4" inside "test3", as well as any parent directories (test4 and test3).
17. Change the current working directory to "test0" and remove the file testfile0.
18. Change the current working directory to "test1" and remove the file testfile1: the
command will prompt the user for confirmation before removing the file, if the user
confirms, the file will be removed.
19. Change the current working directory to the user's home directory and remove the
file named testfile2 and display a message indicating that the file was removed.
20. Change the current working directory to "test2" and create the file testfile2. Use the
remove command to forcibly remove the file testfile2 without prompting for
confirmation.
21. Create inside the directory "test2" a new directory "test22" and two new files
testfile02 and testfile12 and then remove the directory named "test2" and all its
contents (including files and subdirectories).
22. Remove the directories "test0" and "test1".

You might also like