LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 03: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, 03: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, 04: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 04:04 AM.
 
Old 05-29-2008, 04:51 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 05: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, 05:18 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

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

Last edited by colucix; 05-29-2008 at 05:21 AM.
 
Old 05-29-2008, 03: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



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 06:08 AM
A little help with redirecting output tybalt Linux - Newbie 1 08-04-2007 10:08 PM
redirecting output using > cmk77 Slackware 8 11-10-2006 02:08 AM
Redirecting output from XEV 3saul Linux - Software 1 02-26-2006 01:14 PM
redirecting output to multiple outputs granny Linux - General 6 02-13-2004 07:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:55 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
Open Source Consulting | Domain Registration