4

I goofed my Macbook real good. I moved some Time Machine backups from my external drive into Trash and quickly realized that was a horrible mistake. I can't put them back and I can't delete them. So far I've been running rm with a helper function called bypass that is allowing me to skirt Apple's protection of deleting backups.

Anyways, I have a command

sudo /System/Library/Extensions/TMSafetyNet.kext/Contents/Helpers/bypass rm -rfv /Volumes/*/.Trashes

which for brevity can be referred to as

sudo bypass rm -rfv /Volumes/*/.Trashes

that keeps randomly getting interrupted by rm: fts_read: No such file or directory. I think fts_read is essentially a UNIX kernel function that gets into filespace and is read as a file during very verbose recursive rm calls. So I want to catch fts_read and restart my sudo bypass rm -rfv /Volumes/*/.Trashes. I don't know bash that well, but here's some pseudocode of my thoughts:

try:
  sudo bypass rm -rfv /Volumes/*/.Trashes
except 'rm: fts_read: No such file or directory':
  sudo bypass rm -rfv /Volumes/*/.Trashes

Basically right now I'm manually restarting the command every time I get the error, but this process is taking dozens of hours so it'd be nice if it could restart itself.

Frank
  • 735
  • 1
  • 12
  • 33
  • How did you solve it finally? – ebaynaud Aug 28 '19 at 09:20
  • I'm not sure, although perhaps try wrapping your commands in something like python? That way you can utilize try/catch and still make command line `exec` calls @ebaynaud – Frank Aug 28 '19 at 20:25

1 Answers1

2

One possible option could be a while loop that requires the failure of the previous command? example:

counter=0
cd "not a real place" #get the initial error code
while [[ $? -ne 0 ]]; do
    echo 'words'
    (( counter++ ))
    (( counter > 10 ))
done

This will keep going until (( counter > 10 )) returns 0, i.e., evaluates to true. You should be able to do something similar with your command:

sudo bypass rm -rfv /Volumes/*/.Trashes
while [[ $? -ne 0 ]]; do
    sudo bypass rm -rfv /Volumes/*/.Trashes
done

I doubt this is a good solution, but it's a solution.

jeremysprofile
  • 10,028
  • 4
  • 33
  • 53