我如何吐出一行递归路径的平面列表?

例如,我只想要一个文件的完整路径的平面列表:

/home/dreftymac/.
/home/dreftymac/foo.txt
/home/dreftymac/bar.txt
/home/dreftymac/stackoverflow
/home/dreftymac/stackoverflow/alpha.txt
/home/dreftymac/stackoverflow/bravo.txt
/home/dreftymac/stackoverflow/charlie.txt

ls -a1几乎满足了我的需要,但我不想要路径片段,我想要完整的路径。


当前回答

如果将目录作为相对路径传递,则需要在调用find之前将其转换为绝对路径。在下面的例子中,目录作为第一个参数传递给脚本:

#!/bin/bash

# get absolute path
directory=`cd $1; pwd`
# print out list of files and directories
find "$directory"

其他回答

如果将目录作为相对路径传递,则需要在调用find之前将其转换为绝对路径。在下面的例子中,目录作为第一个参数传递给脚本:

#!/bin/bash

# get absolute path
directory=`cd $1; pwd`
# print out list of files and directories
find "$directory"

使用找到:

find .
find /home/dreftymac

如果你只想要文件(忽略目录,设备等):

find . -type f
find /home/dreftymac -type f
du -a

方便一些有限的设备外壳的查找/定位不可用。

tar cf - $PWD|tar tvf -             

这是缓慢的,但递归地工作,并打印目录和文件。你可以用awk/grep管道它,如果你只是想要文件名,而不是所有其他的信息/目录:

tar cf - $PWD|tar tvf -|awk '{print $6}'|grep -v "/$"          

一长串的答案。 这很有帮助,最后,我创建了我自己的,我正在寻找:

列出目录及其子目录下的所有文件。

find "$PWD" -type f

列出目录及其子目录下的所有目录。

find "$PWD" -type d

列出目录及其子目录下的所有目录和文件。

find "$PWD"