我希望能使用grep来检查,看看是否权限已正确设置上的文件...我如何在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
它看起来像grep的不想要搜索的“ - ”字符.. 。
任何绕过这个方法?
谢谢!
你是怎么推断的grep是无视“ - ”字符? – vinothkr 2011-05-31 05:19:50