Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / In the shell, what does ” 2>&1 ” mean?

In the shell, what does ” 2>&1 ” mean?

October 8, 2021 by James Palmer

File descriptor 1 is the standard output (stdout).
File descriptor 2 is the standard error (stderr).
Here is one way to remember this construct (although it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as “redirect stderr to a file named 1”. & indicates that what follows and precedes is a file descriptor and not a filename. So the construct becomes: 2>&1.
Consider >& as redirect merger operator.

echo test > afile.txt

redirects stdout to afile.txt. This is the same as doing
echo test 1> afile.txt

To redirect stderr, you do:
echo test 2> afile.txt

>& is the syntax to redirect a stream to another file descriptor – 0 is stdin, 1 is stdout, and 2 is stderr.
You can redirect stdout to stderr by doing:
echo test 1>&2 # or echo test >&2

Or vice versa:
echo test 2>&1

So, in short… 2> redirects stderr to an (unspecified) file, appending &1 redirects stderr to stdout.

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2023 · News Pro Theme on Genesis Framework · WordPress · Log in