Macos – Delete all files in a folder without deleting directories? (OS X)


Is there a simple terminal command maybe to delete all actual data, all files but leave all the directories there? Including packages (.app) as directories?

— You don't need to read this:
The reason why is on my iPod Touch, whenever I ssh to /private/var/mobile/Applications to get an icon or something to change for a theme, I have to look through every folder to find the application, since they're all in their unique identifier folders (e.g. 2C053638-26FE-42DD-A235-30FCBA59E623), its impossible to find it. So I copied the Applications folder to my desktop, so I could spotlight search for the application name in it and then the folder that its in would be the unique id folder on the iPod, so having it sorted the same I could easily find it.

Best Answer

Are you wanting to delete just the files from the current directory, or files from sub-directories too? For the latter this would work under most unix-a-like environments

find . -type f -print0 | xargs -0 rm -f

or if you know there are no files or directories with spaces in their names you can simplify a little with

find . -type f | xargs rm -f

I'm not an Apple user so I know little of the .app directories of which you speak, but you should be able to avoid touching them by adding grep between find and xargs like

find . -type f | grep -v \.app | xargs rm -f

Replace rm -f with ls or ls -l in all the above to get a list of what would be deleted instead of actually performing the delete.

Related Question