shell判断当前文件是否存在目录,存在则跳过

#获取指定目录下的所有文件名

path=/home/data

files=$(ls ${path})

for filename in $files

do

#判断文件是不是目录,是就跳过

   if [ -d ${path}/$filename ]

   then
        
        echo "$fliename是一个目录"

        continue

    fi
        echo "$filename是普通文件"

   done

灵活的使用for循环和if判断,可快速得到指定目录下的非目录文件或者普通文件。

猜你喜欢

转载自blog.csdn.net/c_shell_python/article/details/81135169