简体   繁体   English

用于删除 ftp 服务器上超过 x 天的文件的 Shell 脚本

[英]Shell script to delete files older than x days on ftp server

Have a shell script which connects and puts files to ftp server.有一个 shell 脚本,用于连接文件并将文件放入 ft​​p 服务器。 Now trying to delete 2 days older files from the same dir on ftp server.现在尝试从 ftp 服务器上的同一目录中删除 2 天前的文件。 Tried to use the find command, but getting ?invalid command find ./*.txt -mtime +2 -exec rm {} \\;尝试使用 find 命令,但得到 ?invalid command find ./*.txt -mtime +2 -exec rm {} \\;

......
ftp -nv <<! >> $FTP_LOG 2>> $FTP_LOG

open xxx
user userid pwd

lcd $FILES_DIR

cd /yyy

put $File1 $File1
put $File2 $File2

find ./*.txt -mtime +2 -exec rm {} \;

quit
!
......

what else can I try??我还能尝试什么?? Need help with this.需要这方面的帮助。

我遇到了同样的错误,在使用 ftp 时,某些 linux 版本无法识别字符“*”,将其替换为特定的字符。

FTP will not provide you with a shell, as pointed here: https://serverfault.com/questions/28568/using-the-find-command-on-the-ftp-server/437649 FTP 不会为您提供 shell,如下所示: https : //serverfault.com/questions/28568/using-the-find-command-on-the-ftp-server/437649

So you would have to do your search using a grep for text files on the client side.因此,您必须在客户端使用grep搜索文本文件。

If you have access to ssh , the find command search files in a directory hierarchy.如果您有权访问ssh ,则find命令会在目录层次结构中搜索文件。 The first argument you pass should be a directory.您传递的第一个参数应该是一个目录。

You could search for a pattern, for example files with the txt extension, by using the -name option:您可以使用-name选项搜索模式,例如带有 txt 扩展名的文件:

find ./ -name "*.txt" -mtime +2 -exec rm {} \;

From the man page:从手册页:

Don't forget to enclose the pattern in quotes in order to protect it from expansion by the shell.不要忘记用引号将模式括起来,以防止它被 shell 扩展。

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

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