Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A shell script to empty the trash on a single volume' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A shell script to empty the trash on a single volume
Authored by: GaelicWizard on Feb 24, '03 03:11:50PM
This script is bad. It deletes all the trashes for all users on that disk, which, unless you are the ONLY user on the machine, is not good. This also uses 'sudo' which should only be used if you are trying to delete a difficult file. Also this cannot delete the trash in the root volume, as it is not mounted in /Volumes. A revision that sorrects all but that last point follows:

#!/bin/sh
# Selectively dump the trash on named volume $1.

cd "/Volumes/$1" # produce sensible error msg if input volume name not found
rm -frv "/Volumes/$1/.Trashes/$UID/*"

---
--
Pell

[ Reply to This | # ]

A shell script to empty the trash on a single volume
Authored by: Andrew Fletcher on Feb 25, '03 07:31:51AM

Anybody copying this script should check and double check that there is no space before the "*" on the rm line. If a space is inadvertently put there the script will remove all your files on that volume.

Andy



[ Reply to This | # ]
Danger will robinson
Authored by: SOX on Feb 25, '03 11:00:08AM

this script is still dangerous.
if the CD fails the RM takes place in the current directory.

you can make the result conditional like this

( cd somedirectoy ) && ( rm somefile)

also as another poster you do not check to the possibility of spaces in the UID environment variable. In a perfect world there would be none. but the consequences if there are any is that you erase the disk!



[ Reply to This | # ]
Danger will robinson
Authored by: GaelicWizard on Feb 26, '03 03:01:29AM

Your first concer is resolved by the absolute path in the 'rm' command, and your second is resolved by the "Quotes" around the path. ;)

JP

---

Pell



[ Reply to This | # ]
Danger will robinson
Authored by: oink on Nov 05, '03 11:19:46PM

From your suggestion, I make this:

( cd /Volumes/aaa/Trash ; pwd ) && ( rm -friv * ) ;( cd /Volumes/aaa/.Trashes ; pwd ) && ( rm -friv * ) ; ( cd /Trash ; pwd ) && ( rm -friv * ) ; ( cd /.Trashes ; pwd ) && ( rm -friv * ) ; ( cd ~/.Trash ; pwd ) && ( rm -friv * )

the pwd is just to make sure I am in the correct directory and I currently use the -i just to make sure everything is okay.

I am sure it is not the most efficient command, but I switch back and forth between 9 and x and have several drives attached and I seem to have trash cans under all sorts of names on each disk. I am hoping to be able to routinely run such a command (probably an alias) and do what I manually do currently...



[ Reply to This | # ]