简体   繁体   English

用于从 FTP 目录中删除超过 30 天的文件的 shell/bash 脚本

[英]shell/bash script to delete files from FTP directory older than 30 days

I need shell script to delete all files older than 30 days from FTP server directories.我需要 shell 脚本从 FTP 服务器目录中删除所有超过 30 天的文件。 I need to delete files from 5 different directories which are older than 30 days, should not delete the directories because they might have other files, have to delete only files older than 30 days.我需要从 5 个不同目录中删除超过 30 天的文件,不应该删除这些目录,因为它们可能有其他文件,只需要删除超过 30 天的文件。 This is the first time I am working on shell script.这是我第一次处理 shell 脚本。 tried following link no luck.尝试以下链接没有运气。 can anyone help me on this.谁可以帮我这个事。

FTP delete directories older than X days FTP 删除超过 X 天的目录

below is the code I am using in my.sh file but I am facing invalid command error下面是我在 my.sh 文件中使用的代码,但我面临无效命令错误

ftp -inv $HOST <<EOS
user $ftp_user $ftp_pass
find /path/somefolder/ -type f -iname '*' -mtime +30 -exec rm {} \;
quit
EOS

Need to check if file is older than 30 days if it is older delete it from the directory.如果文件较旧,则需要检查文件是否超过 30 天,将其从目录中删除。

Create a loop who checks every file and get the file creation date, if the file is older than 30 days delete this.创建一个检查每个文件并获取文件创建日期的循环,如果文件超过 30 天,请删除它。 If loop iterator is directory file count, check next path.如果循环迭代器是目录文件计数,请检查下一个路径。

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

相关问题 Bash脚本从7天以上的远程FTP中删除文件 - Bash script to delete files from remote FTP older than 7 days 尝试使用此 bash 脚本从 ssh 登录到远程 ftp 并删除超过 N 天的文件 - Trying to use this bash script to login to a remote ftp from ssh and delete files older than N days old 使用shell脚本删除超过30天的文件而不使用find - Remove files older than 30 days without using find, using a shell script AWS 删除超过 30 天的文件 aws cli - AWS delete files older than 30 days aws cli 如何根据文件名中的日期删除30天以上的文件 - How to delete files older than 30 days based on the date in the filename shell脚本查找早于x天的文件,如果它们不在日志文件中的列表列表中,则将其删除 - shell script find file older than x days and delete them if they were not listet in log files Bash脚本查找早于X天的文件,然后将其删除,以及具有相同基本名称的文件吗? - Bash script to find file older than X days, then subsequently delete it, and any files with the same base name? BASH脚本-删除早于X天的文件夹,但其中的一些和所有子文件夹/文件除外 - BASH Script - Delete folders older than X days except for some and all their subfolders/files 删除超过 n 天的目录的 Shell 脚本 - Shell script to delete directories older than n days 在 bash 中查找早于 X 天的文件并删除 - find files older than X days in bash and delete
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM