LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   script/command to delete all symlinks from a directory (https://www.linuxquestions.org/questions/linux-general-1/script-command-to-delete-all-symlinks-from-a-directory-302124/)

reddazz 03-15-2005 10:54 PM

script/command to delete all symlinks from a directory
 
Does anyone know a command or script that I could use to delete all symbolic links from a directory and preserve all files that are not symlinks.

shotokan 03-15-2005 10:59 PM

Why would you wan't to do that?

homey 03-15-2005 11:01 PM

From man find, it looks like you could use -lname

Quote:

-lname pattern
File is a symbolic link whose contents match shell pattern pattern. The
metacharacters do not treat / or . specially.
Edit: yep, it seems to work but I'd be careful with what gets removed. Maybe list them firsl...
find /home -lname '*' -exec ls {} \;

find /home -maxdepth 1 -lname '*' -exec rm {} \;

reddazz 03-15-2005 11:34 PM

Quote:

Originally posted by shotokan
Why would you wan't to do that?
Coz I got a directory with about 50 symlinks that need to be deleted.

reddazz 03-15-2005 11:37 PM

Quote:

Originally posted by homey
From man find, it looks like you could use -lname



Edit: yep, it seems to work but I'd be careful with what gets removed. Maybe list them firsl...
find /home -lname '*' -exec ls {} \;

find /home -maxdepth 1 -lname '*' -exec rm {} \;

Thanks the command right at the bottom of your post worked like a charm.

Dark_Helmet 03-15-2005 11:39 PM

I'll 1-up homey:
Code:

find . -maxdepth 1 -type l -exec rm -f {} \;
Really, the same thing, but you don't need the '*' wildcard.


All times are GMT -5. The time now is 06:39 PM.