欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

shell脚本 for循环实现文件和目录遍历 有大用

#!/bin/bash 
#print the directory and file 

for file in /home/hustyangju/*  

do 
if [ -d "$file" ] 
then   
  echo "$file is directory" 
elif [ -f "$file" ] 
then 
  echo "$file is file" 
fi 
done 


[cpp] view plain copy        
  1. 一个for循环实现一个目录下的文件和目录遍历,很实用  

[cpp] view plain copy        
  1. [root@localhost shell_order]# cat test27.sh   

  2. #!/bin/bash  

  3. #print the directory and file  

  4.   

  5. for file in /home/hustyangju/*  

  6. do  

  7. if [ -d "$file" ]  

  8. then   

  9.   echo "$file is directory"  

  10. elif [ -f "$file" ]  

  11. then  

  12.   echo "$file is file"  

  13. fi  

  14. done  

  15. [root@localhost shell_order]# ./test27.sh   

  16. /home/hustyangju/array is directory  

  17. /home/hustyangju/menuwindow-7.12 is directory  

  18. /home/hustyangju/menuwindow-build-desktop is directory  

  19. /home/hustyangju/shell_order is directory  

  20. [root@localhost shell_order]#   

来自  https://blog.csdn.net/hustyangju/article/details/48286843


看 views 目录下有什么东西 ,下面是自己亲自做的 有大用 

for file in /home/wwwroot/*/public_html/resources/views/* ; do

  echo $file >> views.txt;

done


普通分类: