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

Empty all trash cans at once System
Being inherently multi-user, OS X creates a trash can for each user. There's no simple (GUI) way to empty all of these trash cans. Even if you're logged in as root, you have to remove each one individually. Over in this MacNN forum, however, 'MickS' posted a one-line terminal command that will empty all of your trash cans at once. Warning - this is not un-doable, and you won't get any 'Are you sure?' messages before the trash is emptied.

To empty all the system trash cans at once, start a terminal session and type
sudo find / -name ".Trash" -type d -print | xargs rm -fr
You'll have to enter your admin password, but then it should just run. NOTE: I have not tried this myself yet, so use at your own risk.
  • Currently 1.00 / 5
  You rated: 1 / 5 (2 votes cast)

Empty all trash cans at once | 6 comments | Create New Account
Click here to return to the 'Empty all trash cans at once' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Don't use this!!!!!
Authored by: Anonymous on Apr 29, '01 02:54:00PM

It totally screwed up my session, and might have messed up other accounts. I lost access to the trash in the Finder until I logged out and back in, and I'm just hoping everything is back to normal. This command didn't accomplish anything, and just caused me grief. Do not do it yourself!

[ Reply to This | # ]
Don't use this!!!!!
Authored by: robg on Apr 30, '01 09:22:11AM

Interesting ... I just used the 'find' portion, without the rm -rf, and it returned exactyly what I'd expect -- a listing of my three users' .trash directories.

Once I get my experimental OS X partition set up, I'll try this for real with the 'rm' portion and see what happens.


[ Reply to This | # ]
Don't use this!!!!!
Authored by: robh on Apr 30, '01 06:31:19PM
I'd advise folks to never run a 'find .... | xargs rm ....' type of command without first testing the output of the 'find' to make sure that the files to be removed are the ones you want to zap. The 'find'ing is safe, it's the 'rm'ing that can bite your ass.

[ Reply to This | # ]
bad find results?
Authored by: gabester on Apr 30, '01 11:12:24AM

When I ran the first part of this command, the output was similar to as follows (usernames have been changed to protect my innocence):

find: /dev/fd/4: No such file or directory

I'm thinking if the second line of this result gets piped to the rm command, something chokes?
I'm no UNIX expert, just a casual user. What does the "find: /dev/fd/4: No such..." message mean?
Also, trying to look at /dev/fd/3 and 4 gives me "bad file descriptor" errors.

I also note that on my numerous drive volumes (I have several partitions) there are other trashes that didn't get listed by this command...

So my hunch is if you can run the find without funny stuff, piping it to rm will work fine, but if you get errors from the find then piping to rm will choke your unix subsystem up a bit. Experts, what does the survey say?


[ Reply to This | # ]
bad find results?
Authored by: robh on Apr 30, '01 06:23:36PM

The line of output
find: /dev/fd/4: No such file or directory
is almost certainly sent to STDERR rather than STDOUT, so it won't get passed on to the 'rm' command.

By default, when a unix command line program outputs text, it is printed to STDOUT (standard output). If the app wants to report an error then it prints to STDERR (standard error) instead.

Try these commands
ls /Applications /foobar | wc -l
ls /Applications /foobar |& wc -l

I'm assuming /foobar doesn't exist. In the first command you should see the error message 'ls: /foobar: No such file or directory' and only the filenames in /Applications are passed to the 'wc -l' command (which counts lines) and tells you how many there were. In the second line, I've added a '&' after '|' pipe. In the tcsh (and csh) shell, '|&' means combine STDOUT and STDERR, so the error message doesn't appear in the terminal, it gets piped into the 'wc -l' command instead and the number of lines counted should now be 1 more than for the first command.

To answer the question 'What does the "find: /dev/fd/4: No such..." message mean?'...
/dev is a directory full of unix devices. Unix gives access to all (I think) devices as if you were accessing a file. /dev contains a bunch of devices that the system has access to or is able to support even if you don't have the device (yet).

Try this...
In the terminal preferences, check the "device name" checkbox under "Title Bar".
Now open a new terminal window (command-N)
You should see something like (ttyp2) in the title of the new terminal. Go back to the first terminal and type 'echo hello >/dev/ttyp2' (change the '2' to match the new terminal's title)
You should then see the 'hello' appear in the 2nd terminal.
/dev/ttyp2 is the filename that interfaces to the terminal device.

If you do 'ls -l /dev' you see things like this...
crw-rw-rw- 1 root wheel 1, 0 Apr 14 15:28 cu.modem
brw-r----- 1 root operator 14, 0 Apr 14 15:27 disk0
crw-rw-rw- 1 root wheel 5, 2 Apr 30 23:06 ptyp2

Unlike other files, you'll see the letters 'c' and 'b' at the beginning of the line. These refer to 'character' and 'block' devices. Character devices work with streams of characters, 1 at a time. Block devices manipulate blocks of data. If you attempt to write directly to a block device, you probably won't get far...
echo 'hello' > /dev/disk0
/dev/disk0: Permission denied.
Unix doesn't want you writing character garbage onto its block devices.

[ Reply to This | # ]
BAD advice
Authored by: vipw on May 02, '01 04:23:00AM

this is a good way to learn why you gotta be careful with rm -rf.

particularly, doing a find and piping through xargs rm is dangerous.

the find search will list all directories named .Trash, removing all of them is fine, however using xargs is not the safe way to do it.

say you have "/Users/Bozo/.Trash" and "/Users/Bozo The Clown/.Trash"
both of those will match and will be passed to xargs. however, when xargs runs
"rm -rf /Users/Bozo The Clown/.Trash" it will first remove all of /Users/Bozo, then try removing The, and then try removing Clown/.Trash. this will entirely remove Bozo's home directory and the removal of The and Clown/.Trash will fail.

luckily, find has ways to do this whole procedure correctly.
find / -name ".Trash" -type d -exec rm -rf {} ';'

that will only delete directories named .Trash

better yet is to change -exec to -ok, and then it will prompt you before each trash directory.
find . -name ".Trash" -type d -ok rm -rf {} ';'

even so, using find to clean up .Trash directories is pretty sloppy. you would probably be better off querying the lookupd/netinfo for the users' home dirs and deleting .Trash from there, but hey, i have no idea how to do that, os x doesn't seem to use the password files.

[ Reply to This | # ]