'find: Exclude files with the same name based on their depth in a directory

I have a free of files like this:

root_dir
|
-- dir1
     |
     -- file.ext
     -- misc.txt
     subdir
        |
        -- file.ext
        -- rest.ext
|
-- dir2
     |
     -- file.ext
     -- misc.txt
     subdir
        |
        -- file.ext
        -- rest.ext

and I want to compress the following subset of it:

root_dir
|
-- dir1
     |
     -- misc.txt
     subdir
        |
        -- file.ext
        -- rest.ext
|
-- dir2
     |
     -- misc.txt
     subdir
        |
        -- file.ext
        -- rest.ext

My plan is to first get a list of the files, and then pipe them to gzip or tar. The files in dir1 and dir2 have the same name (but different content). Yet, the problematic part is that file.ext in dir* and subdir have the same name, which makes filtering the files based on the names a bit tricky.

Following this, I have tried the following in the root_dir

find -type -f -not -name *misc.txt*

but, expectedly, it finds the file.ext at the depth one as well. Is there a way to exclude these depth-1 file.exts from the find ouput?

Notes

  • the extentions are dummy and represent a bunch of files with various types
  • I have hundreds of dir1 and dir2
  • each dir* is very large and its not efficient to compress all first, and then remove the first level file.exts


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source