我想删除* .mp3文件,这些文件在一个目录中的访问时间比10分钟早。 我能怎么做? 谢谢。
我将使用find命令中的-amin开关:
find <path> -name "*.mp3" -amin +10 -exec rm -f {} \;
从man find :
-amin n File was last accessed n minutes ago.
对于testing或debugging目的,不要运行rm命令,而是使用ls -l :
find <path> -name "*.mp3" -amin +10 -exec ls -l {} \;
编辑
我只想说一下关于-delete选项:这个选项会自动打开-depth选项。
放置删除将使find尝试删除指定的起点下的一切。 为了避免不好的意外,我会明确指定-depth选项。
因为我不知道OP的文件夹/文件树,我不会build议他单独使用-delete选项。 似乎对我有点无意识。
至less我会build议:
find <path> -maxdepth 1 -name "*.mp3" -amin +10 -delete
假设一个合理的最新的find命令: find /path/to/mp3/files -amin +10 -delete 。 当然,我会第一次运行没有“删除”标志,以确保删除了你认为正在删除的内容。
从find手册页:
TESTS Numeric arguments can be specified as +n for greater than n, -n for less than n, n for exactly n. -amin n File was last accessed n minutes ago.
你可以很容易地find
find . -amin +10 -iname '*.mp3' -exec rm {} \;