linux文件脚本操作
1,判断文件目录是否存在
echo "请输入您要查询的目录路径:"
read file
path=
$file
if [ -d $
{path
} ];then
echo $
{path
} exists
!
else
echo $
{path
} not exists
!
fi
2,判断文件是否存在
file =
"/home/bai.txt"
if [ -f $
{file
} ];then
echo $
{file
} exists
!
else
echo $
{file
} not exists
!
fi
3,如果目录存在,则在目录下创建10个文件目录,以dir01,dir02…dir10命名,用shell脚本实现
path=
"/home/bai"
if [ -d $
{path
} ];then
mkdir $
(seq
-f
'dirg' 1 10
)
else
echo "文件目录不存在"
fi
4,shell获取当前目录,并将赋值给其他变量,假设当前目录为/home/bai/
path=$
(pwd)
pdir=$
{path
}/test