Search code examples
linuxfind

Find command: I don't want to print the leading dot slash (./)


When I issue a find command:

$ find . -type f
./Makefile
./main.py
./pkg
./pkg/__init__.py

The output is almost what I want, except for the leading ./. I understand that I can use other commands such as sed to remove the part, but want to know if there is something within find which can accomplish the same?

My Expected output is:

Makefile
main.py
pkg
pkg/__init__.py

Solution

  • This will usually be equivalent:

    find * -type f
    

    The difference is if there are any dot-files in the current directory, they won't be included in the results because * doesn't match files that begin with ..

    This could also get a "command too long" error if the current directory has too many files (in the thousands).