Search code examples
bashdirectorylstailxargs

Tail multiple directories


How do I print only the last (n) file(s) inside nested directories matching a certain pattern?

Doing

ls -l dir*/history/ | tail 

gives only the content of the last directory.

I suspect it has to do with xargs but can't really figure out how.


Solution

  • To answer your question directly, use the loop:

    for d in dir*/history/; do
        ls -l "$d" | tail
    done
    

    But, for more advanced directory "filtering" (and processing) than this, find might come in handy.