The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 11-20-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,617
The reason why this doesn't work is simple: in "ls -l $DIR | grep ..." the grep works on the output of ls, not on the files named in this output.

Note, that getting the diskspace and grepping for some content are two entirely different functions. Therefore you could do it only by performing these two different functions on every file and binding together the output of these via a script.

Having said this: use "find" ("man find") to set up a loop and use the "-exec" clause of "find" to 1.) grep the file for the content you are interested in and 2.) use "du" to get the filesize. 3.) Print out both if the grep has found the content, else do nothing. This will give you a list of filenames and -sizes.

I hope this helps.

bakunin