Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find nested directories?

I have directory tree like:

dir11/dir21/dir31......./dirn1
dir12/dir22/dir32......./dirn2
dir13/dir23/dir33......./dirn3

Depths are different. Does it possible find all paths on which exists directory with file x.txt that has length>0 ? May be need use bash script? Thanks.

like image 846
user710818 Avatar asked Dec 22 '11 12:12

user710818


People also ask

How do I find subfolders?

Open Windows Explorer. Select Organize / Folder and Search options. Select the Search Tab. In the How to search section, select the Include subfolders in search results when searching in file folders option.

How do I get a list of all folders and subfolders?

Substitute dir /A:D. /B /S > FolderList. txt to produce a list of all folders and all subfolders of the directory. WARNING: This can take a while if you have a large directory.

What are nested directories?

A folder stored within another folder. Technically, the nested folder is a "subfolder," and subfolders can also contain subfolders and so on up to a maximum level. After three or four levels, it becomes cumbersome for users to deal with. See folder, files vs. folders and Win Folder organization.


1 Answers

I believe GNU find can match all your criteria by itself:

$ find /top/dir -not -empty -type f -name x.txt -printf '%h\n'

The above recursively searches /top/dir for non-empty (-not -empty), regular (-type f) files named x.txt, and prints the directories leading to these files (-printf '%h\n').

like image 53
Frédéric Hamidi Avatar answered Sep 24 '22 18:09

Frédéric Hamidi