#! /usr/bin/bash
DIRECTORY=/main/dir/sub-dir
if [ -d $DIRECTORY ]; then
find $DIRECTORY/ '*' -maxdepth 1 -mtime 1 -exec rm -rf {} \;;
#Zip Files generated within the last six hour
find $DIRECTORY/ '*' -maxdepth 1 -mmin -360 -exec gzip {} \;
fi
I'm using this command to remove files generated within the last , however the output has the following errors
Error messages :
-bash-4.2$ ./zip_files.sh
find: a*a: No such file or directory
gzip: /main/dir/sub-dir is a directory -- ignored
Files in this directory will be of these sequence,
-rw------- 1 postgres dba 16777216 Sep 23 23:37 000000010000224300000015
-rw------- 1 postgres dba 16777216 Sep 23 23:37 000000010000224300000016
-rw------- 1 postgres dba 16777216 Sep 23 23:37 000000010000224300000017
-rw------- 1 postgres dba 16777216 Sep 23 23:37 000000010000224300000018
-rw------- 1 postgres dba 16777216 Sep 23 23:37 000000010000224300000019
-rw------- 1 postgres dba 16777216 Sep 23 23:37 00000001000022430000001A
我只想洗掉已洗掉和壓縮的檔案并壓縮錯誤訊息
感謝您的回復。
uj5u.com熱心網友回復:
您的腳本可能如下所示。注意引號,注意不帶空格的unquoted 的用法,注意引數,請參閱。用 shellcheck 檢查你的腳本!* findman find
#!/usr/bin/env bash
# prefer upper case variables only for exported variables
directory=/main/dir/sub-dir
if [[ -d "$directory" ]]; then
find "$directory"/* -maxdepth 1 -type f \
'(' -mtime 1 -delete ')' -o \
'(' -mmin -360 -exec gzip {} ';' ')'
fi
使用 bash 陣列,您可以在長引數行之間放置注釋:
cmd=(
find "$directory"/* -maxdepth 1 -type f
# delete somthing
'(' -mtime 1 -delete ')' -o
# gzip them
'(' -mmin -360 -exec gzip {} ';' ')'
)
"${cmd[@]}"
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/517853.html
標籤:linux重击壳Unix
上一篇:Unix并行解壓縮檔案并存盤它們
