Linux 有没有办法告诉sed忽略符号链接?

Linux 有没有办法告诉sed忽略符号链接?,linux,bash,shell,unix,command-line,Linux,Bash,Shell,Unix,Command Line,我有一个目录a,其中有一堆扩展名为.xml的文件,我需要对这些文件进行搜索和替换。a中有几个符号链接(扩展名为.xml的符号链接)指向a中的某些文件。我尝试运行sed-I的/search\u regexp/replacement\u string/'*.xml,但当它遇到符号链接时失败 sed: ck_follow_symlink: couldn't lstat file.xml: No such file or directory 一个解决方案是围绕我实际上想要修改的文件循环,并在每个文件

我有一个目录a,其中有一堆扩展名为
.xml
的文件,我需要对这些文件进行搜索和替换。a中有几个符号链接(扩展名为
.xml
的符号链接)指向a中的某些文件。我尝试运行
sed-I的/search\u regexp/replacement\u string/'*.xml
,但当它遇到符号链接时失败

 sed: ck_follow_symlink: couldn't lstat file.xml: No such file or directory

一个解决方案是围绕我实际上想要修改的文件循环,并在每个文件上调用sed,但是有没有办法告诉sed忽略符号链接?或者只是按照它们修改链接文件

有一个选项(
man sed
):

我使用的sed版本是4.1.5:

ariadne{/tmp}:310 --> sed --help | grep follow
  --follow-symlinks
                 follow symlinks when processing in place
ariadne{/tmp}:311 --> sed --version           
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
ariadne{/tmp}:312 --> uname -a
Linux ariadne 2.6.34.10-0.6-desktop #1 SMP PREEMPT 2011-12-13 18:27:38 +0100 x86_64 x86_64 x86_64 GNU/Linux
ariadne{/tmp}:313 --> 

@piokuc已经为以下符号链接命名了选项,下面是如何使用
find
first忽略它们:

find /path/to/dir/ -type f -name "*.xml" ! -type l -exec sed -i 's/search_regexp/replacement_string/' {} \;
或者,稍微高效一点:

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

-类型l
部分表示“没有任何符号链接”

此选项在sed 4.2中是新选项吗?我正在使用4.1.5(我很想更新,但我公司的系统管理员拒绝更新)。我在别处读到过这个选项,但在手册页上没有看到。我有4.1.5,这个选项是there@fo_x86不知道,也许构建是在没有选项的情况下配置的?我在回答中添加了有关我的
sed
版本的信息。符号链接是否被视为“常规文件”(属于
-type f
)?我使用
-typef
(不使用
!-typel
)运行find命令,它过滤掉了符号链接。我想知道是不是
-实际上需要l型
。@fou x86这也是我的怀疑(你只需要f型),但我认为最好是安全的。
find /path/to/dir/ -type f -name "*.xml" ! -type l | xargs sed -i 's/search_regexp/replacement_string/'