How to use chmod to change a file's permission?
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.
Related videos on Youtube
John Smith
Updated on September 18, 2022Comments
-
John Smith over 1 year
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'
-
Wrikken about 11 years0664, or just
chmod g+w
-
-
John Smith about 11 yearsHmm. 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?
-
nneonneo about 11 yearsThe 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 byandy:dev
. So, you want to change the owner of the first file toandy:dev
:chown andy:dev file.class.php