Linux学习5之shell显示当前目录下所有的文件和文件夹

hadoop@Mcnode4:~/cloud/adam/xubo/data/test20160310/bwa3sh/test142234$ cat showFileAndDirectory.sh 
#!/bin/bash

dir=$(ls -l ./ |awk '!/^d/ {print $NF}')
for i in $dir
do
    echo "File:"$i
done

dir=$(ls -l ./ |awk '/^d/ {print $NF}')
for i in $dir
do
    echo "Directory:"$i
done

结果:

hadoop@Mcnode4:~/cloud/adam/xubo/data/test20160310/bwa3sh/test142234$ ./showFileAndDirectory.sh 
File:4917568
File:a.sh
File:sam2bam.sh
File:showDirectory.sh
File:showFileAndDirectory.sh
File:SRR003161h100000t1.sai
File:SRR003161h100000t1.sam
File:SRR003161h100000t2.sai
File:SRR003161h100000t2.sam
File:SRR003161h100000t3.sai
File:SRR003161h100000t3.sam
File:SRR003161h10000t1.sai
File:SRR003161h10000t1.sam
File:SRR003161h10000t2.sai
File:SRR003161h10000t2.sam
File:SRR003161h10000t3.sai
File:SRR003161h10000t3.sam
File:SRR003161h1000t1.sai
File:SRR003161h1000t2.sai
File:SRR003161h1000t2.sam
File:SRR003161h1000t3.sai
File:SRR003161h1000t3.sam
File:SRR003161h20t1.bam
File:SRR003161h20t1.sai
File:SRR003161h20t1.sam
File:SRR003161h20t1Sort.bam
File:SRR003161h20t1.sorted.bam
File:SRR003161h20t2.sai
File:SRR003161h20t2.sam
File:SRR003161h20t3.sai
File:SRR003161h20t3.sam
File:SRR003161t1.bam
File:SRR003161t1.sai
File:SRR003161t1.sam
File:SRR003161t2.sai
File:SRR003161t2.sam
File:SRR003161t3.sai
File:SRR003161t3.sam
File:te.sh
Directory:fff

    原文作者:KeepLearningBigData
    原文地址: https://blog.csdn.net/bob601450868/article/details/50899645
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞