Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have seen two usages of chown that is used for changing file owner and group

chown -R $USER:$USER /data/db

What is the meaning of $USER:$USER

chown `id -u` /data/db

http://www.mongodb.org/display/DOCS/Quickstart+Unix

what is the meaning of id -u

share|improve this question

migrated from stackoverflow.com Sep 22 '11 at 20:09

This question came from our site for professional and enthusiast programmers.

    
@larsmans, can you tell me how did you make it so that ` is displayed? –  q0987 Sep 22 '11 at 14:22
1  
Escape it with "\", so "\'" within a code portion will display the ` –  birryree Sep 22 '11 at 14:23
2  
I put four spaces before the commands. Backticks are used on SO to put code samples inline in text. –  larsmans Sep 22 '11 at 14:24
    
@birryree, I tried and it doesn't work for me. –  q0987 Sep 22 '11 at 14:26

3 Answers 3

up vote 2 down vote accepted

$USER is an environment variable that always holds the username of the real or system user executing the command. id -u returns the executing user's UID number. chown will accept either the user name or UID.

# on my system here:

$ echo $USER
# michael

$ id -u
# 500

$USER:$USER is used to set ownership of the file/directory to the user as primary owner and the user's group as group owner. Many Linux distributions create a dedicated group for each user. To see yours,

cat /etc/group
share|improve this answer

$USER is a variable that expands to the username of the user executing a command.

id -u

prints the user identification number (UID) of the current user.

chown `id -u` /data/db

runs the command id -u, takes its output (by the backquotes), and passes that to chown as the first argument, so ownership of /data/db is given to the user executing the command.

share|improve this answer

the first $USER variable is the new owner and the 2nd is the new GROUP

id -u will be executed before your chown execution. it will give you the uid.

share|improve this answer

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.