获取不包括父文件夹名称的文件目录

Meh*_*taş 3 command-line directory find

我想获取包含特定文件的目录名称,但排除父目录名称。

例如:

find ./app -name '*.component.html';
Run Code Online (Sandbox Code Playgroud)

当我使用此命令时,它返回如下所示的结果:

./app/register/register.component.html
./app/_directives/alert.component.html
./app/app.component.html
./app/home/home.component.html
./app/login/login.component.html
Run Code Online (Sandbox Code Playgroud)

但我想得到没有./app. 可以通过进入app目录来完成,如下所示:

cd app; find -name '*.component.html';

./register/register.component.html
./_directives/alert.component.html
./app.component.html
./home/home.component.html
./login/login.component.html
Run Code Online (Sandbox Code Playgroud)

但我想用一个命令来完成它,而不输入app. 我怎样才能做到这一点?

ste*_*ver 5

使用 GNU find,您可以使用

find ./app -name '*.component.html' -printf '%P\n'
Run Code Online (Sandbox Code Playgroud)

来自-printf以下部分man find

    %P     File's name with the name  of  the  starting-point  under
           which it was found removed.
Run Code Online (Sandbox Code Playgroud)