-1

I have a directory of directories which may or may not contain files, other directories or links.

I want to delete all the links. Anyone know of a bash script that would let me do this quickly?

Kevin Chavez
  • 949
  • 1
  • 11
  • 27
  • Honest inquiry; why was my question down voted? Asking to learn what to keep in mind when writing my next one. Downvote without comment is very misleading. – Kevin Chavez Oct 10 '17 at 19:53

2 Answers2

0

A google search to find all links in a directory leads to:

find . -maxdepth 1 -type l

You can combine this with rm:

rm `find . -maxdepth 1 -type l`
sauerburger
  • 4,569
  • 4
  • 31
  • 42
  • 1
    Why would someone downvote this? The maxdepth is cautionary, but easy to remove if the OP doesn't want it, and I *SURE* hope he reads the manpage before arbitrarily executing code he doesn't understand... I do get that the OP asked for recursive deletes, but a downvote on this seems like someone was maybe just looking for a badge? – Paul Hodges Oct 10 '17 at 13:29
0

c.f. this

If you're brave, try this -

find $dirPath -type l | xargs rm -f 
Paul Hodges
  • 13,382
  • 1
  • 17
  • 36
  • 2
    You should be careful with this command, it deletes links recursively, i.e. all links in any sub directory (and sub-sub-...-directories). – sauerburger Oct 09 '17 at 21:11
  • Yes, it's quick but very heavy-handed. I would most likely just write the list to a file and eyeball it first, then edit if needed, and when satisfied, feed that list to the xargs, or some other script. ...but it matches the request. – Paul Hodges Oct 10 '17 at 13:26