The g/RE/p stands for globally search for the regular expression (RE) and print out the line.
Return status – success 0, pattern not found 1, file not found 2.
$ ps -ef | grep root
The preceding command will show all processes running currently whose user ID is "root".
$ ll /proc | grep "cpuinfo"
The preceding command will show the file with the name cpuinfo from the /proc directory.
$ grep –lir "text" * // only file names // $ grep –ir "text" dir_name // show lines of files //
We will try the following commands on the love.txt file:
We will create a new file sample.txt, as follows:
Apple Fruit 5 4.5 Potato Vegetable 4 .5 Onion Vegetable .3 8 Guava Fruit 5 1.5 Almonds Nuts 1 16 Tomato Vegetable 3 6 Cashew Nuts 2 12 Mango Fruit 6 6 Watermelon Fruit 5 1
We will try the following commands on the sample.txt file: