LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-18-2018, 08:09 AM   #1
chaotik
LQ Newbie
 
Registered: Jul 2018
Posts: 1

Rep: Reputation: Disabled
Question redirecting stdout and stderr output


Can someone explain what is happening here?

I do not understand why both stderr and stdout are not redirected to the same file. (sample1 and sample2 files exist, and there is no sample3 file)

root@dell:~# ls -l sample1 sample2 sample3 >&2 2>file2
-rw-r--r-- 1 root root 0 Oct 17 12:11 sample1
-rw-r--r-- 1 root root 0 Oct 17 12:11 sample2

root@dell:~# cat file2
ls: cannot access 'sample3': No such file or directory


Thank you.

Last edited by chaotik; 10-18-2018 at 08:13 AM.
 
Old 10-18-2018, 08:43 AM   #2
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Order is important regarding redirections. You cannot redirect a flow to somewhere undefined previously (in your case you are telling: redirect standard output to where error output is redirected, but you define the error output redirection only after)
Instead, please try:
Code:
ls -l sample1 sample2 sample3 >file2 2>&1
or
Code:
ls -l sample1 sample2 sample3 2>file2 >&2
or
Code:
ls -l sample1 sample2 sample3 &>file2

Last edited by l0f4r0; 10-18-2018 at 08:48 AM.
 
1 members found this post helpful.
  


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
Redirecting Cron job output to STDERR fails padeen Slackware 5 05-12-2014 11:15 AM
[SOLVED] Redirecting output from stderr mwilner Linux - Newbie 5 12-02-2010 07:25 AM
redirecting stdin, stdout and stderr, and finding files name and other stats wroom Programming 4 08-14-2010 06:48 AM
How to redirect stdin and stderr to another terminal... trist007 Linux - Newbie 4 06-29-2010 08:10 AM
Shell script stdout, stderr and stdin solo9300 Linux - General 6 12-29-2009 12:33 AM

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

All times are GMT -5. The time now is 11:10 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