gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:26:41 26 4
gpt4 key购买 nike

我有以下内容:

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(是)
    然后:
    查找 ~ 中的所有符号链接(symbolic link)(主目录)并在它们上执行一个 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

    第一部分列出了符号链接(symbolic link)。 Xargs表示对于每个返回值发出 rm

    关于shell - 查找并删除主文件夹中的所有符号链接(symbolic link),使其无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13484825/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com