检查/etc/resolv.conf是否为空的shell脚本
时间: 2023-12-19 19:07:14 浏览: 124
linux里etc下的文件解析
4星 · 用户满意度95%
#!/bin/bash
if [[ ! -s "/etc/resolv.conf" ]]; then
echo "The file /etc/resolv.conf is empty"
else
echo "The file /etc/resolv.conf is not empty"
fi
Explanation:
This script checks if the file /etc/resolv.conf is empty or not. The "-s" option of the "test" command (also known as "[") returns true if the file exists and has a size greater than zero. The "!" operator negates the test, so the script echoes a message indicating that the file is empty if the test fails (i.e., the file does not exist or has a size of zero). If the test succeeds, the script echoes a message indicating that the file is not empty.
阅读全文