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

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.