如果缓存目录变得太大,我正在写一个小的脚本来通过CRON清除我的linux上的空间.因为我真的很喜欢bash脚本,所以我需要你的linux专家的一些帮助.
这里基本上是逻辑(伪代码)
if ( Drive Space Left < 5GB )
{
change directory to '/home/user/lotsa_cache_files/'
if ( current working directory = '/home/user/lotsa_cache_files/')
{
delete files in /home/user/lotsa_cache_files/
}
}
Run Code Online (Sandbox Code Playgroud)
我打算从'/ dev/sda5'命令中获取驱动器空间.如果您的信息返回以下值:
Filesystem 1K-blocks Used Available Use% Mounted on<br>
/dev/sda5 225981844 202987200 11330252 95% /
Run Code Online (Sandbox Code Playgroud)
因此,可能需要一点正则表达式才能使'11330252'超出返回值
'if(当前工作目录=/home/user/lotsa_cache_files /)'部分只是我内心偏执的一种防御机制.在我继续执行delete命令之前,我想确保我确实在'/ home/user/lotsa_cache_files /'中,如果当前工作目录由于某种原因不存在,则该命令可能具有破坏性.
删除文件将使用以下命令而不是通常的rm -f完成:
find . -name "*" -print | xargs rm
Run Code Online (Sandbox Code Playgroud)
这是因为Linux系统固有的无法"rm"目录,如果它包含太多文件,正如我过去所了解的那样.
如何执行目录列表但仅显示目录?
我试过ls | grep'/'但它被错误拒绝了: usage:ls remote-directory local-file
这是因为FTP中的命令行与通常的linux命令行不同,但我想知道FTP命令中是否有相同的东西
提前致谢
我一直在使用一段漂亮的PHP代码通过cURL将文件上传到FTP.它一直很好,直到今天.
执行时返回卷曲错误#3错误解释:CURLE_URL_MALFORMAT(3):URL格式不正确.我认为这是因为密码包含特殊字符.密码包含'<',例如R3lHK2A9 <1此代码适用于过去密码全部仅由字母和数字组成的密码.
我尝试使用escapeshellarg(),urlencode()并escapeshellcmd()密码....徒劳.我错过了什么吗?
你能帮忙吗?
<?php
$ch = curl_init();
$localfile = “test.tar”;
$fp = fopen($localfile, ‘r’);
curl_setopt($ch, CURLOPT_URL, ‘ftp://username:password@ftp.domain.com/public_html/filesfromscript/’.$localfile);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
if ($error_no == 0) {
$message = ‘File uploaded successfully.’;
} else {
$message = “File upload error: $error_no. Error codes explained here http://curl.haxx.se/libcurl/c/libcurl-errors.html”;
}
echo $message;
?>
Run Code Online (Sandbox Code Playgroud) 我一直在尝试将 Twilio 的复杂时间格式(2015 年 10 月 21 日星期三 19:19:53 +0000)转换为时间戳,以便我可以将其格式化为 PHP 中更容易理解的格式。我尝试过各种方法,但没有一个有效。
有人可以解释一下吗?