What you can do is replace the .
in your find with the actual directories you want to search in.
find */tmp -mtime +30 -type f -delete
If tmp
can be several levels deeper then you might be interested in
find . -regex '.*/tmp/[^/]+' -mtime +30 -type f -delete
or similar to the first option, but by using the double-star globular expression (enabled with shopt -s globstar
)
find **/tmp -mtime +30 -type f -delete
*
Matches any string, including the null string. When the globstar shell option is enabled, and *
is used in a pathname expansion context, two adjacent *
s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a /
, two adjacent *
s will match only directories and subdirectories.
source: man bash
Note: you have to be careful though. Imagine that you have a directory folder1/tmp/foo/
then the above commands (with exception of the regex version) will select also files in folder1/tmp/foo
and this might not be wanted. You might be interested in the extra option -maxdepth 1