我已经制作了一个脚本来压缩zip和tar中的3个文件并测量进行比较的时间,但是当我尝试将时间输出重定向到文件时,存储在其中的输出是tar和zip文件,有人能帮帮我吗?
#!/bin/bash
if [ "$#" != 3 ]
then
echo "usage $0 file1 file2 file3"
exit
fi
echo "Start\n"
echo "First zip:" > time.txt
time >> time.txt zip -r $1.zip $1
echo "first zip done"
echo "first tar:" >> time.txt
time >> time.txt tar czf $1.tar.gz $1
echo "first tar done"
echo "second zip:" >> time.txt
time >> time.txt zip -r $2.zip $2
echo "Second zip done"
echo "second tar:" >> time.txt
time >> time.txt tar cfz $2.tar.gz $2
echo "Second tar done"
echo "third zip:" >> time.txt
time >> time.txt zip -r $3.zip $3
echo "third zip done"
echo "third tar:" >> time.txt
time >> time.txt tar cfz $3.tar.gz $3
echo "third tar done"
rm *.zip *.tar.gz
exit
由于
答案 0 :(得分:1)
试试这个:
首先创建一个空白的time.txt文件(在shell脚本的顶部)
>time.txt
然后,对于每个zip命令,执行类似这样的操作(注意:';'在'}之前很重要:
{ time zip -r $1.zip $1 > /dev/null 2>&1; } 2>>time.txt