简体   繁体   English

Bash 脚本查找包含修改文件的目录

[英]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.它在子目录中搜索已更改的文件,然后从路径中删除除第一个目录组件之外的所有文件,并使用sort -u删除重复项。 Note that it also strips off the initial ./ from the results, but it looks like you don't really want/need that part anyway.请注意,它还会从结果中./初始./ ,但看起来您并不真正想要/需要该部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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