I want to find some folders by name, and then list their information using "ls", here is what i did using "find",
find ./ -mindepth 1 -maxdepth 3 -type d -name logs
what i got is:
./RECHMN32Z/US/logs
./RECHMN32Z/UM/logs
./RECHMP3BL/US/logs
./RECHMP3BL/UM/logs
./RECHMAS86/UM/logs
./RECHMAS86/US/logs
and then i add "xargs ls -l" , then it will return information of all files under these folders returned above, if i just want to list information of these folders, how to do ?
It's not find or xargs's fault, but ls's. When given directory names ls shows their contents. You can use -d
to have it only show the directories themselves.
find has a -ls
action that uses the same format as ls -dils
. No need to invoke an external command.
find ./ -mindepth 1 -maxdepth 3 -type d -name logs -ls
Or use ls -ld
to list the directories and not their contents. -exec cmd {} +
is a simpler alternative to xargs
. No pipeline required.
find ./ -mindepth 1 -maxdepth 3 -type d -name logs -exec ls -ld {} +