c0rrupt
July 20th, 2008, 12:20 PM
I am working on a small Bash script to remove some of the junk files that Windows likes to leave laying around (thumbs.db, desktop.ini) but I'm having a problem with folders that contain spaces.
When I have it echo the results everything looks fine. All the lines are enclosed with quotation marks for any directory with spaces. But when I try to remove the files with rm, it freaks out.
Here is the script.
#!/bin/bash
find ~/Music/ -name '*Thumbs.db*' | while read FILE
do
FILE=\"$FILE\"
#echo $FILE
rm -i $FILE
done
Some of the output from echo.
"/home/david/Music/Albums/A Perfect Circle/Thumbs.db"
"/home/david/Music/Albums/A Thorn For Every Heart/Thumbs.db"
"/home/david/Music/Albums/Afghan Whigs/Thumbs.db"
"/home/david/Music/Albums/Against Me!/Thumbs.db"
An error message from rm
rm: cannot remove `"/home/david/Music/Albums/A': No such file or directory
rm: cannot remove `Perfect': No such file or directory
rm: cannot remove `Circle/Thumbs.db"': No such file or directory
rm: cannot remove `"/home/david/Music/Albums/A': No such file or directory
rm: cannot remove `Thorn': No such file or directory
rm: cannot remove `For': No such file or directory
rm: cannot remove `Every': No such file or directory
rm: cannot remove `Heart/Thumbs.db"': No such file or directory
rm: cannot remove `"/home/david/Music/Albums/Afghan': No such file or directory
rm: cannot remove `Whigs/Thumbs.db"': No such file or directory
rm: cannot remove `"/home/david/Music/Albums/Against': No such file or directory
rm: cannot remove `Me!/Thumbs.db"': No such file or directory
I thought that maybe it was because the space didn't have a \ preceding it, but rm accepted this command.
rm -i "/home/david/Music/Albums/A Perfect Circle/Thumbs.db"
Oh, I almost forgot. When I tried rm -i "/home/david/Music/Albums/Against Me!/Thumbs.db I got this ": event not found". The ! must be causing that one.
What is going on here?
When I have it echo the results everything looks fine. All the lines are enclosed with quotation marks for any directory with spaces. But when I try to remove the files with rm, it freaks out.
Here is the script.
#!/bin/bash
find ~/Music/ -name '*Thumbs.db*' | while read FILE
do
FILE=\"$FILE\"
#echo $FILE
rm -i $FILE
done
Some of the output from echo.
"/home/david/Music/Albums/A Perfect Circle/Thumbs.db"
"/home/david/Music/Albums/A Thorn For Every Heart/Thumbs.db"
"/home/david/Music/Albums/Afghan Whigs/Thumbs.db"
"/home/david/Music/Albums/Against Me!/Thumbs.db"
An error message from rm
rm: cannot remove `"/home/david/Music/Albums/A': No such file or directory
rm: cannot remove `Perfect': No such file or directory
rm: cannot remove `Circle/Thumbs.db"': No such file or directory
rm: cannot remove `"/home/david/Music/Albums/A': No such file or directory
rm: cannot remove `Thorn': No such file or directory
rm: cannot remove `For': No such file or directory
rm: cannot remove `Every': No such file or directory
rm: cannot remove `Heart/Thumbs.db"': No such file or directory
rm: cannot remove `"/home/david/Music/Albums/Afghan': No such file or directory
rm: cannot remove `Whigs/Thumbs.db"': No such file or directory
rm: cannot remove `"/home/david/Music/Albums/Against': No such file or directory
rm: cannot remove `Me!/Thumbs.db"': No such file or directory
I thought that maybe it was because the space didn't have a \ preceding it, but rm accepted this command.
rm -i "/home/david/Music/Albums/A Perfect Circle/Thumbs.db"
Oh, I almost forgot. When I tried rm -i "/home/david/Music/Albums/Against Me!/Thumbs.db I got this ": event not found". The ! must be causing that one.
What is going on here?