Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
陆上通信线。你说得很好,但它们是等价的,这就是一个例子。但是,OP确实请求了bash,所以我已经更新了答案。对不起,在sed中忘记了一个-n,已修复 -rw-r--r-- 1 root root 1617 Feb 2 16:17 20200202_Bash_Shell - Fatal编程技术网

陆上通信线。你说得很好,但它们是等价的,这就是一个例子。但是,OP确实请求了bash,所以我已经更新了答案。对不起,在sed中忘记了一个-n,已修复 -rw-r--r-- 1 root root 1617 Feb 2 16:17 20200202

陆上通信线。你说得很好,但它们是等价的,这就是一个例子。但是,OP确实请求了bash,所以我已经更新了答案。对不起,在sed中忘记了一个-n,已修复 -rw-r--r-- 1 root root 1617 Feb 2 16:17 20200202,bash,shell,Bash,Shell,陆上通信线。你说得很好,但它们是等价的,这就是一个例子。但是,OP确实请求了bash,所以我已经更新了答案。对不起,在sed中忘记了一个-n,已修复 -rw-r--r-- 1 root root 1617 Feb 2 16:17 20200202-161647.info.json -rw-r--r-- 1 root root 48699726 Feb 2 16:17 20200202-161647.tar.gz -rw-r--r-- 1 root root 1617 Feb


陆上通信线。你说得很好,但它们是等价的,这就是一个例子。但是,OP确实请求了bash,所以我已经更新了答案。对不起,在sed中忘记了一个-n,已修复
-rw-r--r-- 1 root root     1617 Feb  2 16:17 20200202-161647.info.json
-rw-r--r-- 1 root root 48699726 Feb  2 16:17 20200202-161647.tar.gz
-rw-r--r-- 1 root root     1617 Feb  3 06:25 20200203-062501.info.json
-rw-r--r-- 1 root root 48737781 Feb  3 06:25 20200203-062501.tar.gz
-rw-r--r-- 1 root root     1618 Feb  4 06:25 20200204-062501.info.json
-rw-r--r-- 1 root root 48939569 Feb  4 06:25 20200204-062501.tar.gz
#!/bin/bash

DEBUG="";
DEBUG="echo DEBUG...";    #put last to safely debug without deleting files
keep=2;
for suffix in /home/archives .json .tar; do
    list=( $( find . -wholename "*$suffix" ) ); #allow for zero names
    if [ ${#list[@]} -gt $keep ]; then
        # delete all but last $keep oldest files
        ${DEBUG}rm -f "$( ls -tr "${list[@]}" | head -n-$keep )";
    fi
done
find home/archives/ \( -name '*.json' -o -name '*.tar.gz' \) -print0 |\
    sort -zr |\
    sed -z '3,$p' | \
    xargs -0 echo rm -f
most_recent_json=$(ls -t *.json | head -1)
most_recent_tar_gz=$(ls -t *.tar.gz | head -1)
rm -i $(ls -I $most_recent_json -I $most_recent_tar_gz)
files_to_delete=$(ls -tr1 | tail -n+3)
rm $files_to_delete
find /home/archives/ -daystart \( -name '*.json' -o -name '*.tar.gz' \) -mtime +1 -exec echo rm -f {} +
find /home/archives/ \( -name '*.json' -o -name '*.tar.gz' \) -print0 |\
    sort -zr |\
    sed -nz '3,$p' | \
    xargs -0 echo rm -f