164
find . -type f -print

打印出来

./file1
./file2
./file3

任何让它打印的方法

file1
file2
file3

?

4

7 回答 7

286

Find only regular files under current directory, and print them without "./" prefix:

find -type f -printf '%P\n'

From man find, description of -printf format:

%P     File's name with the name of the command line argument under which it was found removed.

于 2010-04-08T00:10:07.080 回答
65

使用 sed

find . | sed "s|^\./||"
于 2010-04-07T22:57:41.670 回答
42

如果它们仅在当前目录中

find * -type f -print

那是你要的吗?

于 2010-04-07T22:57:38.893 回答
9

它可以更短

find * -type f
于 2010-04-07T23:45:48.070 回答
7

Another way of stripping the ./ is by using cut like:

find -type f | cut -c3-

Further explanation can be found here

于 2019-09-05T06:05:55.897 回答
3

由于-printf选项在 OSX 上不可用,find这里有一个适用于 OSX 查找的命令,以防万一有人不想gnu find使用brewetc 安装:

find . -type f -execdir printf '%s\n' {} + 
于 2020-06-04T20:11:51.060 回答
2

另一种剥离 ./

find * -type d -maxdepth 0
于 2020-03-18T10:40:13.890 回答