Skip to content

Redirecting in Unix

February 3, 2016

Well, sometimes we can use a post for ourselves. This post is part of those.

Sometimes, redirecting is a little mess. Because I wanted to create backups of my database and the output goes right to a file and stderr is just an informative output. This is achieved by the commands curl and mongoexport among others.

Then what is I want to have the stderr sent to the stdout?

Well, quite simple. Follow the example below:

( mongoexport -db mydb --collection my 2>&3 | gzip -c > my.json.gz ) 3>&1

 

The explanation: you send the output to a “third” channel (achieved by 2>&3). Then simply pipe to the compression made through gzip. Don’t forget to make it when a high priority (using the parenthesis) and send back the channel 3 to the stdout (channel 1) by adding 3>&1.

That’s magic but sometimes I need to look on the internet for this trick. And I loose my time googling. Now I know where to find the info! If someone can achieve this in Windows10 on the command line, just drop me the way to do in the comments.

 

Advertisements

From → Computers

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: