Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am working to get Mongodb running on a Ubuntu server install. In reviewing the instructions I needed to create a "\data\db" directory in the root drive. At which point I needed to alter the owner using the CHOWN command as follows:

sudo chown `id -u` /data/db

When I issue that command as it appears in the quick start guide I receive "chown: invalid user: 'id -u'.

I am new to Linux, so what I don't understand is what the 'id -u' was supposed to mean. When I replace with my user name the command completes just fine and mongo runs. Can someone help me understand what the short hand 'id -u' would communicate to an expert Linux user that it did not to me?

share|improve this question
add comment

3 Answers 3

up vote 10 down vote accepted

The command id -u prints out your "numeric user ID" (short: UID); as you already noticed, it is the same as spelling out your username in full on the chown command line. Indeed, the following command invocations should all have the same effect:

 sudo chown `id -u` /data/db
 sudo chown $USER /data/db

The reason why it did not work as expected has likely to do with the quotes: they have to be backquotes (ASCII char 0x60), whereas the chown error message suggests that you used single quotes (ASCII char 0x27).

You can find a very thorough explanation of UNIX shell quoting at: http://www.mpi-inf.mpg.de/~uwe/lehre/unixffb/quoting-guide.html#sect:shell-quot

share|improve this answer
2  
+1 for backticks. OP: There's a difference, in most shells, between "normal" single quotes (') and "backtick" quotes (`). Make sure you use the right ones. –  Ben Williams Aug 5 '10 at 13:20
    
Thank you, I did not even notice the subtle difference in quotes, nor did I know it would cause an issue. I really appreciate the detailed response. –  JPrescottSanders Aug 5 '10 at 14:28
add comment

It returns your user id. Run man id for more information.

share|improve this answer
add comment

id -u prints your user id on the system. As an alternative you can just run this command:

sudo chown <user> /data/db replacing <user> with your username on the system.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.