我希望使用grep检查并查看是否已在文件上正确设置权限...
我知道下面的情况可能并不理想,并不尽可能简洁,但我追求的是个人财产,如所有者名称和权限......
我打算用这样的东西:
cd ~/Desktop
if [ `ls -a | grep My File.txt | wc -l` -eq 1 ];
then
echo "My File.txt Exists"
MYPERMISSIONS=`ls -l My File.txt`
if [ `$MYPERMISSIONS | grep $"\-rwxr\-xr\-x" | wc -l` -eq 1 ];
then
echo "Permissions are correct for My File.txt"
fi
if [ `$MYPERMISSIONS | grep $"\-rwxr\-xr\-x" | wc -l` -eq 0 ];
then
echo "Permissions are NOT correct for My File.txt"
fi
if [ `$MYPERMISSIONS | grep root | wc -l` -eq 1 ];
then
echo "Owner is correct for My File.txt"
fi
if [ `$MYPERMISSIONS | grep root | wc -l` -eq 0 ];
then
echo "Owner is NOT correct for My File.txt"
fi
fi
if [ `ls -a | grep My File.txt | wc -l` -eq 0 ];
then
echo "My File.txt does NOT Exist"
fi
Run Code Online (Sandbox Code Playgroud)
貌似grep不想搜索" - "字符......
有什么办法绕过这个?
谢谢!
| 归档时间: |
|
| 查看次数: |
2115 次 |
| 最近记录: |