linux - Bash 脚本 - 文件大小

标签 linux bash

我有一个 bash 脚本。为了安全起见,我需要 retrofit 。

我原来的 bash 脚本:

mv /home/script/backup /home/script/backup2
mysql -u user -ppassword -Ddatabase --batch --skip-column-names -e 'select id, url from videos where url like "%http%" limit 1' | 
while read id url

do youtube-dl -o "/home/script/uploads/$id.mp4" -f 18/17/22/mp4 "$url"
done

mysql -u user -ppassword -Ddatabase -e "UPDATE videos SET url=CONCAT(id,'.mp4') WHERE url LIKE '%http%' limit 1" ;

mysql -u user -ppassword -Ddatabase -e "UPDATE videos SET source_id='1' WHERE source_id in (3) limit 1";

mv /home/script/backup2 /home/script/backup

exit

我需要这个 bash 脚本:

mv /home/script/backup /home/script/backup2
mysql -u user -ppassword -Ddatabase --batch --skip-column-names -e 'select id, url from videos where url like "%http%" limit 1' | 
while read id url

do youtube-dl -o "/home/script/uploads/$id.mp4" -f 18/17/22/mp4 "$url"
done

这里:我想检查文件大小。如果它大于 10 KB,我想运行以下所有命令。

mysql -u user -ppassword -Ddatabase -e "UPDATE videos SET url=CONCAT(id,'.mp4') WHERE url LIKE '%http%' limit 1" ;

mysql -u user -ppassword -Ddatabase -e "UPDATE videos SET source_id='1' WHERE source_id in (3) limit 1";

mv /home/script/backup2 /home/script/backup

exit

如果小于 10 KB 或找不到文件,我只想运行此命令。

mv /home/script/backup2 /home/script/backup

exit

最佳答案

要获取以字节为单位的文件大小,您可以使用 stat程序。有关此类型的更多信息 man stat进入命令行。 stat -c %s <file path>将以字节为单位输出文件大小,然后您应该可以检查。

关于linux - Bash 脚本 - 文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23591952/

相关文章:

linux - !# :3? 是什么意思

linux - Bash 模式匹配

windows - 安装 cygwin 后 Git Bash 损坏

android - 通过 Wifi-Direct 连接 Linux 和 Android(BeagleBone Black 和 Android-app)

c++ - 使用 Optimus 技术让 OpenCL 在 Linux 笔记本电脑上运行

用于递归查找字符串的正则表达式?

linux - 如何在没有显示器的情况下使用gui启动linux?

bash - 在 Bash if 条件下使用 (( ... )) 时出错

bash - 从shell脚本中的行首删除字符?

c++ - 将字节数组转换为 time_t