LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-19-2006, 09:07 AM   #1
shamgar03
Member
 
Registered: Jul 2004
Distribution: Gentoo, CentOS
Posts: 92

Rep: Reputation: 15
strace, redirecting to file


I need to re-direct the output of strace to a file. I also need to redirect the output for time to a file. The way these two commands work is like this:
strace [options] <command>
so like "strace ls" for instance. The problem is strace ls > out just redirects the output of ls, not strace. So how would I go about doing this? I know strace has an output file command, but I really would like to be able to do this with the simple > operator since there are quite a few cases where I would like to redirect the output of a command, which calls another command, to a file. Any tips would help.

p.s. | less doesnt work after "strace ls" either
 
Old 06-19-2006, 09:12 AM   #2
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Like this:
Code:
strace /bin/ls &> /tmp/u
 
Old 06-19-2006, 09:31 AM   #3
shamgar03
Member
 
Registered: Jul 2004
Distribution: Gentoo, CentOS
Posts: 92

Original Poster
Rep: Reputation: 15
Awesome, but why doesn't it work with the time command?
time ls &> out doesn't work, is it not to standard out or standard error?

LOL maybe I should just strace ls =)

Last edited by shamgar03; 06-19-2006 at 09:35 AM.
 
Old 06-19-2006, 09:42 AM   #4
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Because you need to redirect the whole in a subshell, not only the last command
Code:
(time /bin/ls) &> /tmp/u
 
1 members found this post helpful.
Old 06-19-2006, 01:08 PM   #5
shamgar03
Member
 
Registered: Jul 2004
Distribution: Gentoo, CentOS
Posts: 92

Original Poster
Rep: Reputation: 15
Thanks man, I tried parenthesis before, but not WITH &. Very helpful
 
Old 06-19-2006, 02:33 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
p.s. | less doesnt work after "strace ls" either
Try this:

Code:
strace ls 2>&1 | less
 
Old 06-19-2006, 03:05 PM   #7
shamgar03
Member
 
Registered: Jul 2004
Distribution: Gentoo, CentOS
Posts: 92

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jlliagre
Try this:

Code:
strace ls 2>&1 | less
Nice, similiar effect as parenthesis, but it sort of shows whats going on, so I can still redirect ls to a file, and then pipe strace to less. Thanks alot guys
 
Old 06-20-2006, 06:41 AM   #8
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
You might also be interested in the command tee
Code:
(time /bin/ls) 2>&1 | tee /tmp/u
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecting to file and stdout Quantum0726 Programming 3 11-14-2005 08:35 PM
Redirecting socket output to a file elmafiacs Programming 1 10-15-2005 05:18 AM
why when redirecting output to a file any file extension seems to be fine? dr_zayus69 Linux - General 1 05-21-2005 04:09 AM
redirecting output of compile to a file halfcan Linux - Hardware 1 02-05-2005 10:01 PM
Redirecting debug info to another file subu_s Programming 1 12-07-2004 01:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration