6

I'm looking for a one-line command that find multiple files or directories contained by a single directory.

foo -> bar
    -> baz
    -> quux

temp -> bar

I'm looking to only find foo because it contains bar, baz, and quux, but not find temp.

Due to other reasons, I have to use tcsh for this.

Any suggestions?

StephenG
  • 183
  • 1
  • 7

4 Answers4

9

This should do what you want and works with the data provided

find . -type d -exec test -e '{}'/bar -a -e '{}'/baz -a -e '{}'/quux \;  -print

It basically finds directories then checks to see if they contain the relevant files. If they do it prints the name. It works in bash and tcsh.

user9517
  • 115,471
  • 20
  • 215
  • 297
0

One way of doing that, expecially if you need to find out this information multiple times, is with mlocate. After you install mlocate, you have to run sudo updatedb to populate index database. Future reindexing is triggered by daily cron job (which is configured by default on many popular Linux distributions).

When you have an up-to-date index, you can run a queries such as:

locate -r '^/.*/foo/\(bar\|baz\|quux\)$'

The above command will search everything from the root (/) down and print something like:

/home/foo/bar
/home/foo/baz
/var/lib/foo/quux
/usr/local/foo/bar
Tubeless
  • 1,640
  • 14
  • 15
0

There are several ways to locate your files. One example: finding a directory named "foo", and listing everything inside:

find . -name "foo" -type d | xargs ls -la

Another option, if you have treecommand installed (sudo apt-get install -y tree):

find . -name "foo" -type d | xargs tree -afi 

The -afiwill give you all the files (-a), full file path (-f) and discard the indentation (-i).

0

Try finding all directories and look if they contain your three files/dirs:

find -type d -print0 | xargs -0 -I@@ sh -c '[ -e @@/a ] && [ -e @@/b ] && [ -e @@/c ] && echo @@'
zhenech
  • 1,492
  • 9
  • 13