Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Redirect Terminal command output to desktop file UNIX
I added the following to my .login (actually a file called .aliai which is sourced from my .login):
  alias "DT" "cat >> ~/Desktop/DT.txt" 
I can now have any command's output redirected to a file on my desktop called DT.TXT, appending any new text to the end of the file. If I do not want it to append to an old DT.txt that may already exist, I use the DTo command defined by the following alias:
  alias "DTo" "cat > ~/Desktop/DT.txt" 
Either can be used as follows:
 % ls -la | DT    [... or "| DTo"]
The secret is the "piping" through the DT ( or DTo) command, which executes the redirect alias.
    •    
  • Currently 4.25 / 5
  You rated: 4 / 5 (4 votes cast)
 
[18,811 views]  

Redirect Terminal command output to desktop file | 3 comments | Create New Account
Click here to return to the 'Redirect Terminal command output to desktop file' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
if you also want to see the output as it happens...
Authored by: soob on Jul 25, '02 10:56:35AM
use:
 |& tee filename
This both displays the output normally to stdout (usually your screen) and redirects a copy to the file you've given. For example, I like to keep logs of all my configures and makes for the various unix utilities and tools I install. So I'll use commands like
./configure |& tee ~/Documents/logs/zsh-4.0.4-configure.log
and
sudo make install |& tee ~/Documents/logs/zsh-4.0.4-install.log
for each of the steps used to configure, make and install the package. I'm able to see the output directly in my terminal screen and automatically get the output saved in my logs directory. There's probably ways to incorporate this into aliases or functions... I know zsh supports global aliases that can be used anywhere in the command, for example. Jim

[ Reply to This | # ]
another cool solution
Authored by: SOX on Jul 25, '02 03:02:46PM

here is a solution that allows you to direct the output to another terminal window or wherever.

open a terminal window and type:
mkfifo /tmp/junk ; perl -we 'while (1) { die unless open FILE ,"/tmp/junk"; \
print $x while ( $x=<FILE>); warn "---end of file--\n" }'

you only need to do that part one time.
then from any other terminal just redirect the output to /tmp/junk

for example:
ls -l >/tmp/junk

will send the output to the other terminal window.
for a cool example try
cat >/tmp/junk

and as you type lines they appear in the other window.

you can of course do whatever you want with the text in the other window. send it to a file or parse it or whatever by adding the approriate redirects in the original command.



[ Reply to This | # ]
if you also want to see the output as it happens...
Authored by: rusto on Jul 25, '02 07:19:17PM

This only worked for me (in the bash shell) if I omitted the "&". Cool hint, thanks!



[ Reply to This | # ]