简体   繁体   English

命令清理我的Web服务器上的tmp目录

[英]command to clean tmp directory on my web server

I was getting write failed: No space left on device (28) in my websites. write failed: No space left on device (28)我网站write failed: No space left on device (28) So I checked my tmp size using ssh and it was 100% full. 所以我用ssh检查了我的tmp大小,它是100%满的。

What command can I use through ssh to free up space in the tmp directory? 我可以通过ssh使用什么命令来释放tmp目录中的空间?

cd /tmp
rm -fr *

With PHP I don't know if you have permission to delete the files: 使用PHP我不知道您是否有权删除文件:

$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. 您需要使用包含临时文件的目录路径调整/path/to/tmp

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/ rm -rf tmp /

Recursively deletes the directory tmp, and all files in it, including subdirectories. 递归删除目录tmp及其中的所有文件,包括子目录。 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. 但为了避免它在未来建立一个cron工作,以定期整理。

Look into using find system command to find old files that can be safely deleted (ie temporary files that will not be in use). 查看使用find system命令查找可以安全删除的旧文件(即不使用的临时文件)。

You can remove the file inside the tmp directory just go to the tmp directory 您可以删除tmp目录中的文件,只需转到tmp目录即可

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) (如果这不是您要清理的文件夹,请替换/ tmp /)

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

Edit your cron table: 编辑你的cron表:

$> 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. 要永久删除 / tmp中的所有文件(每日),这是一整天的日子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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