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

后端 未结 10 1387
故里飘歌
故里飘歌 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:45

    Honestly basename and dirname solutions are easier, but you can also check this out :

    find . -type f | grep -oP "[^/]*$"
    

    or

    find . -type f | rev | cut -d '/' -f1 | rev
    

    or

    find . -type f | sed "s/.*\///"
    

提交回复
热议问题