LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-15-2005, 10:54 PM   #1
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 73
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.
 
Old 03-15-2005, 10:59 PM   #2
shotokan
Member
 
Registered: Mar 2005
Distribution: slackware, LFS
Posts: 204

Rep: Reputation: 30
Why would you wan't to do that?
 
Old 03-15-2005, 11:01 PM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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 {} \;

Last edited by homey; 03-15-2005 at 11:19 PM.
 
Old 03-15-2005, 11:34 PM   #4
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Original Poster
Rep: Reputation: 73
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.
 
Old 03-15-2005, 11:37 PM   #5
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Original Poster
Rep: Reputation: 73
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.
 
Old 03-15-2005, 11:39 PM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to delete files with 0k file size in a directory justgiver Linux - Newbie 4 01-28-2008 04:56 AM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 06:54 PM
Specifying target directory for command in bash shell script? spectrescape Programming 1 07-22-2004 05:37 PM
How do I run a command in script from a particular directory? davee Linux - Newbie 1 08-07-2003 03:22 AM
Usedel command doesn't delete user directory? mikeshn Linux - General 2 11-22-2002 12:18 AM


All times are GMT -5. The time now is 10:58 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration