- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- >/dev/null 2>&1
Operating System - Linux
1820095
Members
3364
Online
109608
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 10:22 PM
тАО08-27-2007 10:22 PM
hi
what does it mean
>/dev/null 2>&1
on the end of the cron job ?
kind regards
chris
what does it mean
>/dev/null 2>&1
on the end of the cron job ?
kind regards
chris
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2007 11:11 PM
тАО08-27-2007 11:11 PM
Solution
Ok, we'll need to talk a little bit about pipes and file handles to make sure this all makes sense in the long run.
First off, I'll give you the short answer:
Send any output to the bin, so you don't see it.
Now, we'll go into it a bit further, so you'll know what some of the funkie's mean.
When in a shell, you can do various things with the output and input to commands. You can run them through a pipe:
grep root /var/log/messages | less
This takes the output of the 'grep' commands, and uses the 'less' paginator to finally display it on the screen.
To go into further detail, this sends the STDOUT of 'grep' to less.
If you wanted to send the output to a file, you'd use a redirect:
grep root /var/log/messages > /tmp/file
This takes the STDOUT, and sticks it into '/tmp/file'. I won't go into detail about the > and >> options etc. as they are all covered in the man page.
There are 3 file descriptors for every process. STDIN, STDOUT and STDERR. These map to 0, 1 and 2 respecitvly.
Strangely enough, the above command can also be written as:
grep root /var/log/messages 1> /tmp/file
The first command makes the assumption that you want to redirect STDOUT. This one clears up that assumption.
Now we'll look at STDERR:
grep root /var/log/mseeagse > /tmp/file
This will spit out an error to your tty, even though you've redirected the output.
grep root /var/log/mseeagse 2> /tmp/file
This one will output nothing, and '/tmp/file' will contain the error. If we didn't miss-spell the messages file name, any errors that might occur would go to the file, but the output will go to the TTY.
Now we'll do the last confusing thing, moving a file descriptor to a different one. This is where the & comes in:
grep root /var/log/mseeagse 2> &1
This moves STDERR so it comes out in the same place as STDOUT. It says "Move file descriptor 2 to file descriptor 1".
Thus where we get to your tail. We mix and match the STDOUT and STDERR redirections:
grep root /var/log/messages > /tmp/file 2> &1
grep root /var/log/mseeagse > /tmp/file 2> &1
With both of these commands, both the regular output (STDOUT), and any errors that occur (STDERR) will go into '/tmp/file'.
When stacking redirects like this, there is one major thing to be aware of. When you move a file descriptor, you have to make sure the descriptor you are moving too has already been redirected to where you want, otherwise you can get some... interesting results.
First off, I'll give you the short answer:
Send any output to the bin, so you don't see it.
Now, we'll go into it a bit further, so you'll know what some of the funkie's mean.
When in a shell, you can do various things with the output and input to commands. You can run them through a pipe:
grep root /var/log/messages | less
This takes the output of the 'grep' commands, and uses the 'less' paginator to finally display it on the screen.
To go into further detail, this sends the STDOUT of 'grep' to less.
If you wanted to send the output to a file, you'd use a redirect:
grep root /var/log/messages > /tmp/file
This takes the STDOUT, and sticks it into '/tmp/file'. I won't go into detail about the > and >> options etc. as they are all covered in the man page.
There are 3 file descriptors for every process. STDIN, STDOUT and STDERR. These map to 0, 1 and 2 respecitvly.
Strangely enough, the above command can also be written as:
grep root /var/log/messages 1> /tmp/file
The first command makes the assumption that you want to redirect STDOUT. This one clears up that assumption.
Now we'll look at STDERR:
grep root /var/log/mseeagse > /tmp/file
This will spit out an error to your tty, even though you've redirected the output.
grep root /var/log/mseeagse 2> /tmp/file
This one will output nothing, and '/tmp/file' will contain the error. If we didn't miss-spell the messages file name, any errors that might occur would go to the file, but the output will go to the TTY.
Now we'll do the last confusing thing, moving a file descriptor to a different one. This is where the &
grep root /var/log/mseeagse 2> &1
This moves STDERR so it comes out in the same place as STDOUT. It says "Move file descriptor 2 to file descriptor 1".
Thus where we get to your tail. We mix and match the STDOUT and STDERR redirections:
grep root /var/log/messages > /tmp/file 2> &1
grep root /var/log/mseeagse > /tmp/file 2> &1
With both of these commands, both the regular output (STDOUT), and any errors that occur (STDERR) will go into '/tmp/file'.
When stacking redirects like this, there is one major thing to be aware of. When you move a file descriptor, you have to make sure the descriptor you are moving too has already been redirected to where you want, otherwise you can get some... interesting results.
One long-haired git at your service...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2007 03:06 AM
тАО08-29-2007 03:06 AM
Re: >/dev/null 2>&1
Chris,
in UNIX
0 = stdin
1 = stdout
2 = stderr
>/dev/null 2>&1 means
redirect all the standard out and standard error messages/output/results from the programs/scripts to /dev/null ( which means they go to a bottomless pit)
in UNIX
0 = stdin
1 = stdout
2 = stderr
>/dev/null 2>&1 means
redirect all the standard out and standard error messages/output/results from the programs/scripts to /dev/null ( which means they go to a bottomless pit)
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP