nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

How can I redirect the output of time command to file

This is a discussion on How can I redirect the output of time command to file within the Linux software forums, part of the Linux Getting Started category; How can I redirect the output of time command to file... I tried, -bash-3.00# time > file1.txt real 0m0.000s user ...


Go Back   nixCraft Linux Forum > Linux Getting Started > Linux software

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 05-15-2006, 02:16 PM
Member
User
 
Join Date: Jun 2005
Posts: 45
Rep Power: 0
warren
Default How can I redirect the output of time command to file

How can I redirect the output of time command to file...
I tried,
-bash-3.00# time > file1.txt

real 0m0.000s
user 0m0.000s
sys 0m0.000s

but it didn't work...

thanks,
warren
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-15-2006, 02:50 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

Use -o option.

Write the resource use statistics to FILE instead of to the standard error stream. By default, this overwrites the file, destroying the file's previous contents. This option is useful for collecting information on interactive programs and programs that produce output on the standard error stream.

Code:
time -o output.txt myprog 
cat output.txt
To append output use -a option
Code:
time -a output.txt myprog 
cat output.txt
Reply With Quote
  #3 (permalink)  
Old 05-15-2006, 03:19 PM
Member
User
 
Join Date: Jun 2005
Posts: 45
Rep Power: 0
warren
Default

i'm having an error. I am using FC5.

-bash-3.00# time -o file1.txt ls -l
-bash: -o: command not found

real 0m0.001s
user 0m0.000s
sys 0m0.000s

same also with append -a option

thanks,
warren
Reply With Quote
  #4 (permalink)  
Old 05-15-2006, 04:21 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

Try old way it works with all UNIX oses out there including linux:

Code:
( time ls ) 2> /tmp/output.txt
cat /tmp/output.txt
-o or -a only works with GNU version of time command.
Reply With Quote
  #5 (permalink)  
Old 05-15-2006, 04:36 PM
Member
User
 
Join Date: Jun 2005
Posts: 45
Rep Power: 0
warren
Default

yes, it works!!!!
thank you so much.
btw, what does it mean when a command is inside a parenthesis?
Reply With Quote
  #6 (permalink)  
Old 05-15-2006, 04:55 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

I just want to clarify few things here

1) time command is external as well as internal. To use GNU version of external command use full path:
Code:
/usr/bin/time -o /tmp/output.txt ls
When you type time command with full path, shell will run internal time command. To verify this use following command:
Code:
type -a time
time is a shell keyword
time is /usr/bin/time

As you see time command is both internal and external to shell. That is why you got an error when you use time –o syntax.

2)
Quote:
btw, what does it mean when a command is inside a parenthesis?
It is nothing but one of the compound command. ( time ls ) is executed in a subshell environment so that you can capture its output. Please see this article for more information: http://www.cyberciti.biz/nixcraft/vi...tand-which.php
Reply With Quote
  #7 (permalink)  
Old 05-16-2006, 04:25 PM
tom tom is offline
Contributors
User
 
Join Date: Jun 2005
Location: London, UK
Posts: 213
Rep Power: 4
tom is on a distinguished road
Default

monk, cool info.

Shell may have its own version of command, which usually supersedes the version located in /usr/bin /bin or /sbin or /usr/sbin.

It is better to use full path and type command is a real lifesaver.
Reply With Quote
  #8 (permalink)  
Old 07-24-2006, 03:42 PM
Junior Member
 
Join Date: Jul 2006
Posts: 2
Rep Power: 0
clueless
Default

hi i wanted to append my output to the log file, but what is wrong i cant seem to get it to work, pls help,thks.

58 15 * * * /usr/bin/cp /a/p/s/originalSDR-config.xml /a/p/s/sdr-stm66.xml 2>>/a/l/s/SDRtestresults.log ; /usr/bin/cp /a/p/s/testSDR.xml /a/p/s/sdr-stm66.xml 2>>/a/l/s/SDRtestresults.log
Reply With Quote
  #9 (permalink)  
Old 07-25-2006, 03:59 AM
chimu's Avatar
Contributors
User
 
Join Date: Mar 2005
My distro: Ubuntu
Posts: 33
Rep Power: 0
chimu is an unknown quantity at this point
Default

clueless,

i think you need to add -v option to cp command, which explain what is being done including errors.

Code:
58 15 * * * /usr/bin/cp -v /a/p/s/originalSDR-config.xml /a/p/s/sdr-stm66.xml 2>>/a/l/s/SDRtestresults.log ; /usr/bin/cp -v /a/p/s/testSDR.xml /a/p/s/sdr-stm66.xml 2>>/a/l/s/SDRtestresults.log
Why not put all command in a script and call just script
Reply With Quote
  #10 (permalink)  
Old 07-25-2006, 09:51 AM
Junior Member
 
Join Date: Jul 2006
Posts: 2
Rep Power: 0
clueless
Default

Quote:
Originally Posted by chimu
clueless,

i think you need to add -v option to cp command, which explain what is being done including errors.

Code:
58 15 * * * /usr/bin/cp -v /a/p/s/originalSDR-config.xml /a/p/s/sdr-stm66.xml 2>>/a/l/s/SDRtestresults.log ; /usr/bin/cp -v /a/p/s/testSDR.xml /a/p/s/sdr-stm66.xml 2>>/a/l/s/SDRtestresults.log
Why not put all command in a script and call just script
hi, would like to thank you for the tip, it works!
that is just a test procedure, the actual requirement is to copy first then run a script, e.g:

28 10 * * * /usr/bin/cp -v /a/p/s/originalSDR-config.xml /a/p/s/sdr-stm66.xml 2>>/a/l/s/SDRtestresults.log ; /a/s/s/SDRGenerate.sh 2>>/a/l/s/SDR.log 1>/a/l/s/SDR2.log

but, when i try the above, the -v does not work, illegal option??
pls help..thks..
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Find out information about my file - explaining ls command sweta Getting started tutorials 1 01-11-2007 05:21 PM
How to redirect Output puppen Shell scripting 15 12-06-2006 09:44 PM
how to create multiple file in a single command selvam Shell scripting 3 07-26-2006 02:01 AM
How can I get some specific characters of dd command output warren Shell scripting 2 05-24-2006 04:59 PM
command to install tar file on freebsd hellBoy All about FreeBSD/OpenBSD/NetBSD 1 01-08-2006 01:02 AM


All times are GMT +5.5. The time now is 01:07 AM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36