chown and chmod Command

Image

I feel like there might be a need for me to change the ownership of certain files in my Raspberry Pi directory.

I’m not sure why my web2py files are in www-data whose owner is the root. As i will continue doing the tutorial from Killer Web Development, i guess i might have to access that file quite often, which may be risky if it is still under the root. And it was suggested by one of the community member at this forum thread.

I found some useful information from How to use chmod and chown Command, and i would like to share with you (and to keep a record for my future use).

So what are they use for?

chmod – to change file access permissions such as read, write, and access

chown – to change file owner and group information

Syntax for chown:

chown owner-user file
chown owner-user:owner-group file
chown owner-user:owner-group directory
chown options owner-user:owner-group file

To list down the permission for a certain file:

# ls -l /home/www-data/web2py/applications

which will return something stating the owner of the files.

Since it is a directory, i would like to change the ownership and group of it. so i typed:

sudo chown -R pi:pi /home/www-data/web2py/applications

Then list the permission:

ls -l /home/www-data/web2py/applications

which will return pi as the owner and group name of the files now.

Other syntax can be used similarly.

1. Change file ownership only

chown owner-user file

2. Change file and group ownership

chown owner-user:owner-group file

3. Change group ownership only

chown :owner-group file

4. Change none

chown : file

5. Change to root

chown root:owner-group file

6. Change the ownership of the subfiles as well

chown -R owner-user:owner-group file

-R – Recursively change ownership of directories and their contents

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s