PART 1: USING GREP TO FIND PATTERNS
1) Run the following command:-
cd /tmp
dmesg > dmesg1.txt
3) Now we can determine what network device is being used, run the command below:-
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:-
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
cd lbooktemp
ls>f1.txt; route>f2.txt; sudo dmesg>f3.txt
5) Create more files!
ifconfig>ifconfig.dat; sudo dmesg>dmesg.dat
zip lbook1.zip *.txt *.dat
7) The unzip program is used to extract files out of a zipped file. Make another directory using the command:-
cp lbook1.zip test
ls -la
12) There is another alternative way to view the zip file without extract anything, run the command below:-
12) There is another alternative way to view the zip file without extract anything, run the command below:-
unzip -l lbook1.zip
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.
cp lbook1.tar.gz test
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
cd /tmp
PART 3: OTHER HELPFUL COMMANDS SUCH AS STAT, SUM, TOUCH, AND MORE
1) Run the following command:
cd /tmp
dmesg > file1.txt
ls -la
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
8) Suppose you want to just view a text file. Run the following command:-
less file1.txt
You may press Q to exit.
head file1.txt
No comments:
Post a Comment