Home » Questions » Computers [ Ask a new question ]

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

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?

Asked by: Guest | Views: 289
Total answers/comments: 2
Guest [Entry]

"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."
Guest [Entry]

"open your terminal application

(1) cd {path of the iTouch content}

for example: cd /Users/Mike/Desktop/myTouch

(2) then recurse through the directories and remove content.

find {directory} -type f | tee output

for i in `grep -v .app output`
do
echo ${i}; rm ${i}
done

for example,

find /Users/Mike/Documents/myTouch/ -type f | tee output

for file in `grep -v .app output`
do
echo ${file}
rm ${file}
done"