zoukankan      html  css  js  c++  java
  • Shell获取某个文件夹下的所有文件名(含文件夹)

    1. 获取某个文件夹下的所有文件名(含文件夹),并显示

    #!/bin/sh 
    #============ get the file name =========== 
    Folder_A="/home/youname/shell/gotfilename/bin" 
    for file_a in ${Folder_A}/*
    do 
    temp_file=`basename $file_a` 
    echo $temp_file 
    done

    2、若要去掉文件名的后缀(假如该文件夹下的所有文件为.txt格式),则代码为

    #!/bin/sh 
    #============ get the file name =========== 
    Folder_A="/home/youname/shell/gotfilename/bin" 
    for file_a in ${Folder_A}/*
    do 
    temp_file=`basename $file_a .txt` 
    echo $temp_file 
    done

    3、如果要输出到一个文件的话也可以重定向到一个文件中去

    #!/bin/sh 
    #============ get the file name =========== 
    Folder_A="/home/Neo/shell/gotfilename/bin" 
    Output_file="output.txt" 
    #这里用于清空原本的输出文件,感觉 : 这个符号用处挺大,shell的学习还是要多用才是 
    : > $Output_file 
    for file_a in ${Folder_A}/*
    do 
    temp_file=`basename $file_a` 
    echo $temp_file >> $Output_file 
    done

    4、增加了交互性

    #!/bin/sh 
    #============ get the file name =========== 
    echo -e "请输入你要读取的文件夹路径\n当前路径为${PWD}" 
    read InputDir 
    echo "你输入的文件夹路径为${InputDir}" 
    echo -e "请输入你要将数据输出保存的文件路径n当前路径为${PWD}" 
    read OutputFile 
    echo "输出保存的文件路径为${OutputFile}" 
    : > $OutputFile #清空OutputFile 
    #循环读取文件夹名 
    for file_a in ${InputDir}/*
    do 
    temp_file=`basename $file_a` 
    echo $temp_file >> $OutputFile 
    done
    如果错过太阳时你流了泪,那你也要错过群星了。
    在所有的矛盾中,要优先解决主要矛盾,其他矛盾也就迎刃而解。
    不要做个笨蛋,为失去的郁郁寡欢,聪明的人,已经找到了解决问题的办法,或正在寻找。
  • 相关阅读:
    完全图解scrollLeft,scrollWidth,clientWidth,offsetWidth 获取相对途径,滚动图片
    Input的size,width,maxlength属性
    Linux,VI命令详解
    Javascript 第十章
    Javascript 第七章
    IE css hack
    Javascript 第九章
    js中document.documentElement 和document.body 以及其属性
    关于xmlhttp.status == 0的问题
    Javascript 第八章
  • 原文地址:https://www.cnblogs.com/szrs/p/15662707.html
Copyright © 2011-2022 走看看