1

A friend of mine has one directory (/var/mail) on his Linux machine where rm seems to truncate files if he has no write permissions on the directory. I like this feature and wonder how could I do the same on my Linux box?

This is the behavior what I want:

$ mkdir /tmp/nase
$ echo "something" > /tmp/nase/bla
$ chmod ugo-w /tmp/nase
# ...do some more tricks with /tmp/nase ...

$ rm /tmp/nase/bla
rm: cannot remove ‘/tmp/nase/bla’: Permission denied
# but the file is truncated now:
$ stat -c '%s' /tmp/nase/bla
0

On my friends machine /var/mail is an NFS mount with these permissions:

drwxrwsr-x  2 root postdrop 4096 Dec  8  2005

The NFS server is probably a SUN machine.

One more general technical NFS question: Does the "permission denied" error come from the client only or from server?

  • Just make a function called rm, check the permissions of the dir, if you have exec access run real rm, if not then copy /dev/null into the file. – 123 Dec 8 '16 at 14:50
  • 1
    Or just use > file. – terdon Dec 8 '16 at 14:58
  • @terdon but do they "know" CLOBBER? – thrig Dec 8 '16 at 15:23
  • @terdon Does that work on everything? I can never remember. – 123 Dec 8 '16 at 15:32
  • As far as I know, yes. – terdon Dec 8 '16 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.