问题
I have the following:
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:
- 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.
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.
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...
etc.
Many thanks for any help you can provide!
EDIT:
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
回答1:
find /path -type l | xargs rm
The first part lists the symlinks. Xargs says for each of the returned values issue an rm
回答2:
How about this?
find ~ -type l | while read line
do
rm -v "$line"
done
回答3:
I was able to solve the problem, turns out it was the if conditional that wasn't working. Thanks for your help anyway guys! :)
来源:https://stackoverflow.com/questions/13484825/find-and-delete-all-symlinks-in-home-folder-having-trouble-making-it-work