How to strip leading “./” in unix “find”?

前端 未结 7 1902
盖世英雄少女心
盖世英雄少女心 2020-11-29 17:14
find . -type f -print

prints out

./file1
./file2
./file3

Any way to make it print

file1
file2
fil         


        
相关标签:
7条回答
  • 2020-11-29 17:17

    it can be shorter

    find * -type f
    
    0 讨论(0)
  • 2020-11-29 17:23

    Use sed

    find . | sed "s|^\./||"
    
    0 讨论(0)
  • 2020-11-29 17:34

    Find only regular files under current directory, and print them without "./" prefix:

    find -type f -printf '%P\n'
    

    From man find, description of -printf format:

    %P     File's name with the name of the command line argument under which it was found removed.

    0 讨论(0)
  • 2020-11-29 17:35

    Since -printf option is not available on OSX find here is one command that works on OSX find, just in case if someone doesn't want to install gnu find using brew etc:

    find . -type f -execdir printf '%s\n' {} + 
    
    0 讨论(0)
  • 2020-11-29 17:38

    Another way of stripping the ./

    find * -type d -maxdepth 0
    
    0 讨论(0)
  • 2020-11-29 17:40

    Another way of stripping the ./ is by using cut like:

    find -type f | cut -c3-
    

    Further explanation can be found here

    0 讨论(0)
提交回复
热议问题