O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.4. grep on the system

If we want to use grep to get information from our system, this is easily accomplished from what we have just learnt. In these examples, we’ll be using the pipe command, i.e. that the bar sign (|) takes the output from the left of the bar and uses it for input for the command on the right.

8.4.1. Directories

If you want to search a directory for directory listings only we can do this:

							$ ls -l | grep '^d'
						

or search a directory and don’t include any directories:

							$ ls -l | grep '^[^d]'
						

If we want to search for directories that have executable files set by group and other:

							$ ls -l | grep '^d.....x..x'
						

8.4.2. passwd file

							$ grep "louise" /etc/passwd louise:lxAL6GW9G.ZyY:501:501:Accounts Sect 1C:/home/accts/louise: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required