Mittwoch, 13. April 2011

Shell-004: Selective Listing

Given the case that a number of files are in a directory, and at the same time there is a directory called file-test in the same directory. How can only the directories be listed? This is useful when the content of the directories needs to be processed somehow.

ls -l|grep ^d|awk '{print $8}'

Grep matches the beginning of the line output by 'ls' with 'd', which indicates a directory. " 'awk {print $8}' " then prints the 8th column of the output (so the directory name is available again).

Keine Kommentare:

Kommentar veröffentlichen