Remove all symbolic links of files in one command

To remove the links (from man find under -type):

          l      symbolic link; this is never true if the -L option or the
                 -follow option is in effect, unless the symbolic link  is
                 broken.  If you want to search for symbolic links when -L
                 is in effect, use -xtype.

I think this should do the trick:

find /usr/local/lib/ -maxdepth 1 -follow  -type l

Does the output produce a list of the files you want to delete? If so, when you are 100% sure:

find /usr/local/lib/ -maxdepth 1 -follow  -type l -delete

This will remove only broken links. To delete all links, remove the -follow stanza, but I wouldn't do that under /usr/local/lib.

Tags:

Linux

Bash