Find the answer to your Linux question:
Results 1 to 6 of 6
I have a large tree. It is mostly links but has a bunch of files too. I want to recursively remove ONLY the links. Is there a way?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    8

    remove symbolic links only


    I have a large tree. It is mostly links but has a bunch of files too. I want to recursively remove ONLY the links. Is there a way?

  2. #2
    Linux Guru Jonathan183's Avatar
    Join Date
    Oct 2007
    Posts
    3,043
    you could try a combination of unlink and find -type l

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Posts
    8
    I think that would work but I don't know how to pass the output of find to unlink. I tried "find -type l | unlink" but that complained.

  4. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Use the 'exec' function of find, e.g.:
    Code:
     find . -type l -exec rm -vi {} \;
    Not sure what diff b/t unlink and rm is, but rm will remove your links, too.

  5. #5
    Just Joined!
    Join Date
    Dec 2009
    Posts
    8
    That did it, thanks.

  6. #6
    Linux Guru Jonathan183's Avatar
    Join Date
    Oct 2007
    Posts
    3,043
    for current folder and tree I'd try something like unlink $(find -type l) ... anyway glad you got it sorted

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •