Skip to content
Advertisement

linux command line recursively check directories for at least 1 file with the same name as the directory

I have a directory containing a large number of directories. Each directory contains some files and in some cases another directory.

JavaScript

I need to check that each sub_dir contains at least one file with the exact same name. I don’ need to check any further down if there are sub directories within the sub_dirs.

I was thinking of using for d in ./*/ ; do (command here); done but I dont know how to get access to the sub_dir name inside the for loop

JavaScript

What is the best way to do this or is there a simpler way?

Advertisement

Answer

from the parent directory

JavaScript

will give you the name/name.txt pair. Compare with the all dir names to find the missing ones.

UPDATE

this might be simpler, instead of scanning you can check whether file exists or not

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement