简体   繁体   English

Shellscript遍历所有文件并调整符号链接

[英]Shellscript Looping Through All Files and adjusting symlink

I was trying to get libetpan up and running on iOS, however there seemed to be something wrong with their setup shell script (problem explained in more detail here).. but basically I got a folder with a long list of symlinks pointing to nowhere ie 我试图在iOS上启动并运行libetpan ,但是他们的安装外壳脚本似乎出了点问题(问题在这里进行了更详细的解释)..但是基本上我得到了一个文件夹,里面有指向不通之处的符号链接列表,例如

mhdriver_types.h -> ../../src/driver/implementation/mh/mhdriver_types.h

when in fact it should be 实际上应该是

mhdriver_types.h -> ../../../src/driver/implementation/mh/mhdriver_types.h 

I want to write a shell script that loops through all the symlinks, deleting each, then recreating a symlink for it to the same former destination only one subdirectory deeper.. basically doing what i did in the example to all the files.. 我想编写一个shell脚本,该脚本循环遍历所有符号链接,删除每个符号链接,然后为它重新创建一个符号链接到相同的以前的目标,只有一个子目录更深..基本上,我在示例中对所有文件进行了操作。

any ideas? 有任何想法吗?

inspired by anishsane's answer i got this code that works: 受anishsane的答案启发,我得到了可以运行的代码:

for name in $(find . -type l); do
    tgt=`readlink "$name"`
    ln -sf ../$tgt
done

尝试:

find $DIR_PATH -type l | while read x; do tgt=`readlink "$x"`; ln -sf ../$tgt $x; done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM