Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I automatically cleanup failed uploads? PHP is storing them in /tmp and all file names look like phpAbCDeF (basically php followed by 6 characters).

I know that I can use the command:

find /tmp -name php\*

BUT this also removes other temp files that begins with php (created by other processes) that I don't want to delete.

Please suggest a solution.

share|improve this question
add comment

1 Answer

It depends on how your files are named. Here are some suggestions:

  1. delete all files whose name is php followed by exactly 6 characters:

    find /tmp -type f -name 'php??????' -delete
    
  2. Delete all files whose name starts with php and which are empty:

    find /tmp -type f -name "php*"  -empty -delete
    
  3. A better way would be to edit your server's php-ini file and set the variable upload_tmp_dir. That way, you can just delete everything in that directory. For example, if you set this in your php.ini:

    upload_tmp_dir=/tmp/phptmp
    

    You can then simply remove all files from the folder:

    rm  /tmp/phptmp/*
    
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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