简体   繁体   中英

Bash script find directories with modified files in it

For usage within a backup script I'm looking for a way to find all folders which have been modified since a certain time. I got to this:

find ./ -maxdepth 1 -mtime -1 -type d

Unfortunately, this does not return any results, since the directories itself have not been modified, only the contents within some of the directories. The complete script is now:

repodir=/somepath
backupdir=/someotherpath

find . -mtime -1 -type d -maxdepth 1|while read repo; do
  svnadmin dump -q $repodir/$repo | bzip2 -9 > $backupdir/$repo-`date +%F`.dump.bz2
done

Try this:

find . -mindepth 2 -type f -mtime -1 | sed 's,^\./,,;s,/.*$,,' | sort -u | \
while read repo; do
   svnadmin dump -q $repodir/$repo | bzip2 -9 > $backupdir/$repo-`date +%F`.dump.bz2
done

It searches for files in subdirectories which have changed, then strips off all but the first directory component from the path, and uses sort -u to remove duplicates. Note that it also strips off the initial ./ from the results, but it looks like you don't really want/need that part anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM