shell脚本 for循环实现文件和目录遍历
[root@localhost HeZuoShi_wt]# cat read_dir.sh #!/bin/bash #print the directory and file for file in /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/*; do if [ -d "$file" ]; then echo "$file is directory"; elif [ -f "$file" ]; then echo "$file is file"; fi; done [root@localhost HeZuoShi_wt]# ./read_dir.sh /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_01 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_02 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_03 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_04 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_05 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_06 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_07 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_08 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_09 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_10 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_11 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_12 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_13 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_14 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_15 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_16 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_17 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/EPSG_4326_18 is directory /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/read_dir.sh is file /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/卫图_中国_9至11级_4326瓦片.rar is file /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/卫图_全球_1至8级_无边界_4326瓦片.rar is file /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/卫图_合作市_15至17级_4326瓦片.zip is file /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/卫图_合作市_主城区_框选_18级_4326瓦片.zip is file /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/卫图_甘南藏族自治州_11至14级_4326瓦片.zip is file /disk2/oyz3dserver/oyz_HeZuoShi/geoserver/HeZuoShi_wt/卫图_甘肃省_12至13级_4326瓦片.rar is file [root@localhost HeZuoShi_wt]#
本文摘自 :https://www.cnblogs.com/