0

I have a 3.2G file in /tmp called phpvXcoZn and I need to remove it. Therefore I'd like to know if it is still in use but the commands I typed returned nothing :

/tmp$ bigfile=phpvXcoZn
/tmp$ ll -h $bigfile
-rw------- 1 www-data www-data 3.2G Aug 25 09:49 phpvXcoZn
/tmp$ cd
$ sudo lsof | grep $bigfile
$ sudo fuser -avm /tmp 2>&1 | grep $bigfile
$ sudo ls -l /proc/*/fd/* 2>/dev/null | grep $bigfile
$ 

EDIT0: As @MarcusMüller suggested, I can try to unlink the file and the space usage will we freed when the file is closed but I cannot unlink that file belonging to www-data with sudo su :

$ sudo su www-data -c "unlink /tmp/phpvXcoZn"
This account is currently not available.
$ grep www-data /etc/passwd
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin

This command worked : sudo -u www-data bash -c "unlink /tmp/phpvXcoZn"

Do you other command to know if it is still in use ?

9
  • 1
    well, seems like it's not in use. Also, rming a file that is still open somewhere else has no effect on the program that has it still opened. It just can't be opened through the file name anymore – and as soon as it is closed, its storage can be freed. See man 2 unlink. Sep 9, 2022 at 9:48
  • @MarcusMüller Cannot unlink the file as the www-data user although I didn't use su -l to avoid using a login shell. I don't understand ?
    – SebMa
    Sep 9, 2022 at 10:17
  • why not simply sudo rm /tmp/phpvXcoZn? Sep 9, 2022 at 10:27
  • 1
    (it's very likely that it's intentional that www-data cannot be used through su, probably a secure linux rule that blocks this, and it's a good thing.) Sep 9, 2022 at 10:29
  • @MarcusMüller This worked : sudo -u www-data bash -c "unlink /tmp/phpvXcoZn". Thanks. Can you please convert your first comment to an answer so I can accept it ?
    – SebMa
    Sep 9, 2022 at 12:22

1 Answer 1

1

rming a file that is still open somewhere else has no effect on the program that has it still opened. It just can't be opened through the file name anymore – and as soon as it is closed, its storage can be freed. See man 2 unlink.

Your Answer

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

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