简体   繁体   中英

command to clean tmp directory on my web server

I was getting write failed: No space left on device (28) in my websites. So I checked my tmp size using ssh and it was 100% full.

What command can I use through ssh to free up space in the tmp directory?

cd /tmp
rm -fr *

With PHP I don't know if you have permission to delete the files:

$files = glob('/tmp/*');
foreach($files as $file){
   if(is_file($file)){
       unlink($file);
   }
}

You just need to remove the files

rm -rf /path/to/tmp/*

You need to adjust /path/to/tmp with the path to your directory containing the temp files.

Warning: Please keep in mind, that all removed files are truly removed (= lost). So check all parameters first, before using this command.

rm -rf tmp/

Recursively deletes the directory tmp, and all files in it, including subdirectories. And better be careful with this command!!

To overcome your problem do what one of the posters has suggested.

But to avoid it in the future set up a cron job to tidy up periodically.

Look into using find system command to find old files that can be safely deleted (ie temporary files that will not be in use).

You can remove the file inside the tmp directory just go to the tmp directory

cd tmp/

and run the following command

rm -rf ./

It will delete all the directories inside that directory.

and

rm -rf *.*

It will delete all the files inside that directory.

Test this command. It shows the files?

(replace /tmp/ if this is not the folder you wanted to clean up)

find /tmp/ -mtime +6 -exec ls   {} \;

Edit your cron table:

$> crontab -e

Add a line:

* 6 * * * find /tmp/ -mtime +6 -exec rm -r   {} \;

To permanently delete all files (daily) in /tmp, that are a handfull of days old.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM