Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:40:19+00:00 2026-06-12T07:40:19+00:00

I’m having trouble getting the command to send standard error to standard out. I

  • 0

I’m having trouble getting the command to send standard error to standard out. I intend to put it in cron, but for now am just running manually.

/home/backups/backup_scripts/backup.sh 2>&1 >> /var/log/backups/backup.log

I was hoping the log file would contain any messages that were printed to standard out, but the log file only showed standard out, and the console output showed the errors.

What am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:40:20+00:00Added an answer on June 12, 2026 at 7:40 am

    This happened because of the order of the redirections. The 2>&1 means “redirect standard error to the current location of standard out”. They are processed left to right so first standard error is redirected to the current standard out (still the terminal) then standard out is redirected to a file. If you switch the order to read

    /home/backups/backup_scripts/backup.sh >> /var/log/backups/backup.log 2>&1
    

    it should do what you want. If your shell is bash it has a shortcut to redirect standard out and standard error at the same time: command &> file redirects them both to a file and command &>> file appends both to a file. This order dependency is also mentioned in the bash manual

    Note that the order of redirections is significant. For example, the command

    ls > dirlist 2>&1
    

    directs both standard output and standard error to the file dirlist, while the command

    ls 2>&1 > dirlist
    

    directs only the standard output to file dirlist, because the standard error was
    duplicated from the standard output before the standard output was redirected to
    dirlist.

    I think there is some misunderstanding of how file descriptors and redirection works. The kernel has a big table of all the open files on the system that contains the file offset, status flags, and the name of the file itself. Then each process has a table that maps file descriptor numbers to the entries in this global table.

    Before any redirections happen the global table might look something like this

    A: TERMINAL
    

    and the process table looks like

    0: A
    1: A
    2: A
    

    since descriptor numbers 0, 1, and 2 are stdin, stdout, and stderr respectively.

    Then the 2>&1 redirection is processed. This changes the process table so that 2 contains points to the same global entry as 1. However, they are already the same so nothing happens.

    When the >> /var/log/backups/backup.log redirection is processed. First the file is opened and assigned to file descriptor 3 in the process table so the tables look like

    A: TERMINAL
    B: /var/log/backups/backup.log
    

    and

    0: A
    1: A
    2: A
    3: B
    

    then standard out is changed to point to the newly opened file (as if 1>&3 were done) so the process table is now

    0: A
    1: B
    2: A
    3: B
    

    Note that 2 (stderr) is still pointing to the terminal.

    When the redirections are done in the other order, the table after >> /var/log/backups/backup.log looks the same.

    0: A
    1: B
    2: A
    3: B
    

    and then the 2>&1 redirection changes what 2 points to giving

    0: A
    1: B
    2: B
    3: B
    

    so now stdout and stderr both go to the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.