Is there a built-in way for find to not display the initial path in the results? Ideally a built-in option or a simple -printf argument.

For example, find initial/path returns:

initial/path/file1
initial/path/dir1/file1
initial/path/dir1/file2

I would like to just have:

file1
dir1/file1
dir1/file2

Things I've tried:

1) cd to the initial path first.

cd initial/path
find

But that gives ./file1, it still includes an extra ./

2) find initial/path | sed 's,^initial/path/,,'

This works, but it just seems to be unnecessary/extra processing if there is a better way.

有帮助吗?

解决方案

With GNU find:

find some/dir -printf '%P\n'

More info

%P    File's  name  with  the  name of the starting-point under
      which it was found removed.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top