Recursively search directories for specific directories, and create a text file of the relative or absolute path

Posted on

Problem :

Is there any means in the command line I can do a find and chain it to something that writes/appends to a text file and creates a list of the paths they find matching to specific folder names I’d like to search for?

All in all I have dozens upon dozens of directories with dozens and dozens more subdirectories and subdirectories there in.

At this point I just want an easier way to find them..

best I have thus far is

find / > tacos.txt -xdev -name "backup"

but it doesn’t let me do multiple names, and it doesn’t append to the text if I repeat multiple times

Solution :

You have a couple of options here. First, you can use >> instead of > to append to a file. The double arrows will append to the file, while the single > truncates the file.

Better right here though is that find can take multiple names like

find / -xdev -name "backup" -o -name "otherName1" -o -name "otherName2" > tacos.txt

with find -o means “or” so you can chain together sets of criteria to match, which is fairly straightforward for lists of names.