方案1
- /d/video/为此目录路径
filelist='ls /d/video/*'
for file in $filelist
do
#echo $file
dir2=`echo $file | sed "s/\// /g"`
dir2=`echo $dir2| awk 'NR==1{print $NF}'`
echo $dir2
done
方案2
- 可以处理空格文件打印输出
#!/usr/bin/env bash –xv
down_path=/D/download/满分作文
#设置单词分割符
IFS=$(echo -en "\n\b")
#文件目录
lst=`ls ${down_path}`
#还原单词分割符
IFS=$(echo -en "\n\t")
for itm in ${lst};do
if test -e ${down_path}/${itm}; then
echo ${itm}
fi
done
方案3
ls -al | awk '{print $9}'
网友评论