Вопрос

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