时间输出重定向 [英] Time output redirection

查看:183
本文介绍了时间输出重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个脚本,COM preSS拉链及焦油3档,测量时间做一个比较,但是当我尝试了时间的输出重定向到一个文件存储在其中的输出是焦油和拉链的人,可能有人帮助我吗?

i have made an script to compress 3 files in zip and tar and measure the time to make a comparison, but when i try to redirect the output of time to a file the output stored in it is the tar and zip ones, could someone help me?

#!/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

感谢

推荐答案

试试这个:

首先创建一个空白TIME.TXT文件(在你的shell脚本的顶部)

First create a blank time.txt file (at top of your shell script)

>time.txt

那么,对于每一个zip命令,做这样的事情(注:';'之前是'}'重要:

then, for each zip command, do something like this (NOTE: ';' is important before '}' :

{ time zip -r $1.zip $1 > /dev/null 2>&1; } 2>>time.txt

这篇关于时间输出重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆