Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-23-2003, 04:58 AM   #1
Registered: Sep 2003
Location: India
Distribution: Red Hat 8
Posts: 51

Rep: Reputation: 16
Confusing useradd

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. :-)

Old 09-23-2003, 05:26 AM   #2
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
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.
Old 09-23-2003, 05:27 AM   #3
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400
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.

=> 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):
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.
Old 09-23-2003, 06:22 AM   #4
Registered: Sep 2003
Location: India
Distribution: Red Hat 8
Posts: 51

Original Poster
Rep: Reputation: 16
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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mplayer confusing me subh Debian 6 11-30-2005 03:29 PM
What is confusing my Intel536ep? bobzilla Debian 1 11-24-2005 07:34 PM
so confusing c12ayon Programming 5 10-26-2003 11:52 PM
Very confusing rm Luc Linux - Newbie 3 11-04-2002 01:42 PM
Kernel Confusing??? jISV Linux - Software 6 03-31-2002 11:52 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:30 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration