简体   繁体   English

Shell脚本删除带空格的文件

[英]Shell Script to Delete Files with Spaces

I'm trying to delete all files in a certain folder with an .sh script (linux) which are older than one day. 我正在尝试使用超过一天的.sh脚本(linux)删除某个文件夹中的所有文件。 This script is running daily and needs to delete all files in the "DTV" folder. 该脚本每天运行,需要删除“ DTV”文件夹中的所有文件。 So far I have tested with a .sh file called (full file path shown): 到目前为止,我已经测试了一个名为.sh的文件(显示了完整的文件路径):

/volume1/tasks/dtv_delete_old_files.sh

This file contains the following command inside: 该文件内部包含以下命令:

find /volume1/video/DTV/ -mtime +1 -exec rm {} \;

The folder location where the files inside need to be deleted are located here: 需要删除内部文件的文件夹位置位于:

/volume1/video/DTV

The files inside this folder have the following naming format (full path shown): 此文件夹中的文件具有以下命名格式(显示完整路径):

/volume1/video/DTV/2016-02-19_1859_BBC NEWS_BBC News.ts

The script is unsuccessful deleting the files. 该脚本无法成功删除文件。 I believe this is due to the fact that the file has spaces in the filename. 我认为这是由于文件名中包含空格。 Does anyone know how I could formulate the script so that all files in the DTV folder would be deleted (excluding the folder itself). 有谁知道我该如何制定脚本,以便删除DTV文件夹中的所有文件(不包括文件夹本身)。 Any feedback would be greatly appreciated. 任何反馈将不胜感激。

Here's man find : 这是man find

When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago. 当发现计算出该文件有多少个24小时周期前最后一次访问,小数部分被忽略,因此如果要匹配-atime +1,文件必须已经至少前两天访问的。

Use -mtime +0 to delete files that are 24+ hours old. 使用-mtime +0删除24小时以上的文件。 Spaces don't matter. 空间无关紧要。

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

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