Find + Symlinks = me confused

So i have read the man pages a few time. Searched google but I am not quite sure i understand all the lingo.

What i want to do is list all files on / except i dont want any symlinks (because if I am searching / I will find the "true" file...correct?)

So there is the -P, -H, and '-type l' switches..but how do i know which one to use?

Is there a difference between?

Find -P / -type f -print

and

Find / \( -type l \) -prune -o -type f -print

Hi,

if you your requirement is to print the list of files except the symlinks.Then you can use both the codes.

1.In the first code -P option : Never follow symbolic links.So symlinks wont get printed in output.

  1. In second code prune option and -type l are combined .Type -l will print the symlinks since prune is used it will suppress the symlinks.

I hope you would have understood.If there is correction ,anyone can improve the answer.Thanks in advance

You are correct in that symlinks will not be printed, but your analysis is incorrect.

If a symbolic link is encountered, -type l is true. -prune is always true, regardless of the file type, but it only has any effect when the type is a directory. The only reason that the symlink's path isn't printed is because there's nothing in that subexpression trying to print it.

Either of the following would print symlinks (I am dropping the parentheses because they are redundant):

find / -type l -prune -print -o -type f -print
find / -type l -prune -o -type f

Regards,
Alister

1 Like