Using find with symbolic links

Symbolic links, or symlinks come in handy when you need to share directories
with multiple directories and not have to worry about keeping each linked
instance in sync.

The problem with symlinks is that not every command-line utility supports them,
and often times, they do support them, but it’s not default behavior.

One such utility is find which allows you to search a directory for files and
directories that match a pattern. Out of the box, find doesn’t follow symbolic
links.

To will find into following symbolic links, all you need to do is pass in the
-L argument (as a predicate to the path):

# Finds all files, but won't follow symlinks
find . -type f

# Finds all files, AND follows symlinks
find -L . -type f

If you happen to want this behavior all of the time, you can simply alias find
to include the argument:

alias find='find -L'
Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.