The Linux `chown` command

Unix/Linux file ownership FAQ: How do I use the chown command?

The chown command is most commonly used by Unix/Linux system administrators who need to fix a permissions problem with a file or directory, or many files and many directories.

For instance, suppose you want files to be owned by the user "nobody", but when you issue an ls command, you see that they're owned by the user "fred", like this:

$ ls -l
-rw-------   1 fred  groupfred   1459 May 7 12:18 ltr1.txt
-rw-------   1 fred  groupfred   8156 May 7 11:27 ltr2.txt

To fix the file ownership (permissions) problem, you use the Linux chown command. If you just want these files to be owned by the user nobody, you'd use this command:

chown nobody *txt

However, since these files are also in the group named "groupfred", you'll probably want to change the group as well. To change the owner and group in one command on Linux systems you can use this command:

chown nobody.nobody *txt

The way this works is that the first "nobody" string refers to the owner, and the second "nobody" string -- the one after the decimal -- refers to the group. Therefore, the general case looks like this:

chown owner.group file(s)

On older Unix systems you may have to use the chown and chgrp commands to achieve the same result, like this:

chown nobody *txt
chgrp nobody *txt

(Where "chown" means "change owner", "chgrp" means "change group".)

Linux chown - Be careful

If you're not the root user on your Unix or Linux system -- or even if you are -- be very careful with the chown and chgrp commands. Once you grant ownership of files to another user on your Unix/Linux system, guess what? You don't own them any more. This can lead to all sorts of nasty problems, such as not being able to delete the files.

Fortunately the chown and chgrp commands are commonly used by Unix system administrators (Unix 'root' users) and this isn't usually much of a problem, but I thought I better warn you about it anyway, as it can create a mess.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.