重定向 bash find 的输出,然后通过管道传输到 xargs。
redirecting output of bash find and then piping to xargs.
这是一个脚本,如果文件量大于 85%,它将删除文件。它工作正常,但是,我想在终端中查看 find 命令的输出并将其保存到临时文件中。如果我在 gzip 命令的末尾加上 -verbose,它会变得冗长,但我想在 zip 之前而不是之后查看文件。
volume="vol10"
mountp="/casper/vol10"
filepath="/casper/vol10/casperfile/"
fileglob="/casper/vol10/casperfile/201*"
filetemp=$(mktemp /tmp/vol10cleanup.XXXXXX)
get_volpercent() {
{ read foo ; read foo; read size used avail prct mountpoint ; } < <(df -k ${mountp}/*)
printf "%s\n" "The Percentage of $volume is $prct"
}
cd $filepath
for filerm in execution order ; do
get_volpercent
if [[ "$prct" > "85%" ]] ; then
printf "%s\n" "Disk is over 85% full"
printf "%s\n" "find $fileglob/$filerm -mtime +10 -type f | xargs gzip "
printf "%s\n" "Zipping files"
find $fileglob/$filerm -mtime +10 -type f -print 2>&1 | tee -a $filetemp | xargs gzip
get_volpercent
else
get_volpercent
cat $filetemp
fi
done
如何使用 /dev/tty
将文件名打印到屏幕上?和 GNU Parallel 用于处理 "ugly" 文件名:
find $fileglob/"$filerm" -mtime +10 -type f -print | tee -a "$filetemp" /dev/tty | parallel gzip
这是一个脚本,如果文件量大于 85%,它将删除文件。它工作正常,但是,我想在终端中查看 find 命令的输出并将其保存到临时文件中。如果我在 gzip 命令的末尾加上 -verbose,它会变得冗长,但我想在 zip 之前而不是之后查看文件。
volume="vol10"
mountp="/casper/vol10"
filepath="/casper/vol10/casperfile/"
fileglob="/casper/vol10/casperfile/201*"
filetemp=$(mktemp /tmp/vol10cleanup.XXXXXX)
get_volpercent() {
{ read foo ; read foo; read size used avail prct mountpoint ; } < <(df -k ${mountp}/*)
printf "%s\n" "The Percentage of $volume is $prct"
}
cd $filepath
for filerm in execution order ; do
get_volpercent
if [[ "$prct" > "85%" ]] ; then
printf "%s\n" "Disk is over 85% full"
printf "%s\n" "find $fileglob/$filerm -mtime +10 -type f | xargs gzip "
printf "%s\n" "Zipping files"
find $fileglob/$filerm -mtime +10 -type f -print 2>&1 | tee -a $filetemp | xargs gzip
get_volpercent
else
get_volpercent
cat $filetemp
fi
done
如何使用 /dev/tty
将文件名打印到屏幕上?和 GNU Parallel 用于处理 "ugly" 文件名:
find $fileglob/"$filerm" -mtime +10 -type f -print | tee -a "$filetemp" /dev/tty | parallel gzip