LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   append command output to file by giving command in terminal (https://www.linuxquestions.org/questions/linux-newbie-8/append-command-output-to-file-by-giving-command-in-terminal-737491/)

sumeet inani 07-03-2009 09:43 AM

append command output to file by giving command in terminal
 
Hi,I am using openSUSE 10.3.
When I install software from tarball then to record time required I send output of date to beg.txt(when installation begins) and end.txt (when installation finishes).
How can I append output of date to a file so I don't need two files?

geek.ksa 07-03-2009 10:25 AM

ummm I would do that with a small script. The tar command will be invoked from within the script. Let's the tar command arguments are passed to the script in $1 and tarball in $2
so

#!/bin/ksh
date > log.txt
tar $1 $2
date >> log.txt


do man tar, you could find something better

mericet 07-03-2009 10:33 AM

The output of any command can be redirected from standard output to a file using > or >>
example
$ ls > listings.txt write directory listing into a new file called listing.txt
$ date >> log.txt append the current date/time to the file log.txt

note that > creates a new file, >> appends to an existing one.

veerain 07-03-2009 10:34 AM

You can pretty well use time command also to estimate the time.
time command
It will show time it takes to completing the command.

nuwen52 07-03-2009 10:36 AM

Code:

echo "start time: `date`" > /tmp/time.txt
<do stuff>
echo "end time: `date`" >> /tmp/time.txt

The quotes around date are backquotes, not the normal quotes. The ">>"means append.


All times are GMT -5. The time now is 11:30 AM.