How to use chmod to change a file's permission?

0

I used ls -l to find file permissions in a shell and found this:

File 1: -rw-r--r-- 1 root root 451 Mar 9 15:25 file.class.php

File 2: -rw-rw-r-- 1 andy dev 872 Mar 9 15:43 file.class.php

I want file 1's permissions to be changed to file 2's permissions. I have root access and am cd'd to the proper directories. I have never used chmod before and am having some trouble. When I try to do this:

chmod 872 file.clas.php

I get the error: chmod: invalid mode: '872'

John Smith

Posted 2013-03-09T21:02:55.663

Reputation: 125

0664, or just chmod g+w – Wrikken – 2013-03-09T21:06:15.007

Answers

3

That 5th column is the filesize, not the permissions. The permissions are listed on the left in expanded form. The permissions on the first file are 644 in octal (add up the contributions from each bit: r-- = 4, -w- = 2, --x = 1, so rw- = 6), and the permissions on the second file are 664. Therefore, you want

chmod 664 file.class.php

Alternately, remember that the three permission groups are user, group and other, so rw-rw-r-- is "user rw, group rw, other r". Then, to change rw-r--r-- into rw-rw-r--, you need to add group-write permissions, i.e.

chmod g+w file.class.php

This lets you update the permissions individually.

nneonneo

Posted 2013-03-09T21:02:55.663

Reputation: 901

Hmm. The permissions changed successfully but I still can't seem to save the file while connected to the server in Notepad++. It's located on a server and I created it with a root account instead of a user account and even with the different permissions the upload is failing. Any idea what it might be? Are there other permissions I could change? – John Smith – 2013-03-09T21:10:11.850

The 3rd and 4th columns are the user and group who own the file. The first file is owned by root:root and the second file by andy:dev. So, you want to change the owner of the first file to andy:dev: chown andy:dev file.class.php – nneonneo – 2013-03-09T21:12:11.210