How to strip leading "./" in unix "find"?

UnixFindStrip

Unix 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbreadjesusView Question on Stackoverflow
Solution 1 - UnixIlia K.View Answer on Stackoverflow
Solution 2 - UnixLie RyanView Answer on Stackoverflow
Solution 3 - UnixTim GreenView Answer on Stackoverflow
Solution 4 - Unixghostdog74View Answer on Stackoverflow
Solution 5 - UnixbanjoAtixView Answer on Stackoverflow
Solution 6 - UnixanubhavaView Answer on Stackoverflow
Solution 7 - UnixValheruView Answer on Stackoverflow