dev/null

Can anyone explain proper syntax and use of dev/null I understand it is to have the cron executed and do nothing in terms of logging the output.

Not everything in my cron uses it and the ones that do have different variations such as.

/dev/null 2>&1

&> /dev/null 2>&1

N1XBM

Apparare Scientor

Paratus Communicare

Allstar Node # 27086, 41540, 41812

The ‘/dev/null’ device is essentially a device driver with a ‘face’ and no ‘body’. It can
also be looked at as the ‘bit-bucket’ device. You can write all the data that you want to
it, and it will do nothing with it, and you can attempt to read from it as many times as
you want, and it will never have data for you.

A shell (command line) oriented program in a UNIX(1) (or UNIX-like, such as Linux) environemnt
has 3 “standard” “streams” of characters associated with it. “stdin” (the stream from which it
receives
characters as input, such as the keyboard you are typing on), “stdout” (the stream to which it outputs characters for “normal” uses, such as the display that you are looking at), and “stderr”
(also for outputting characters, but normally to indicate some erroneous condition). Streams
are type of “files” and are accessed through “file handles”, of which stdin is file handle “0”.
stdout is file handle “1”. and stderr is file handle “2”. Whatever additional files and/or streams
your process opens are assigned larger file handle numbers, etc.

From a shell (command line), you can “redirect” any of these streams to non-default places, such
as
a case like this, where you want no “normal” or “error” output, and you
re-direct it to go to “/dev/null”., effectively making your program not
output anything anywhere.

The “>/dev/null 2>&1” syntax
means “redirect stdout to /dev/null, and redirect stderr (file handle 2) to whatever file handle 1 (stdout) is doing”.

Jim, WB6NIL

(1) UNIX is a footnote of Bell Laboratories.

:slight_smile:

···

Date: Sat, 22 Aug 2015 14:42:08 -0400
From: N1XBM@amsat.org
To: app_rpt-users@ohnosec.org
Subject: [App_rpt-users] dev/null

Can anyone explain proper syntax and use of dev/null I understand it is to have the cron executed and do nothing in terms of logging the output.

Not everything in my cron uses it and the ones that do have different variations such as.

/dev/null 2>&1

&> /dev/null 2>&1

N1XBM

Apparare Scientor

Paratus Communicare

Allstar Node # 27086, 41540, 41812


App_rpt-users mailing list
App_rpt-users@ohnosec.org
http://ohnosec.org/cgi-bin/mailman/listinfo/app_rpt-users
To unsubscribe from this list please visit http://ohnosec.org/cgi-bin/mailman/listinfo/app_rpt-users and scroll down to the bottom of the page. Enter your email address and press the “Unsubscribe or edit options button”
You do not need a password to unsubscribe, you can do it via email confirmation. If you have trouble unsubscribing, please send a message to the list detailing the problem.

I appreciate all of the replies. So is there any difference between these two? I have both in my cron and most of that has come from different scripts I’ve used.

/dev/null 2>&1

&> /dev/null 2>&1

N1XBM

Apparare Scientor

Paratus Communicare

Allstar Node # 27086, 41540, 41812, 42086

Hi Robert,

I believe the &> redirection operator is bash specific and means to
simultaneouly redirect both stdout and stderr.

So, these two statements should be the same:

  >/dev/null 2>&1

  &>/dev/null

As you have listed below, the 2>&1 is redundant on the second statement.

73, David KB4FXC

···

On Sat, 22 Aug 2015, Robert Newberry wrote:

I appreciate all of the replies. So is there any difference between these
two? I have both in my cron and most of that has come from different
scripts I've used.

>/dev/null 2>&1

&> /dev/null 2>&1

N1XBM
Apparare Scientor
Paratus Communicare
Allstar Node # 27086, 41540, 41812, 42086