-1
你好我有脚本的问题,我想删除7天以前的文件,但我做了错误的东西:)并且不起作用。预先感谢您的帮助linux脚本查找x天以前的文件并删除
#!/bin/bash
# sudo apt-get install pydf
#pydf
# source
DST="/mnt/share/backup"
#find TIF
FINDFILE=*.TIF
if ! [ -f "$DST/$FINDFILE" ]; then
echo "no file in: $DST"
find $DST -type f -mtime +7 -name '*.TIF'
if ! [ "$?" = "0" ]; then
echo "ERROR $DST/"
exit 200
fi
else
echo "file exist"
echo "older than 7 days wiil deleted "
find $DST -type f -mtime +7 -name '*.TIF' -execdir rm -- {} \;
if ! [ "$?" = "0" ]; then
echo "ERROR : $DST"
exit 200
fi
fi
如果dosent文件存在,那么find $DST -type f -mtime +7 -name '*.TIF'
是否存在find $DST -type f -mtime +7 -name '*.TIF' -execdir rm -- {} \;
输出端子
[email protected]:/home/fm-x2# ./find.sh
no file in: /mnt/share/backup
/mnt/share/backup/P1010007.TIF
/mnt/share/backup/P1010004.TIF
/mnt/share/backup/P1010003.TIF
/mnt/share/backup/P1010009.TIF
/mnt/share/backup/P1010008.TIF
/mnt/share/backup/P1010005.TIF
/mnt/share/backup/P1010006.TIF
[email protected]:/mnt/share/backup# ls -lh
razem 224M
-rw-r--r-- 1 fm-x2 fm-x2 82M sty 13 09:37 2016-01-13.backup.tar.bz2
-rwxr-xr-x 1 fm-x2 fm-x2 21M gru 31 2004 P1010003.TIF
-rwxr-xr-x 1 fm-x2 fm-x2 21M gru 31 2004 P1010004.TIF
-rwxr-xr-x 1 fm-x2 fm-x2 21M gru 31 2004 P1010005.TIF
-rwxr-xr-x 1 fm-x2 fm-x2 21M gru 31 2004 P1010006.TIF
-rwxr-xr-x 1 fm-x2 fm-x2 21M gru 31 2004 P1010007.TIF
-rwxr-xr-x 1 fm-x2 fm-x2 21M gru 31 2004 P1010008.TIF
-rwxr-xr-x 1 fm-x2 fm-x2 21M gru 31 2004 P1010009.TIF
[email protected]:/mnt/share/backup#
在刚开始如果没有TIFF退出错误if ! [ -f "$DST/$FINDFILE" ]; then
。
问题解决了
13线if ! [ "$DST/$FINDFILE" ]; then
[email protected]:/home/fm-x2# ./find.sh
file exist
older than 7 days wiil deleted
[email protected]:/mnt/share/backup# ls -l
razem 83536
-rw-r--r-- 1 fm-x2 fm-x2 85538248 sty 13 09:37 2016-01-13.backup.tar.bz2
'不work',关心扩大这个 ? – 123
是不工作的输出终端:'no file in:/ mnt/share/backup /mnt/share/backup/P1010007.TIF /mnt/share/backup/P1010004.TIF'并且不删除文件 –
请发表你的问题中的整个输出。 – 123