查找并删除主文件夹中的所有符号链接,无法正常工作 [英] Find and delete all symlinks in home folder, having trouble making it work
问题描述
我有以下几点:
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
我正在努力实现以下目标:
What I'm trying to achieve is the following:
- 如果提示等于 y(是)然后:找到
~
(主目录)中的所有符号链接,并对它们执行 for 循环,这将删除它们并输出它删除了哪一个.
- If prompt equals y (yes)
Then:
Find all the symlinks in
~
(home directory) and do a for loop on them which would delete them and output which one it deleted.
虽然现在它不做删除部分,其余的工作正常.我没有包括有效的部分,它只是一堆 ln -s
.
Although right now it doesn't do the deleting part, the rest works fine. I didn't include the part that works, it's just a bunch of ln -s
.
我在 Mac OS X Mountain Lion (10.8.2) 中,使用 Zsh 作为 shell,这在 .sh
文件中.
I am in Mac OS X Mountain Lion (10.8.2), using Zsh as shell, this goes in a .sh
file.
我遇到的问题是什么也没有发生,所以它只是说:
The problem I am having is that nothing happens, and so it just says:
ln: /Users/eduan/.vim/vim: File exists
ln: /Users/eduan/.vimrc: File exists
ln: /Users/eduan/.gvimrc: File exists
Done...
等
非常感谢您提供的任何帮助!
Many thanks for any help you can provide!
我现在有以下内容:
I now have the following:
read -p 'Delete old symlinks? y/n: ' prompt
if [ $prompt == [yY] ]
then
find ~ -type l | while read line
do
rm -v "$line"
done
fi
推荐答案
我能够解决问题,结果是 if 条件不起作用.无论如何,感谢您的帮助!:)
I was able to solve the problem, turns out it was the if conditional that wasn't working. Thanks for your help anyway guys! :)
这篇关于查找并删除主文件夹中的所有符号链接,无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!