查找早于 X 天的文件,不包括其他一些文件
我正在尝试为linux和solaris编写一个shell脚本,它会找到一些早于X天的特定文件,然后删除它们。诀窍是,在此过程中,有几个文件不能删除。
例如,从以下文件列表中,我需要删除 *.zip 并保留 *.log 和 *.something.*
1.zip
2.zip
3.日志
prefix.something.suffix
查找文件并将它们提供给 rm 很容易,但我在从删除列表中排除文件时遇到困难。
i'm trying to write a shell script, for linux and solaris, that finds some specific files older than X days and then deletes them. the trick is that during this process there are a couple of files that must not be deleted.
for example from the following list of files i need to delete *.zip and keep *.log and *.something.*
1.zip
2.zip
3.log
prefix.something.suffix
finding the files and feeding them to rm was easy, but i'm having difficulties in excluding the files from the deletion list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过实验,我发现可以从与逻辑运算符分组的多个复杂表达式中受益,如下所示:
干杯,
G
experimenting around i discovered one can benefit from multiple complex expressions grouped with logical operators like this:
cheers,
G
或者你可以这样做:
or you could do this:
我需要找到一种方法来提供排除文件的硬编码列表,以便不删除,但删除超过 30 天的其他所有内容。下面是一个小脚本,用于删除 30 天之前的所有文件,[exclude_file] 中列出的文件除外。
I needed to find a way to provide a hard coded list of exclude files to not remove, but remove everything else that was older than 30 days. Here is a little script to perform a remove of all files older that 30 days, except files that are listed in the [exclude_file].