Searching for directories containing specified files?

Hope this is an interesting question. I want to find a directory containing all the data. So far I have done the following:

Find multiple files in unix ...

find . -type f \( -name "*cache" -o -name "*xml" -o -name "*html" \)

link: http://alvinalexander.com/linux-unix/linux-find-multiple-filenames-patterns-command-example

Search only directories containing specified files ...

find . -type f -name '*.pdf' |sed 's#\(.*\)/.*#\1#' |sort -u

Link: http://www.unix.com/unix-for-dummies-questions-and-answers/107488-find-files-display-only-directory-list-containing-those-files.html

How can I create a command that will give me a directory that contains all the specified files ... (The files should be in the given directory, but not in the subdirectory .. and all the files listed should be present)

Want to find WordPress theme directories

+4
2

find :

find -type d -exec sh -c '[ -f "$0"/index.php ] && [ -f "$0"/style.css ]' '{}' \; -print

, && [ -f "$0"/other_file ]. sh , . , sh , .

:

$ mkdir dir1
$ touch dir1/a
$ mkdir dir2
$ touch dir2/a
$ touch dir2/b
$ find -type d -exec sh -c '[ -f "$0"/a ] && [ -f "$0"/b ]' '{}' \; -print
./dir2

, dir1 dir2. dir2 , .

gniourf_gniourf (), sh. :

find -type d -exec test -f '{}'/a -a -f '{}'/b \; -print

[ test . -a && , .

, :

find -type d -exec test -f '{}'/a -a -f '{}'/b \; -print0 | tar --null -T - -cf archive.tar.bz2

-print0 , . , , . tar , bzip. , find -print0. , -print ( --null tar), .

+3

script:

#!/bin/bash

# list of files to be found
arr=(index.php style.css page.php single.php comment.php)
# length of the array
len="${#arr[@]}"

# cd to top level themes directory
cd themes

# search for listed files in all the subdirectories from current path
while IFS= read -d '' -r dir; do
   [[ $(ls "${arr[@]/#/$dir/}" 2>/dev/null | wc -l) -eq $len ]] && echo "$dir"
done < <(find . -type d -print0)
+1

All Articles