LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-29-2008, 04:34 AM   #1
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Rep: Reputation: 15
Redirecting output to multiple locations?


How does one redirect the output for a command to multiple locations? For instance for:
Code:
ls /dir > out1.txt
Instead of just out1.txt, can one output to out1.txt and out2.txt?

And can one both output to an output file, and display the output to the shell screen as normal (as if there was no output redirection)?
 
Old 05-29-2008, 04:58 AM   #2
ophirg
Member
 
Registered: Jan 2008
Location: Israel
Distribution: Kubuntu 13.10
Posts: 134

Rep: Reputation: 34
you can use
Code:
ls /dir > a ; cat a > b
it's a bit long, and technically it's a two commands
but it works
 
Old 05-29-2008, 05:02 AM   #3
grizly
Member
 
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
Quote:
$ls /dir | tee file1.txt | tee file2.txt
Enjoy dude, outputs to both files and displays on screen.

Last edited by grizly; 05-29-2008 at 05:04 AM.
 
Old 05-29-2008, 05:51 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And if you don't want to see it use tee and redirect ;}


Code:
$ls /dir | tee out1.txt > out2.txt
 
Old 05-29-2008, 06:04 AM   #5
ophirg
Member
 
Registered: Jan 2008
Location: Israel
Distribution: Kubuntu 13.10
Posts: 134

Rep: Reputation: 34
Nice solution
Tinkster and grizly
didnt think about it...
 
Old 05-29-2008, 06:18 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Or simply
Code:
ls /dir | tee file1 file2 file3 file4 file5 ... fileN > /dev/null

Last edited by colucix; 05-29-2008 at 06:21 AM.
 
Old 05-29-2008, 04:52 PM   #7
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by grizly View Post
Enjoy dude, outputs to both files and displays on screen.
Thanks, this works

The program that I actually want to output takes a very long time (hours), so the two commands option wouldn't work, but 'tee' does.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Managing multiple screens: redirecting video output and switching between screens simopal6 Linux - Hardware 2 11-13-2007 07:08 AM
A little help with redirecting output tybalt Linux - Newbie 1 08-04-2007 11:08 PM
redirecting output using > cmk77 Slackware 8 11-10-2006 03:08 AM
Redirecting output from XEV 3saul Linux - Software 1 02-26-2006 02:14 PM
redirecting output to multiple outputs granny Linux - General 6 02-13-2004 08:18 AM


All times are GMT -5. The time now is 06:38 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration