How to only get file name with Linux 'find'?

后端 未结 10 1367
故里飘歌
故里飘歌 2020-11-28 18:19

I\'m using find to all files in directory, so I get a list of paths. However, I need only file names. i.e. I get ./dir1/dir2/file.txt and I want to get fi

10条回答
  •  执念已碎
    2020-11-28 18:37

    If you are using GNU find

    find . -type f -printf "%f\n"
    

    Or you can use a programming language such as Ruby(1.9+)

    $ ruby -e 'Dir["**/*"].each{|x| puts File.basename(x)}'
    

    If you fancy a bash (at least 4) solution

    shopt -s globstar
    for file in **; do echo ${file##*/}; done
    

提交回复
热议问题