Changing Permissions on Files & Folders in Shell

March 18, 2008

Chmod is the most widely-used command line perhaps in Shell. In dedicated server hosting, it’s very important to know these shell commands and even memorize them so you can run your dedicated server efficiently and affordably.

Since permissions on files and folders will often require changing or altering, you can do so with the chmod command.

For example, “chmod 755 foldername” will set a folder to 755 as seen below:

[root@restoretmp diva]# ls -l
total 4
-rw-r–r–    1 root     root            0 May  4 05:47 file.html
drw-r–r–    2 root     root         4096 May  4 05:48 public_html
[root@restoretmp diva]#

public-html” is set at chmod 644.

But type “chmod 755 public_html” and then look again using “ls-l

[root@restoretmp diva]# chmod 755 public_html
[root@restoretmp diva]# ls -l
total 4
-rw-r–r–    1 root     root            0 May  4 05:47 file.html
drwxr-xr-x    2 root     root         4096 May  4 05:48 public_html
[root@restoretmp diva]#

Where it states “drwxr-xr-x is 755” the “d” means it is a directory

Changing Ownership

Since the file.html is currently owned by root, you can change this ownership to yourself (chown):

Type “chown diva:diva file.html” and you’ll see:

[root@restoretmp diva]# chown diva:diva file.html
[root@restoretmp diva]# ls -l
total 4
-rw-r–r–    1 diva    diva           0 May  4 05:47 file.html
drwxr-xr-x    2 root     root         4096 May  4 05:48 public_html
[root@restoretmp diva]#

As you can see, “diva” is now made the owner, or you will own it in its place!

More Dedicated Web Hosting Help!

Comments are closed.