LAB 4
DKT 221/3
OPERATING SYSTEM PRINCIPLE
LAB
MODULE 4
DKT 221/3
OPERATING SYSTEM PRINCIPLE
PART 1 : Using Grep to Find Patterns
1. Use dmesg to create a file, so we can search for some information about your system:
dmesg >dmesg1.txt
2. To see if the network is being used we can use ' grep network dmesg1.txt ' :
3.Then we use command ' grep -i network dmesg1.txt '. ' -i ' in the command line tells grep to ignore case. It make easier to see which network driver your system is using.
4.After that we use command ' grep -i cdrom dmesg1.txt'
5.grep returns a code based on the results of the search. Run the above command again (remember the up arrow shortcut?) : grep -i cdrom dmesg1.txt
6.Now run the following command: echo$?
7.Assuming the text was found , the return code will be o. Now search for a string that should not be there: grep -i jimlewis dmesg1.txt
1.Let's make a temporary directory: mkdir lbooktemp
2.Run the following command: cd Ibooktemp
3.Create some files: ls > f1.txt; route > f2.txt; sudo dmesg > f3.txt
4. Create more files: ifconfig > ifconfig.dat; sudo dmesg > dmesg.dat
5.let's zip all files: zip lbook1.zip *.txt *.dat
6.The unzip Program is used to extract file out a zipped file. Make another directory using the command: mkdir test
7.run the following command:
- cp lbook1.zip test
- cd test
8.Now unzip the file: unzip lbook1.zip
9.Run ls. You should see the files as before.
Part 3 : Using TAR
1.We can use the same file as before: cd /tmp /lbooktemp
2.Create a gzip compressed archive file: tar cvzf Ibook1.tar.gz *.txt
3.Run: file lbook1.tar.gz. It should show you something.
4.To extract, first copy it to the test directory: cp lbook1.tar.gz test
5.Run: cd test
6.Extract file: tar xvzf lbook1.tar.gz
7.Run ls -la. You should see the files again.
8.To view a tar archive, use: tar tvzf lbook1.tar.gz
9.Now let's TAR the whole directory; cd /tmp
10.Run: tar cvzf lbooktemp1.tar.gz lbooktemp
11. This will get the entire directory, even the hidden files if any exist.
Part 4 : Other Helpful Command Such as Stat, Sum, Touch, and more
1.Create a file: sudo dmesg > file1.txt
2.run ls- la and remember the info. We will use this later
3.Use the stat command to see practically everything you would ever want to know about the file: stat file1.txt
4.Now suppose you have sent that file to someone that is running a Linux system, and want to ensure it did not get corrupted along the way. Run the following command: sum file1.txt
*The first number is the checksum and the second is the number of blocks for that file. If the other person runs sum on his copy of the file and sees the same info, the files are the same.
5.We have created a lot of files by using the redirection operator. You can also use the touch command: touch file2.txt
6.Since :file2 . txt did not already exist, touch will create it as an empty file. In fact, let's prove that: file file2.txt
7.So what happens if we run touch on an existing file? Does it empty it? No, it updates the time and date on it. Run the following command: ls -la file1.txt
8.Now run the following command: touch file1.txt
9.Run ls - la again. You should notice it now shows the current date and time on that file.
10.Suppose you want to just view a text file. Run the following command: less fi1e1.txt
12.Say we want to see just the first few lines in that file: head fi1e1.txt
13.The head command shows the first 10 lines by default. How about the last 10 lines? Run the following command: tail file1.txt
Comments
Post a Comment