Full width home advertisement

728+3

Post Page Advertisement [Top]

728+3

 image

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

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

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

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

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 $?
image
    The Output should not be 0.

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

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

3) Run the following command:-
    cd lbooktemp
image

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

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

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

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
image

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

9) Run the following command:-
     cd test
image

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

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

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


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.
image

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

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

4) Run the following command:-
    cd test
image

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

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

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

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

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


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

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

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

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

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
image
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
    
.com/img/b/R29vZ2xl/AVvXsEik24UVbK7DEudmQyB5y4qZk7WTKOXsnzTTqeFZ6oa9pVyuZVKyMW8LO82yZcGfmUa938IsCNNZAyg6PCvtNyZmtz4q_moO18-VvrcqvNJSOvfeb54YHGrRLZt2qqjvIOE6zgWfmwWBZ2uF/

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
image
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
image
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
image

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
image


LAB 4 END

image

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]

728+3
| Designed by Colorlib