我正在开发一个便携式 anaconda 包,我正在尝试使用 find 和 sed 来查找所有文件并替换当前目录及其子目录中文件中的路径。
但是,当我执行命令时,sed 抛出错误:
sed: couldn't edit anaconda3: not a regular file
Run Code Online (Sandbox Code Playgroud)
我使用的命令是:
find ./ -type f -exec sed -i -e "s+/opt/conda_tools+$TOOLKIT_DIR+g" * {} \;
Run Code Online (Sandbox Code Playgroud)
我使用 + 作为分隔符,因为 / 是路径的一部分。我正在执行脚本的目录的内容是:
drwxr-xr-x 24 test_user linuxusers 4096 十一月 21 日 16:07 anaconda3
单独执行 find 命令会按预期列出文件,但由于某种原因,目录名称仍在被选取。我还尝试了以下命令变体,但没有成功:
find ./ -type f -exec sed -i '' "s+/opt/conda_tools+$INSTALL_DIR+g" * {} \;
Run Code Online (Sandbox Code Playgroud)
我以前成功地使用过 find 和 sed,但我有点不知道下一步该往哪里看。有什么明显的错误是我在这里遗漏的,或者不是那么明显?
小智 6
从中删除“*”
find ./ -type f -exec sed -ie "s+/opt/conda_tools+$TOOLKIT_DIR+g" * {} \;
Run Code Online (Sandbox Code Playgroud)
所以
find ./ -type f -exec sed -ie "s+/opt/conda_tools+$TOOLKIT_DIR+g" {} \;
Run Code Online (Sandbox Code Playgroud)