I need to remove a large number of symbolic links from a folder that has other files which I don't want to remove. Is there any easy way to remove only symbolic links?
Asked
Active
Viewed 369 times
1 Answers
1
You can use the find(1) command
find . -maxdepth 1 -type l -exec rm {} \;
-maxdepth 1
is for only scanning current directory.-type l
is for searching symbolic links-exec
executesrm
to delete given file, the{}
being replaced byfind
with an appropriate path, and the\;
ending the sub-command run byfind
See also the man
page of rm(1) (and of ls(1), mv(1), cp(1), ln(1), stat(1) if you want to use them in a variant of that find
command).

Basile Starynkevitch
- 223,805
- 18
- 296
- 547

Derviş Kayımbaşıoğlu
- 28,492
- 4
- 50
- 72
-
-
1I added a link to the documentation of `find`. Please take time to read it – Basile Starynkevitch Dec 30 '18 at 14:10
-
@Simonare is there anyway to ensure I don't actually remove the folders which each link points to? – ZakS Dec 30 '18 at 14:41
-
1
-
@Simonare I don't want to delete the files, only the soft link. Moving the softlinks would also be an option -- would u be able to adapt this script to move the files instead? – ZakS Dec 30 '18 at 14:57
-
1@ZakS: Read again [find(1)](http://man7.org/linux/man-pages/man1/find.1.html). And also [rm(1)](http://man7.org/linux/man-pages/man1/rm.1.html) and [mv(1)](http://man7.org/linux/man-pages/man1/mv.1.html). And *you* should be able to adapt the command – Basile Starynkevitch Dec 30 '18 at 15:33
-
1