Lab 4 ZIP FILE AND CHANGE DIRECTORY
PART 1. In this session we are going to learn about command line grep. Grep is an acronym that stands for Global Regular Expression Print which used to search for a string of characters in a specified file.
For example to use grep :
1) First change directory to /tmp. Then we used dmesg to create a text file inside it.
- "-i" means display ignoring case so it is more information displayed.
*Since my laptop do not have CD ROM, here's a sample output from Mr.Arvind..
4) Now we use "echo $?" to return the error code if available which we learned from last lab. The command will return a 0 if there are no error code from the last command.
*Since my laptop do not have CDROM so it will prompt 1 error.
5) Same goes with the non existing file command, the error will become 1 if there is error.
5) Same goes with the non existing file command, the error will become 1 if there is error.
*In my case it become 2 since the last command has error adds the new error.
PART 2. In this session, we going to learn how to packaging and compress multiple files into one zip or tar file.
1) First we make folder inside /tmp and named it lbooktemp
2) Then we create five files which 3 are text file and 2 dat file into that folder:
3) Now we zip the three text file into a package. There are two ways of doing this:
-we either write all the file we wanted to zip or use *.txt to select all text files in that folder.
4) We can zip file with different extension too :
example: zip all file of text file and dat file:
5) Now we try make new directory and copy the zipped file into it and unzip it :
- This shows that the files had successfully being unziped out to directory test.
6) We can also list the zipped file with command "-l"
PART 3.Using .tar
1) Assume that there are 3 text file exist that are f1 f2 and f3
Ways to tarball a file, like zip :
- then i created a new folder named test and used "tar xvzf" to export out all files to the directory.
- to show the files in the directory, I used command "ls -la"
2) We can also tell what's inside the .tar file using "tar txzf"
3) We can even tar whole folder lbook into a .tar file
PART 4. In this session we going to learn some helpful commands such as stat, sum, touch, and more..
1) use "state" to show detail of a file.
the result size is same with using command "ls -ls" :
2) use "sum" to show is it corrupted or not. The output first number is the checksum and second number is the number of blocks for that file.
3) use "touch" to create a new file and rerun "file" to check if it is exist.
*it shown file2.txt did exist but is empty content
4) Now we use show the time we created file1.txt and now use "touch" again and show the new output time.
*This show the file time is renewed.
5) Now we can use command "less" to view the content inside a text file.
Output:
*content inside my file1.txt
*use ctrl+z to stop viewing
6) By using "head" or "tail" to show first/last 10 lines in the text file.
Example I list Hello Word! and A to Z in rows and the output:
- END OF LAB 4 -
Comments
Post a Comment