How to strip leading "./" in unix "find"?
UnixFindStripUnix Problem Overview
find . -type f -print
prints out
./file1
./file2
./file3
Any way to make it print
file1
file2
file3
?
Unix Solutions
Solution 1 - Unix
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.
Solution 2 - Unix
Use sed
find . | sed "s|^\./||"
Solution 3 - Unix
If they're only in the current directory
find * -type f -print
Is that what you want?
Solution 4 - Unix
it can be shorter
find * -type f
Solution 5 - Unix
Another way of stripping the ./
is by using cut
like:
find -type f | cut -c3-
Further explanation can be found here
Solution 6 - Unix
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' {} +
Solution 7 - Unix
Another way of stripping the ./
find * -type d -maxdepth 0