When dealing with files, it is convenient to be able to search for patterns within the text. This is often used in code development for example. Here we show how to use grep.
We will use the dmesg
program, which shows information about the running kernel, for this example. If it is not available, or if your computer has been running for a long time, the following may not match up quite right on your system.
The following is an example on using grep
:
Run the following command:
cd /tmp
Use
dmesg
to create a file, so we can search for some information about your system:dmesg > dmesg1.txt
Let's see if we can determine what network device is being used. Run:
grep network dmesg1.txt
The output might not be very informative. But what if case is an issue? Try the following command:
grep -i network dmesg1.txt
The
-i
tellsgrep
to ignore case. You should now see which network driver your system is using. Now try the following command:grep ...