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


what is the meaning of id -u

  • @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 ` – wkl 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. – Fred Foo Sep 22 '11 at 14:24
  • @birryree, I tried and it doesn't work for me. – q0987 Sep 22 '11 at 14:26

$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
| 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.

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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