Full width home advertisement

Post Page Advertisement [Top]

 

PART 1: USING GREP TO FIND PATTERNS
1) Run the following command:-
    cd /tmp

2) Use dmesg to create a file to search the information of your computer. Run the command below:-
    dmesg > dmesg1.txt

3) Now we can determine what network device is being used, run the command below:-
    grep network dmesg1.txt

4) The output might not be very informative. But what if case is an issue? Try the following                        command:-
     grep -i network dmesg1.txt

5) The -i tells grep to ignore case. You should now able to see which network driver your system is             using, Try the command below:-
     grep -i cdrom dmesg1.txt

6) grep returns a code based on the results of the search. Run the above command again (you can press up arrow for quick way):
    grep -i cdrom dmesg1.txt

 *The above 5 and 6 coding is only available to PC or Laptop that have CD-rom. Ignore it if you don't have CD-rom.*

7) Now run the following command:-
    echo $?

8) Assuming the text was found, the return code will be 0. Now search for a string that should not be        there, follow the command below:-
    grep -i jimlewis dmesg1.txt
    echo $?
    The Output should not be 0.

PART 2 : COMPRESSING FILES USING ZIP AND TAR
ZIP
1) Run the following command:-
    cd /tmp

2) Next, let's make a temporary directory:-
    mkdir lbooktemp

3) Run the following command:-
    cd lbooktemp

4) Now let's create some files:-
     ls>f1.txt; route>f2.txt; sudo dmesg>f3.txt

5) Create more files!
    ifconfig>ifconfig.dat; sudo dmesg>dmesg.dat

6) Now let's include all into zip file, follow the command below:-
     zip lbook1.zip *.txt *.dat

When you open file, it should be look like that.

7)  The unzip program is used to extract files out of a zipped file. Make another directory using the             command:-
     mkdir test

8) Run the following command:-
    cp lbook1.zip test

9) Run the following command:-
     cd test

10) Now unzip the file:-
      unzip lbook1.zip

11) Continue with command below and you able to see the files as before.
      ls -la

12) There is another alternative way to view the zip file without extract anything, run the command            below:-
      unzip -l lbook1.zip


TAR
1)Use the files created from the last task and run the command as below:-
   tar cvzf lbook1.tar.gz *.txt 
   This will create a gzip compressed archive file.

2) Next, run the command below:- 
    file lbook1.tar.gz

3) To extract, first copy it to the text directory, follow the command as below:-
     cp lbook1.tar.gz test

4) Run the following command:-
    cd test

5) Run the following command:-
     tar xvzf lbook1.tar.gz

6)  Follow the command below to see the file again:-
     ls -la

7) To view a tar archive, use the t (for tell) option:-
    tar tvzf lbook1.tar.gz

8) Now let's TAR the whole directory, follow the command below:-
    cd /tmp

9) You will get the entire directory even the hidden files if exist, run the following command:-


PART 3: OTHER HELPFUL COMMANDS SUCH AS STAT, SUM, TOUCH, AND MORE
1) Run the following command:
    cd /tmp

2) Create a file:-
     dmesg > file1.txt

3) Run the command below and screenshot or take a photo. We will use it later.
    ls -la

4) Use the stat command to see practically everything you would want to know about the file:
     stat file1.txt

5) Now assume you had sent that file to someone that running 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 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. The file names do not have to match.

6) We have created a lot of files by using the redirection operator. You can use the touch command:
    touch file2.txt. Due to file2.txt is not exist, the touch command we auto create it as an empty file,          we can use file to check whether it is correct, follow the command below:-
    touch file2.txt
    file file2.txt
    

7)  What if we run touch on an existing file? What will happen to it? Let's try it with the command             below:-
     ls -la file1.txt
     touch file1.txt
     ls -la
We can clearly see that the changes of the Date and Time of file1.txt.

8) Suppose you want to just view a text file. Run the following command:-
    less file1.txt
You may press Q to exit.

9)  If you want to view only the first few lines in that file, you may the follow the command below:-
      head file1.txt

10) The head command shows the 10 lines by default. We can also view the last 10 lines by change the head to tail, follow the command below:-
      tail file1.txt


LAB 4 END


LET'S MAKE A LITTLE BIT PROGRESS EVERY DAY AND YOU SEE 
THE POWER OF SMALL CHANGES

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib