IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 1 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Removing files from Time Machine backups
So I have left a process running on my Mac over the past couple of days to get me a list of all *.class files on my Time Machine backup drive. I finally have a list, and it looks something like this:


./2009-01-21-015517/Macintosh HD/Users/mike/NWL/AxisTester2/build/classes/axistester2/mdWebService/MdWebServices.class
./2009-01-21-015517/Macintosh HD/Users/mike/NWL/AxisTester2/build/classes/axistester2/mdWebService/MdWebServicesLocator.class


This file was created by the command:

# find . -name "*.class" -print | grep NWL > ~/java-class-file-list.txt

Note that it's FAR longer, and that every line in the file has a space in the filename. I want to remove every single file that's mentioned in this file.

So I've created a bash script to read the text file as input and attempt to remove all the .class files:

#!/bin/sh

while read line
do
rm "Backups.backupdb/numbersix/$line";
done < ~/java-class-file-list.txt


However, the space in the "Macintosh HD" portion of the filenames are screwing me up, as confirmed by:


bash-3.2# rm -f "Backups.backupdb/numbersix/2009-01-21-015517/Macintosh HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class"
rm: Backups.backupdb/numbersix/2009-01-21-015517/Macintosh HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class: Operation not permitted

bash-3.2# rm -f "Backups.backupdb/numbersix/2009-01-21-015517/Macintosh\ HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class"

bash-3.2# file "Backups.backupdb/numbersix/2009-01-21-015517/Macintosh\ HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class"
Backups.backupdb/numbersix/2009-01-21-015517/Macintosh\ HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class: cannot open `Backups.backupdb/numbersix/2009-01-21-015517/Macintosh\ HD/Users/mike/NWL/Code/jakarta-struts-1.2.4-src/contrib/struts-el/target/library/classes/org/apache/strutsel/taglib/tiles/ELPutListTagBeanInfo.class' (No such file or directory)


So adding a backslash before the space will fix things and allow my process to run and remove all those pesky compiled Java files. How might I do that inside my bash script operating on each $line?
-Mike

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
- Benjamin Franklin, 1759 Historical Review of Pennsylvania
New Re: Removing files from Time Machine backups
sed will do it, maybe tr.
Both suck, as does all command line backslashing, especially as you move through multipl levels of scripts the need to be re-escaped.

Something along the lines of:
new_var=`echo $old_var | sed 's/ /\ /g`
or along those lines, it's been many years since I do all my scripting in Perl if possible.
New easier way
vi java-class-file-list.txt
:1,$s/Mackintosh HD/Mackintosh*HD/g
:wq
then rerun the remove script
hope that helps
Any opinions expressed by me are mine alone, posted from my home computer, on my own time as a free American and do not reflect the opinions of any person or company that I have had professional relations with in the past 55 years. meep
New I agree with this one.
Quickly edit the sourcefile list and then re-run your script.

sed -e s/ /\ /g

Or something close to that.
New Re: I agree with this one.
or....

Edit the file with sed to add a double-quote to the beginning/ending of each line.

:%s/^/"/
:%/$/"/

(that's what I usually do)
     Removing files from Time Machine backups - (mvitale) - (4)
         Re: Removing files from Time Machine backups - (crazy)
         easier way - (boxley) - (2)
             I agree with this one. - (folkert) - (1)
                 Re: I agree with this one. - (S1mon_Jester)

This is the most insane thing I've seen in six or seven hours.
48 ms