加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell – 查找并删除主文件夹中的所有符号链接,无法使其正常工作

发布时间:2020-12-15 22:26:50 所属栏目:安全 来源:网络整理
导读:我有以下内容: read -p 'Delete old symlinks? y/n: ' promptif [ $prompt == [yY] ]then current_dir=$(pwd) script_dir=$(dirname $0) if [ $script_dir = '.' ] then script_dir="$current_dir" fi for sym in {find $PATH -type l -xtype d -lname "~"}
我有以下内容:

read -p 'Delete old symlinks? y/n: ' prompt

if [ $prompt == [yY] ]
then    
    current_dir=$(pwd)
    script_dir=$(dirname $0)

    if [ $script_dir = '.' ]
    then
        script_dir="$current_dir"
    fi

    for sym in {find $PATH -type l -xtype d -lname "~"}
    do
        rm $sym
        echo "Removed: $sym"
    done
fi

我想要实现的目标如下:

>如果提示等于y(是)
然后:
找到?(主目录)中的所有符号链接并对它们执行for循环,这将删除它们并输出它删除的那个.

虽然现在它没有删除部分,其余工作正常.我没有包含有效的部分,它只是一堆ln -s.

我在Mac OS X Mountain Lion(10.8.2)中,使用Zsh作为shell,这是一个.sh文件.

我遇到的问题是没有任何反应,所以它只是说:

ln: /Users/eduan/.vim/vim: File exists
ln: /Users/eduan/.vimrc: File exists
ln: /Users/eduan/.gvimrc: File exists
Done...

等等

非常感谢您提供的任何帮助!

编辑:
我现在有以下内容:

read -p 'Delete old symlinks? y/n: ' prompt

if [ $prompt == [yY] ]
then    
   find ~ -type l | while read line
   do
      rm -v "$line"
   done
fi

解决方法

find /path -type l | xargs rm

第一部分列出了符号链接. Xargs说每个返回的值都会发出一个rm

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读