I want to run a command to:
- Find all directories named "
inc
" under a folder "X
". - List all the subdirectories under each "
X/.../inc/
". - Redirect the output to a file named "
list
"
I tried various combinations of the below command, without success:
$ find X/ -name "inc" -print | xargs find {} -type d > list
find: path must precede expression
How can I do this?
Best Answer
find
can do this all by itself:Read the
-path
part ofman find
for more info.As I mentioned quickly in a comment: if you store the directories line separated in a text file, directory names containing newlines won't be unambiguously representable. If you are certain that directories don't contain newlines, that's OK. Just a general remark.