【发布时间】:2014-04-29 12:43:26
【问题描述】:
使用 find 命令,我可以传递标志 -type 以仅打印特定类型的文件。
例如,要仅打印当前目录中的目录,我运行:
find . -maxdepth 1 -type d
这些是其他类型:
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option or the
-follow option is in effect, unless the symbolic link is
broken. If you want to search for symbolic links when -L
is in effect, use -xtype.
s socket
D door (Solaris)
问题是符号链接的目录不被认为是-type d的目录,并且符号链接(-type l)的标志是广泛的,因为它还将包括不是目录的符号链接文件。也许符号文件无论是指向目录还是文件都被视为相同,但是我如何确保只打印指向目录的文件?我不一定非得使用 find 命令。
【问题讨论】:
-
这是什么操作系统? Linux?
-
@JoeDF Linux (Ubuntu)
-
这行得通吗?
find -L -xtype l -type d
标签: command-line directory find symlink file-type