Changes

Jump to navigation Jump to search
960 bytes added ,  01:34, 21 February 2015
adds mime-report example
== Using Find ==
The find command in Linux is very powerful, and thus somewhat complex to learn all the syntax and options.
Suffice to say that you can read the manpage and info pages to answer your questions. However,  === Mime report ===This example finds and counts files by their extension. A "poor-man's mime-report"<source lang="bash" line>for x in \ $(find . -maxdepth 1 -type d | \ sort | \ grep -v ^./$ ); \do \ echo -e "\n\n$x\n"; \ find "$x" -type f | \ egrep -o '\.(.?.?..)$' | \ sort | \ uniq -c ; \done</source>Breakdown:<pre> 2. look for directories that are immediate descendants of the current directory 3. sort them 4. don't include hidden directories 6. with these: echo the name of the directory as a 'heading' in the report 7. find the files per directory 8. match only on the extensions found (between two and four-letter extensions) 9. sort them</pre>10. count and summarize by unique values But it looks more impressive as a one-liner:<source lang="bash">for x in $(find . -maxdepth 1 -type d|sort|grep -v ^./$); do echo -e "\n\n$x\n"; find "$x" -type f | egrep -o '\.(.?.?..)$' | sort | uniq -c ; done</source> === Prune ===In case you are trying to figure out the prune option so that you can efficiently scan a directory for something while also ignoring .svn metadata, here is an example:
<source lang="bash">
find ./ -name .svn -prune -o -name "*html*"
4,558

edits

Navigation menu