LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 02-13-2007, 09:26 AM   #1
mavness
Member
 
Registered: Aug 2002
Location: Chicago
Distribution: Debian 3.1
Posts: 45

Rep: Reputation: 15
Can I delete a symbolic link and the file its linked to?


Is there any way I can delete the link I created along with the file it points to with one command?

Thanks in advance!
 
Old 02-13-2007, 11:11 AM   #2
sn68
Member
 
Registered: Oct 2005
Distribution: FC5
Posts: 338

Rep: Reputation: 30
No! you cannot delete the sybolic link and the file pointed by the link with any "one" command as far as I know.
However you can always write a bash script to achieve the purpose, which is as good as a single command
 
Old 02-13-2007, 11:21 AM   #3
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
The closest I can get to a single command is a single command line:

Code:
rm $(ls -l yoursymboliclink | sed -e 's/^.* -> //'); rm yoursymboliclink
And even that won't be adequate if you want to go through an arbitrary number of symbolic links, where x might be a symbolic link to y which is a symbolic link to a regular file z.
 
Old 02-13-2007, 11:40 AM   #4
wpn146
Member
 
Registered: Jan 2005
Distribution: Solaris, Linux Fedora Core 6
Posts: 170

Rep: Reputation: 30
Quote:
Originally Posted by wjevans_7d1@yahoo.co
The closest I can get to a single command is a single command line:

Code:
rm $(ls -l yoursymboliclink | sed -e 's/^.* -> //'); rm yoursymboliclink
And even that won't be adequate if you want to go through an arbitrary number of symbolic links, where x might be a symbolic link to y which is a symbolic link to a regular file z.
I was thinking down the same lines, but your semicolon cheats because it makes two commands . Here is how to make yours one command:
Code:
rm $(ls -l yoursymboliclink | sed -e 's/^.* -> //') yoursymboliclink
Here is my contribution:
Code:
rm $(ls -l yoursymboliclink | awk '{print $11}') yoursymboliclink
Writing a bash script to recursively navigate a "link points to link points to link" situation is still difficult because a completely different chain of links could ultimately point to the target file (or any of its links) and end up a broken link when the file or link gets removed.

Last edited by wpn146; 02-13-2007 at 11:48 AM.
 
Old 02-14-2007, 01:31 PM   #5
mavness
Member
 
Registered: Aug 2002
Location: Chicago
Distribution: Debian 3.1
Posts: 45

Original Poster
Rep: Reputation: 15
Yeah you guys got what I mean. Im sorry, I didnt mean nesscarily ONE command, but more so one line of "text" if you will. I am doin something in php and I was trying to avoid running some kind of loop to delete 3 links and then the 3 files the links were pointing to.

Thanks for the help guys!

--Z
 
  


Reply



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
copy both soft link and its linked file okeyla Programming 3 02-13-2005 11:30 PM
Checking whether a file is symbolic link or not rajesh_b Programming 3 01-06-2005 10:07 AM
How to delete a symbolic link aroop Linux - Newbie 24 07-29-2004 01:52 AM
Can't delete symbolic link chichibabin Linux - General 1 01-20-2004 06:30 AM
Executing PHP symbolic link file from site ricocali Linux - General 6 11-22-2002 10:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:34 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration