我试图基本上查看一个目录,该目录具有每个用户的子目录。说 user1 和 user2 等等。我想基本上遍历每个目录并查找早于特定日期的文件并将其记录下来。我可以使用 ls -d/directory/*/获取目录列表。我知道我可以使用 find ./-type f -mtime +30 来查找超过 30 天未修改的文件。我无法弄清楚如何使用 find 所以每次通过它都会看起来像 find ./user1 -type f -mtime30 然后 ./user2 等等。
#!/bin/bash
LIST="$(ls -d /Volumes/db_backups/*/)"
for i in "$LIST";do
fold=`basename $i`
echo $fold
ModList=$(find $i -type f -mtime +30 >$fold.out )
$ModList
done
更新:我能够获得文件列表。但是,我不想循环遍历特定的子目录并向每个用户发送电子邮件。例如,我有一个文件被记录为/dir1/dir2/user1/file.txt。我将如何获取 user1 列表并将其放入 user1.out 然后放入 user2.out 等等?
最佳答案
您可以提供到 find
的多个路径:
find directory/* -type f ...
此处 directory/*
将扩展为 directory/user1 directory/user2
,实际上为 find
提供了多个路径。
编辑再想一想,您应该可以只使用find directory -type f
(帽子提示@anubhava)。
关于linux - 循环的 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20999967/