Using the find command, I can pass the flag -type to print only files of a certain type.
For example, to print only directories in the current directory, I run:

find . -maxdepth 1 -type d

These are the other types:

-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)

The problem is that a symbolically linked directory is not considered a directory of -type d, and the flag for symbolic links(-type l) is to broad because it will also include symbolically linked files that aren't directories. Perhaps a symbolic file is treated the same whether it points to a directory or file, but how would I ensure I only print the ones that point to directories? I don't necessarily have to use the find command.

有帮助吗?

解决方案

Try : find -L -xtype l -type d

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top