Find and delete all symbolic links in the home folder without having problems with its operation

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 the prompt is y (yes) Then: Find all the symbolic links in ~ (the home directory) and execute a for loop that will delete them and show which one has been deleted.

Although now it does not perform part removal, everything works fine. I did not include the part that works, this is just a bunch of ln -s .

I'm on Mac OS X Mountain Lion (10.8.2), using Zsh as a shell, this is in the .sh file.

The problem I am facing is that nothing is happening and therefore it just says:

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

and etc.

Thanks so much for any help you can provide!

EDIT:
Now I 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 
+4
source share
3 answers

I was able to solve the problem, it turned out that this condition was not working. Thanks for your help guys! :)

-1
source
 find /path -type l | xargs rm 

The first part lists symbolic links. Xargs says rm is returned for each return value

+16
source

How about this?

 find ~ -type l | while read line do rm -v "$line" done 
+2
source

Source: https://habr.com/ru/post/1447379/


All Articles