I have set 000 permission for a single file writing this code:

sudo chmod 000 ./Desktop/*.gif

But still this file is deletable and renameable (but not readable).

Although this code:

sudo chmod 000 ./Desktop/Directory_name

makes the directory inaccessible (read,write,execution protected).

What's wrong ?

  • 6
    This is pretty well addressed in the Unix & Linux question Why can rm remove read-only files? – G-Man Says 'Reinstate Monica' Dec 15 '15 at 10:09
  • 2
    P.S. I encourage you to avoid giving files names with asterisks in them; especially short ones like *.gif.  (Your question indicates that you have "a single file" called *.gif.)  Also, you don't need the ./ at the beginning of the pathname. – G-Man Says 'Reinstate Monica' Dec 15 '15 at 10:12
  • @G-Man, good suggestion. Actually I had only 1 .gif file in Desktop, So that selected a single file (I am sorry that, that is ambiguous for others) – partho Dec 15 '15 at 13:30
  • You don't need to use sudo to change the permissions for your own files. Hence, chmod 000 Desktop/*.gif will do just as well. – Paddy Landau Dec 22 '15 at 8:18

What's wrong?

Nothing. Removing all permissions from a file does not prevent deletion or renaming - those are controlled by the permissions of the containing directory (Desktop, in this case). If you want to prevent deletion or renaming, remove write permissions from the directory:

chmod a-w Desktop

Or make the files immutable:

sudo chattr +i Desktop/*.gif

rm will ask you if you want to delete an immutable file, but it can't:

$ rm foo
rm: remove write-protected regular file ‘foo’? y
rm: cannot remove ‘foo’: Operation not permitted
  • 4
    Real-life analogy: you don't need to shoot someone in the head to remove them from the phone book. – Jörg W Mittag Dec 15 '15 at 12:55
  • 6
    Though people usually don't die from not being listed in any phone books. – jwodder Dec 15 '15 at 13:29
  • @cjm I read it as a double-negative. Maybe I should have read that a few more times... – Canadian Luke Dec 15 '15 at 21:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.