rm to remove a dir, any symlinks, AND symlink destinations? [duplicate]

 Clash Royale CLAN TAG#URR8PPP
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
This question already has an answer here:
 How to remove the directory a symbolic link links to plus the symbolic link?
 
 3 answers
 
 
I have two directories: /all/origins/ & /all/links/.
Everything in links/ points individually to something in origins/, but not everything in origins/ is linked in links/. (Squares, rectangles & categorical hierarchy, get i?) These are symlinks (ln -s), not hard links.
Everything in 1. links/ needs to be deleted, along with 2. the symlink destinations in origins/ (not knowing whether they are in origins/), and 3. the links/ directory itself.
What rm Unix command should I type to remove both the entire links/ directory AND any symlinked destinations symlinked to in origins/?
I'm looking for something maybe like: rm -R /all/links or rm -r --follow-all-ln /all/links.
If an rm command with parameters will not do the job, please say so explicitly as that is my preference and implicit in the title (can Unix & Linux do this via rm without a do loop?—only if that won't work, then please state so and explain what do loop.)
rm ln
 marked as duplicate by RalfFriedl, G-Man, elbarna, Thomas, schily Nov 23 at 13:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
3
down vote
favorite
This question already has an answer here:
 How to remove the directory a symbolic link links to plus the symbolic link?
 
 3 answers
 
 
I have two directories: /all/origins/ & /all/links/.
Everything in links/ points individually to something in origins/, but not everything in origins/ is linked in links/. (Squares, rectangles & categorical hierarchy, get i?) These are symlinks (ln -s), not hard links.
Everything in 1. links/ needs to be deleted, along with 2. the symlink destinations in origins/ (not knowing whether they are in origins/), and 3. the links/ directory itself.
What rm Unix command should I type to remove both the entire links/ directory AND any symlinked destinations symlinked to in origins/?
I'm looking for something maybe like: rm -R /all/links or rm -r --follow-all-ln /all/links.
If an rm command with parameters will not do the job, please say so explicitly as that is my preference and implicit in the title (can Unix & Linux do this via rm without a do loop?—only if that won't work, then please state so and explain what do loop.)
rm ln
 marked as duplicate by RalfFriedl, G-Man, elbarna, Thomas, schily Nov 23 at 13:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
 
 
 1
 
 
 
 
 In third line I think you want to say- links/instead of- origins/.
 – Debian_yadav
 Nov 22 at 23:23
 
 
 
 
 
 
 
 
 
 
 Possible and related, but not coterminous. My question is about removing the directory itself and such links with it. This near-dup removes only a file and only one at a time, specifically. But, it is related, so thanks.
 – Jesse Steele
 Nov 23 at 1:43
 
 
 
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
This question already has an answer here:
 How to remove the directory a symbolic link links to plus the symbolic link?
 
 3 answers
 
 
I have two directories: /all/origins/ & /all/links/.
Everything in links/ points individually to something in origins/, but not everything in origins/ is linked in links/. (Squares, rectangles & categorical hierarchy, get i?) These are symlinks (ln -s), not hard links.
Everything in 1. links/ needs to be deleted, along with 2. the symlink destinations in origins/ (not knowing whether they are in origins/), and 3. the links/ directory itself.
What rm Unix command should I type to remove both the entire links/ directory AND any symlinked destinations symlinked to in origins/?
I'm looking for something maybe like: rm -R /all/links or rm -r --follow-all-ln /all/links.
If an rm command with parameters will not do the job, please say so explicitly as that is my preference and implicit in the title (can Unix & Linux do this via rm without a do loop?—only if that won't work, then please state so and explain what do loop.)
rm ln
This question already has an answer here:
 How to remove the directory a symbolic link links to plus the symbolic link?
 
 3 answers
 
 
I have two directories: /all/origins/ & /all/links/.
Everything in links/ points individually to something in origins/, but not everything in origins/ is linked in links/. (Squares, rectangles & categorical hierarchy, get i?) These are symlinks (ln -s), not hard links.
Everything in 1. links/ needs to be deleted, along with 2. the symlink destinations in origins/ (not knowing whether they are in origins/), and 3. the links/ directory itself.
What rm Unix command should I type to remove both the entire links/ directory AND any symlinked destinations symlinked to in origins/?
I'm looking for something maybe like: rm -R /all/links or rm -r --follow-all-ln /all/links.
If an rm command with parameters will not do the job, please say so explicitly as that is my preference and implicit in the title (can Unix & Linux do this via rm without a do loop?—only if that won't work, then please state so and explain what do loop.)
This question already has an answer here:
 How to remove the directory a symbolic link links to plus the symbolic link?
 
 3 answers
 
 
rm ln
rm ln
edited Nov 25 at 4:14
asked Nov 22 at 23:16


Jesse Steele
12717
12717
 marked as duplicate by RalfFriedl, G-Man, elbarna, Thomas, schily Nov 23 at 13:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
 marked as duplicate by RalfFriedl, G-Man, elbarna, Thomas, schily Nov 23 at 13:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
 
 
 1
 
 
 
 
 In third line I think you want to say- links/instead of- origins/.
 – Debian_yadav
 Nov 22 at 23:23
 
 
 
 
 
 
 
 
 
 
 Possible and related, but not coterminous. My question is about removing the directory itself and such links with it. This near-dup removes only a file and only one at a time, specifically. But, it is related, so thanks.
 – Jesse Steele
 Nov 23 at 1:43
 
 
 
add a comment |
 
 
 1
 
 
 
 
 In third line I think you want to say- links/instead of- origins/.
 – Debian_yadav
 Nov 22 at 23:23
 
 
 
 
 
 
 
 
 
 
 Possible and related, but not coterminous. My question is about removing the directory itself and such links with it. This near-dup removes only a file and only one at a time, specifically. But, it is related, so thanks.
 – Jesse Steele
 Nov 23 at 1:43
 
 
 
1
1
In third line I think you want to say
links/ instead of origins/.– Debian_yadav
Nov 22 at 23:23
In third line I think you want to say
links/ instead of origins/.– Debian_yadav
Nov 22 at 23:23
Possible and related, but not coterminous. My question is about removing the directory itself and such links with it. This near-dup removes only a file and only one at a time, specifically. But, it is related, so thanks.
– Jesse Steele
Nov 23 at 1:43
Possible and related, but not coterminous. My question is about removing the directory itself and such links with it. This near-dup removes only a file and only one at a time, specifically. But, it is related, so thanks.
– Jesse Steele
Nov 23 at 1:43
add a comment |
 1 Answer
 1
 
active
oldest
votes
up vote
3
down vote
accepted
First take backup of your data in case something goes wrong.
What I understood is that you want to delete all the contents of /all/links/ directory and the file to which the links inside this directory are pointing.
There is no way to do this with a simple Unix command as you preferred, but it will work with a simple script.
#!/bin/bash
for i in /all/links/*
do
rm "$(readlink -f $i)"
rm "$i"
done
rmdir /all/links
As you said that all files inside /all/links/ are symbolic links so there is no need to check each value of i whether it is a link or not.
 
 
 
 
 
 
 Is there no way to do this with a simple Unix command? If so, I accept this as the answer and please approve my edit.
 – Jesse Steele
 Nov 23 at 3:21
 
 
 
 
 
 1
 
 
 
 
 The backticks in the last line of the script should be quotes, right? I guess you don't want command substitution there.
 – fra-san
 Nov 23 at 8:32
 
 
 
 
 
 
 
 
 
 @fra-san ohhh, yes thanks.
 – Debian_yadav
 Nov 23 at 8:53
 
 
 
 
 
 
 
 
 
 @JesseSteele the script is short enough that you could write it in a single line of shell...- for f in /all/links/*; do rm "$(readlink -f $f)"; rm "$f"; done; rmdir /all/links. If you need it possibly more than once... go for the script as script.
 – planetmaker
 Nov 23 at 9:39
 
 
 
 
 
 
 
 
 
 
 Thank you, make it an answer and I will up vote it for usefulness, but, honestly, it is still not a simple Unix command (part of the question), but a script on a single line
 – Jesse Steele
 Nov 23 at 9:41
 
 
 
|
show 5 more comments
 1 Answer
 1
 
active
oldest
votes
 1 Answer
 1
 
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
First take backup of your data in case something goes wrong.
What I understood is that you want to delete all the contents of /all/links/ directory and the file to which the links inside this directory are pointing.
There is no way to do this with a simple Unix command as you preferred, but it will work with a simple script.
#!/bin/bash
for i in /all/links/*
do
rm "$(readlink -f $i)"
rm "$i"
done
rmdir /all/links
As you said that all files inside /all/links/ are symbolic links so there is no need to check each value of i whether it is a link or not.
 
 
 
 
 
 
 Is there no way to do this with a simple Unix command? If so, I accept this as the answer and please approve my edit.
 – Jesse Steele
 Nov 23 at 3:21
 
 
 
 
 
 1
 
 
 
 
 The backticks in the last line of the script should be quotes, right? I guess you don't want command substitution there.
 – fra-san
 Nov 23 at 8:32
 
 
 
 
 
 
 
 
 
 @fra-san ohhh, yes thanks.
 – Debian_yadav
 Nov 23 at 8:53
 
 
 
 
 
 
 
 
 
 @JesseSteele the script is short enough that you could write it in a single line of shell...- for f in /all/links/*; do rm "$(readlink -f $f)"; rm "$f"; done; rmdir /all/links. If you need it possibly more than once... go for the script as script.
 – planetmaker
 Nov 23 at 9:39
 
 
 
 
 
 
 
 
 
 
 Thank you, make it an answer and I will up vote it for usefulness, but, honestly, it is still not a simple Unix command (part of the question), but a script on a single line
 – Jesse Steele
 Nov 23 at 9:41
 
 
 
|
show 5 more comments
up vote
3
down vote
accepted
First take backup of your data in case something goes wrong.
What I understood is that you want to delete all the contents of /all/links/ directory and the file to which the links inside this directory are pointing.
There is no way to do this with a simple Unix command as you preferred, but it will work with a simple script.
#!/bin/bash
for i in /all/links/*
do
rm "$(readlink -f $i)"
rm "$i"
done
rmdir /all/links
As you said that all files inside /all/links/ are symbolic links so there is no need to check each value of i whether it is a link or not.
 
 
 
 
 
 
 Is there no way to do this with a simple Unix command? If so, I accept this as the answer and please approve my edit.
 – Jesse Steele
 Nov 23 at 3:21
 
 
 
 
 
 1
 
 
 
 
 The backticks in the last line of the script should be quotes, right? I guess you don't want command substitution there.
 – fra-san
 Nov 23 at 8:32
 
 
 
 
 
 
 
 
 
 @fra-san ohhh, yes thanks.
 – Debian_yadav
 Nov 23 at 8:53
 
 
 
 
 
 
 
 
 
 @JesseSteele the script is short enough that you could write it in a single line of shell...- for f in /all/links/*; do rm "$(readlink -f $f)"; rm "$f"; done; rmdir /all/links. If you need it possibly more than once... go for the script as script.
 – planetmaker
 Nov 23 at 9:39
 
 
 
 
 
 
 
 
 
 
 Thank you, make it an answer and I will up vote it for usefulness, but, honestly, it is still not a simple Unix command (part of the question), but a script on a single line
 – Jesse Steele
 Nov 23 at 9:41
 
 
 
|
show 5 more comments
up vote
3
down vote
accepted
up vote
3
down vote
accepted
First take backup of your data in case something goes wrong.
What I understood is that you want to delete all the contents of /all/links/ directory and the file to which the links inside this directory are pointing.
There is no way to do this with a simple Unix command as you preferred, but it will work with a simple script.
#!/bin/bash
for i in /all/links/*
do
rm "$(readlink -f $i)"
rm "$i"
done
rmdir /all/links
As you said that all files inside /all/links/ are symbolic links so there is no need to check each value of i whether it is a link or not.
First take backup of your data in case something goes wrong.
What I understood is that you want to delete all the contents of /all/links/ directory and the file to which the links inside this directory are pointing.
There is no way to do this with a simple Unix command as you preferred, but it will work with a simple script.
#!/bin/bash
for i in /all/links/*
do
rm "$(readlink -f $i)"
rm "$i"
done
rmdir /all/links
As you said that all files inside /all/links/ are symbolic links so there is no need to check each value of i whether it is a link or not.
edited Nov 23 at 8:53
answered Nov 22 at 23:30
Debian_yadav
1,3153922
1,3153922
 
 
 
 
 
 
 Is there no way to do this with a simple Unix command? If so, I accept this as the answer and please approve my edit.
 – Jesse Steele
 Nov 23 at 3:21
 
 
 
 
 
 1
 
 
 
 
 The backticks in the last line of the script should be quotes, right? I guess you don't want command substitution there.
 – fra-san
 Nov 23 at 8:32
 
 
 
 
 
 
 
 
 
 @fra-san ohhh, yes thanks.
 – Debian_yadav
 Nov 23 at 8:53
 
 
 
 
 
 
 
 
 
 @JesseSteele the script is short enough that you could write it in a single line of shell...- for f in /all/links/*; do rm "$(readlink -f $f)"; rm "$f"; done; rmdir /all/links. If you need it possibly more than once... go for the script as script.
 – planetmaker
 Nov 23 at 9:39
 
 
 
 
 
 
 
 
 
 
 Thank you, make it an answer and I will up vote it for usefulness, but, honestly, it is still not a simple Unix command (part of the question), but a script on a single line
 – Jesse Steele
 Nov 23 at 9:41
 
 
 
|
show 5 more comments
 
 
 
 
 
 
 Is there no way to do this with a simple Unix command? If so, I accept this as the answer and please approve my edit.
 – Jesse Steele
 Nov 23 at 3:21
 
 
 
 
 
 1
 
 
 
 
 The backticks in the last line of the script should be quotes, right? I guess you don't want command substitution there.
 – fra-san
 Nov 23 at 8:32
 
 
 
 
 
 
 
 
 
 @fra-san ohhh, yes thanks.
 – Debian_yadav
 Nov 23 at 8:53
 
 
 
 
 
 
 
 
 
 @JesseSteele the script is short enough that you could write it in a single line of shell...- for f in /all/links/*; do rm "$(readlink -f $f)"; rm "$f"; done; rmdir /all/links. If you need it possibly more than once... go for the script as script.
 – planetmaker
 Nov 23 at 9:39
 
 
 
 
 
 
 
 
 
 
 Thank you, make it an answer and I will up vote it for usefulness, but, honestly, it is still not a simple Unix command (part of the question), but a script on a single line
 – Jesse Steele
 Nov 23 at 9:41
 
 
 
Is there no way to do this with a simple Unix command? If so, I accept this as the answer and please approve my edit.
– Jesse Steele
Nov 23 at 3:21
Is there no way to do this with a simple Unix command? If so, I accept this as the answer and please approve my edit.
– Jesse Steele
Nov 23 at 3:21
1
1
The backticks in the last line of the script should be quotes, right? I guess you don't want command substitution there.
– fra-san
Nov 23 at 8:32
The backticks in the last line of the script should be quotes, right? I guess you don't want command substitution there.
– fra-san
Nov 23 at 8:32
@fra-san ohhh, yes thanks.
– Debian_yadav
Nov 23 at 8:53
@fra-san ohhh, yes thanks.
– Debian_yadav
Nov 23 at 8:53
@JesseSteele the script is short enough that you could write it in a single line of shell...
for f in /all/links/*; do rm "$(readlink -f $f)"; rm "$f"; done; rmdir /all/links. If you need it possibly more than once... go for the script as script.– planetmaker
Nov 23 at 9:39
@JesseSteele the script is short enough that you could write it in a single line of shell...
for f in /all/links/*; do rm "$(readlink -f $f)"; rm "$f"; done; rmdir /all/links. If you need it possibly more than once... go for the script as script.– planetmaker
Nov 23 at 9:39
Thank you, make it an answer and I will up vote it for usefulness, but, honestly, it is still not a simple Unix command (part of the question), but a script on a single line
– Jesse Steele
Nov 23 at 9:41
Thank you, make it an answer and I will up vote it for usefulness, but, honestly, it is still not a simple Unix command (part of the question), but a script on a single line
– Jesse Steele
Nov 23 at 9:41
|
show 5 more comments
1
In third line I think you want to say
links/instead oforigins/.– Debian_yadav
Nov 22 at 23:23
Possible and related, but not coterminous. My question is about removing the directory itself and such links with it. This near-dup removes only a file and only one at a time, specifically. But, it is related, so thanks.
– Jesse Steele
Nov 23 at 1:43