LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Confusing useradd (https://www.linuxquestions.org/questions/linux-newbie-8/confusing-useradd-95799/)

Arenba 09-23-2003 04:58 AM

Confusing useradd
 
Hi
When I was reading up some info. on installing Squid (to enable delay pools), I came across this "gem" of a useradd. It said:
useradd -d /cache/ -r -s /dev/null squid >/dev/null 2>&1
Can somebody please explain what it all means? I understood the options (-d -r -s) but the rest is Greek to me (I am not from Greece either).
What is this device/null ? (other than my head, of course..) And what are those 2>&1 at the end?
The command works......but, how, when, what, where, who...??
I need some enlightenment. :-)

Thanks

UltimaGuy 09-23-2003 05:26 AM

The /dev/null is just a file that fills its destination with null values. The term 2>&1 means that both the standard output and the standard error are both turned out towards a single stream,i.e., they both are now turned towards the console.

druuna 09-23-2003 05:27 AM

This is all the info useradd needs (and as you stated, you understand these):
useradd -d /cache/ -r -s /dev/null squid

That leaves you with:
>/dev/null 2>&1

This is called redirecting (changing the standard input/output destination).
There are 3 'default' file descriptors in linux/unix:

0 - standard input (stdin) - from keyboard.
1 - standard output (stdout) - to screen.
2 - standard error (stderr) - to screen.

>/dev/null (1>/dev/null, but you do not actually need the 1)
=> This puts the output from, in this example, useradd in /dev/null. This /dev/null is a bitbucket/blackhole, ie everything you put in is gone.

2>&1
=> duplicate standard error (file descriptor 2) to standard out (file descriptor 1)

So >/dev/null 2>&1 will redirect everything that's normally show on your screen to /dev/null.

The order is important (below a part from man bash about redirecting):
Quote:

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 as standard output
before the standard output was redirected to dirlist.
Hope this enlightens you a bit.

Arenba 09-23-2003 06:22 AM

Hi druuna and UltimaGuy,
Thanks for the info. and "redirecting" me. I thought it was some new kind of formula devised by Linus Torvalds to confuse us newbies (something like e=mc squared). :=)
I get the idea now.

Thanks


All times are GMT -5. The time now is 10:56 AM.