递归列出目录中的所有文件,但排除目录本身

The*_*hop 10 linux find search file-search

一个简单的问题,我正在运行以下 find 命令:

find . -type d \( -path ./.git -o   \
                  -path ./log -o    \
                  -path ./public -o \
                  -path ./tmp       \) \
                  -prune -o         \
                  -print
Run Code Online (Sandbox Code Playgroud)

列出我目录中的所有文件,不包括指定目录。

这很好用,但是,我还想做的是从输出中排除任何实际目录,因此如果有如下目录结构:

test
  -- foo.text
  -- bar.text
Run Code Online (Sandbox Code Playgroud)

当我运行我的命令时,我想看到:

./test/foo.text
./test/bar.text
Run Code Online (Sandbox Code Playgroud)

代替:

.
./test
./test/foo.text
./test/bar.text
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

unx*_*nut 11

find . -type f
Run Code Online (Sandbox Code Playgroud)

会做的。如果要对文件名进行操作,可以执行 exec 。


Sté*_*las 7

只需使用! -type d

find . -type d \( -path ./.git -o \
                  -path ./log -o \
                  -path ./public -o \
                  -path ./tmp \) -prune -o \
       ! -type d -print
Run Code Online (Sandbox Code Playgroud)