Is there a way to tell sed to ignore symlinks?

bash, command-line, linux, shell, unix

Solution

@piokuc already named the option for following symlinks, here's how you can ignore them with `find` first:

find /path/to/dir/ -type f -name "*.xml" ! -type l -exec sed -i 's/search_regexp/replacement_string/' {} \;

or, slightly more efficient:

find /path/to/dir/ -type f -name "*.xml" ! -type l | xargs sed -i 's/search_regexp/replacement_string/'

The `! -type l` part means "not anything that is a symlink"

Problem

I have a directory A with a bunch of files with `.xml` extension that I need to run a search-and-replace on. There are a couple of symlinks (also with `.xml` extension) in A that link to certain files in A. I tried running `sed -i 's/search_regexp/replacement_string/' *.xml` but when it hits a symlink it fails with ``` sed: ck_follow_symlink: couldn't lstat file.xml: No such file or directory ``` A solution would be to loop around the files that I actually want to modify and call sed on each file, but is there a way to tell sed to ignore symlinks? or just follow them and modify the linked file?

Original source