Closing.
]]>OK.
ls -l | grep -- '->' | sed -e's/.*-> //'|xargs -0 echo| sed 's/\(.*\)/"\1"/'|xargs rm
That really and truly seems to do what I want. It's a lot longer than I thought the solution to such a simple problem would be, but it works.
Instead of wrapping the output via pipeline with sed you can wrap the quotes on xargs.
ls | xargs -I {} rm "{}"
for x in *; do if [ -L $x ]; then rm -i "`readlink $x`" && rm -i $x; fi ; done
ls -l | grep -- '->' | sed -e's/.*-> //'|xargs -0 echo| sed 's/\(.*\)/"\1"/'|xargs rm
That really and truly seems to do what I want. It's a lot longer than I thought the solution to such a simple problem would be, but it works.
]]>which futzes up the whole thing
-0 is not magical and not to be used alone.
try
'ls | xargs echo'
then
'ls | xargs -0 echo'
in a directory with filenames spaces.
I use it all the time to do stuff like
ls | xargs -0 echo | sed 's/\(.*\)/"\1"/'
you can also use it with find -print0 and some other commands allowing the input/output of zero-bounded strings
]]>use xargs -0 and such
As I understand it, xargs -0 interprets newlines as \n, which futzes up the whole thing.
]]>for x in *; do if [ -L $x ]; then rm -rf `readlink $x` && rm $x; fi ; done
Very dangerous though!
]]>raymano wrote:Here's another way. It actually checks to see if a file is a symbolic link:
for x in *; do if [ -L $x ]; then rm $x; fi ; done
he doesn't want to just delete the symlink, he wants to delete the file it's linking to as well.
You are right. The above only deletes the links not what they point to. I miss read the question.
]]>ls -l | awk '/^l/ { print $9 " " $11}' | xargs rm
Or, to prevent the selection of symlinks to directories:
ls -l | awk '/^l/ && !/\/$/ { print $9 " " $11}' | xargs rm
To delete symlink and linked-to file in one go...
]]>Here's another way. It actually checks to see if a file is a symbolic link:
for x in *; do if [ -L $x ]; then rm $x; fi ; done
he doesn't want to just delete the symlink, he wants to delete the file it's linking to as well.
]]>Here's another way. It actually checks to see if a file is a symbolic link:
for x in *; do if [ -L $x ]; then rm $x; fi ; done
Holy crap, thank GOD I wasn't root when I accidentially ran that command in /dev.
]]>for x in *; do if [ -L $x ]; then rm $x; fi ; done