Skip to main content
added 303 characters in body
Source Link
bmike
  • 241.3k
  • 80
  • 433
  • 958

Spotlight can locate folders with a specific name on all mounted and indexed volumes (but it's not going to be the answer - bear with me):

mdls ~/.Trash/

This will show you that the kMDItemFSName is ".Trash" so you might try mdfind to do a spotlight search

mdfind "kMDItemFSName == '.Trash'"

Sadly, this won't find the trashes since Apple has made them invisible and probably excluded them entirely from the spotlight indexing. But, this is the best Apple way to search for general files.

So now, you need to crawl the filesystem:

find / -name .Trash -print

This will throw filesystem errors, so you'll need to engage root - be careful with sudo - you can ruin a system so you can't boot if you move or delete files (which is what you're about to do - find things and then delete them)

 sudo find / -name .Trash -print

Even without the sudo you'll find most of the trashes since your user should be able to write to Trash to store files there.

Now, there is a tool faster than find (it may take tens of minutes or perhaps hours if it starts crawling remote or connected drives)

locate .Trash

The locate database won't likely be built when you ask for it, so follow the instructions it prints if you don't have a pre-made locate database to consult. Happy scripting. Feel free to ask a follow on question on how to delete if you need that help too, but this answers how to find files specifically hidden system ones like the various trash files.

Or, you know - just tell Finder to empty the trash from the command line:

Boom, now you're done super fast no matter where or how the folders are named.

osascript -e 'tell app "Finder" to empty' 

Spotlight can locate folders with a specific name on all mounted and indexed volumes (but it's not going to be the answer - bear with me):

mdls ~/.Trash/

This will show you that the kMDItemFSName is ".Trash" so you might try mdfind to do a spotlight search

mdfind "kMDItemFSName == '.Trash'"

Sadly, this won't find the trashes since Apple has made them invisible and probably excluded them entirely from the spotlight indexing. But, this is the best Apple way to search for general files.

So now, you need to crawl the filesystem:

find / -name .Trash -print

This will throw filesystem errors, so you'll need to engage root - be careful with sudo - you can ruin a system so you can't boot if you move or delete files (which is what you're about to do - find things and then delete them)

 sudo find / -name .Trash -print

Even without the sudo you'll find most of the trashes since your user should be able to write to Trash to store files there.

Now, there is a tool faster than find (it may take tens of minutes or perhaps hours if it starts crawling remote or connected drives)

locate .Trash

The locate database won't likely be built when you ask for it, so follow the instructions it prints if you don't have a pre-made locate database to consult. Happy scripting. Feel free to ask a follow on question on how to delete if you need that help too, but this answers how to find files specifically hidden system ones like the various trash files.

Spotlight can locate folders with a specific name on all mounted and indexed volumes (but it's not going to be the answer - bear with me):

mdls ~/.Trash/

This will show you that the kMDItemFSName is ".Trash" so you might try mdfind to do a spotlight search

mdfind "kMDItemFSName == '.Trash'"

Sadly, this won't find the trashes since Apple has made them invisible and probably excluded them entirely from the spotlight indexing. But, this is the best Apple way to search for general files.

So now, you need to crawl the filesystem:

find / -name .Trash -print

This will throw filesystem errors, so you'll need to engage root - be careful with sudo - you can ruin a system so you can't boot if you move or delete files (which is what you're about to do - find things and then delete them)

 sudo find / -name .Trash -print

Even without the sudo you'll find most of the trashes since your user should be able to write to Trash to store files there.

Now, there is a tool faster than find (it may take tens of minutes or perhaps hours if it starts crawling remote or connected drives)

locate .Trash

The locate database won't likely be built when you ask for it, so follow the instructions it prints if you don't have a pre-made locate database to consult. Happy scripting. Feel free to ask a follow on question on how to delete if you need that help too, but this answers how to find files specifically hidden system ones like the various trash files.

Or, you know - just tell Finder to empty the trash from the command line:

Boom, now you're done super fast no matter where or how the folders are named.

osascript -e 'tell app "Finder" to empty' 
added 431 characters in body
Source Link
bmike
  • 241.3k
  • 80
  • 433
  • 958

Spotlight can locate folders with a specific name on all mounted and indexed volumes (but it's not going to be the answer - bear with me):

mdls ~/.Trash/

This will show you that the kMDItemFSName is ".Trash" so you might try mdfind to do a spotlight search

mdfind "kMDItemFSName == '.Trash'"

Sadly, this won't find the trashes since Apple has made them invisible and probably excluded them entirely from the spotlight indexing. But, this is the best Apple way to search for general files.

So now, you need to crawl the filesystem:

find / -name .Trash -print

This will throw filesystem errors, so you'll need to engage root - be careful with sudo - you can ruin a system so you can't boot if you move or delete files (which is what you're about to do - find things and then delete them)

 sudo find / -name .Trash -print

Even without the sudo you'll find most of the trashes since your user should be able to write to Trash to store files there.

Now, there is a tool faster than find (it may take tens of minutes or perhaps hours if it starts crawling remote or connected drives)

locate .Trash

The locate database won't likely be built when you ask for it, so follow the instructions it prints if you don't have a pre-made locate database to consult. Happy scripting. Feel free to ask a follow on question on how to delete if you need that help too, but this answers how to find files specifically hidden system ones like the various trash files.

Spotlight can locate folders with a specific name on all mounted and indexed volumes:

Spotlight can locate folders with a specific name on all mounted and indexed volumes (but it's not going to be the answer - bear with me):

mdls ~/.Trash/

This will show you that the kMDItemFSName is ".Trash" so you might try mdfind to do a spotlight search

mdfind "kMDItemFSName == '.Trash'"

Sadly, this won't find the trashes since Apple has made them invisible and probably excluded them entirely from the spotlight indexing. But, this is the best Apple way to search for general files.

So now, you need to crawl the filesystem:

find / -name .Trash -print

This will throw filesystem errors, so you'll need to engage root - be careful with sudo - you can ruin a system so you can't boot if you move or delete files (which is what you're about to do - find things and then delete them)

 sudo find / -name .Trash -print

Even without the sudo you'll find most of the trashes since your user should be able to write to Trash to store files there.

Now, there is a tool faster than find (it may take tens of minutes or perhaps hours if it starts crawling remote or connected drives)

locate .Trash

The locate database won't likely be built when you ask for it, so follow the instructions it prints if you don't have a pre-made locate database to consult. Happy scripting. Feel free to ask a follow on question on how to delete if you need that help too, but this answers how to find files specifically hidden system ones like the various trash files.

Source Link
bmike
  • 241.3k
  • 80
  • 433
  • 958

Spotlight can locate folders with a specific name on all mounted and indexed volumes: