bash shell 文件比较

我们可以使用以下运算符进行比较和检查文件:

  • -d my_filebash shell检查是否为文件夹。

  • -e my_filebash shell检查文件是否可用。

  • -f my_filebash shell检查它是否是文件。

  • -r my_filebash shell检查它是否可读。

  • my_file nt my_file2bash shell检查my_file是否比my_file2更新。

  • my_file ot yot_file2bash shell检查my_file是否比my_file2大。

  • -o my_filebash shell检查文件的所有者和记录的用户匹配。

  • -g my_filebash shell检查文件和记录的用户是否具有相同的组。

示例:

#!/bin/bash
mydir=/home/onitroad
if [ -d $mydir ]; then
	echo "Directory $mydir exists"
	cd $mydir
	ls
else
	echo "NO such file or directory $mydir"
fi
日期:2020-07-15 11:16:51 来源:oir作者:oir