Reputation: 2929
If I use head *.txt | less
, it will display the head of all files with *.txt in the current directory? What if I wish to display the head of all files with .txt residing in current directory and subdirectories.
Thanks for your help
Upvotes: 3
Views: 5809
Reputation: 165
I was trying to do the same thing; here's what worked for me (I output the response to the file headtest.txt). Note that this will move through the current directory and the subdirectories.
find . -type f -exec head '{}' \; >> headtest.txt
Hope this helps.
Upvotes: 1
Reputation: 24435
If your shell supports it (zsh does, not sure about the rest), you can use **
syntax:
head **/*.txt
Upvotes: 1
Reputation: 43
Another option is to use -
find -name '*.txt' | xargs head
Please note that -name need not work in all environments In that case, you can use
find . | grep ".txt" | xargs head
Upvotes: 0