I'm not looking to format the stick at all, but rather to iterate through the files deleting them all (though after typing 'iterate through' I can sense a Python script coming along.

So far I've been doing rm filename1 rm filename2 rm filename3 etc, is there a way to just 'rm -all' while on in the root of the USB drive?

  • 2
    man is your friend. – Kale Muscarella Sep 6 '13 at 17:53
  • I tried this before posting -- couldn't figure it out. – Dave Melia Sep 6 '13 at 17:54
  • rm filename* or rm | grep filename – Everett Sep 20 '13 at 21:17


rm -rf *

Be carefull where you are when you run this it will delete everything from the current directory and all subdirectories.

If you only want to delete files, and no directories use:

rm *

As @DanielAndersson very correctly pointed out in the comments, this will not delete hidden files and directories (those beginning with a .). To delete those as well do

rm -rf * .*

This will give an error about not being able to delete . and .. (the current and parent directories respectively). You can safely ignore that, rm will never delete these since they are protected by the POSIX standard (see here and here). If you don't want to see the error message you can specify that you only want to delete those dotfiles and folders whose . is followed by a non . character:

rm -rf * .[^.]*

Finally, if you want to delete all files in the current directory and all subdirectories but keep the directories, do this:

find . -type f -delete
  • You're the man! Thanks @terdon -- I would upvote but you need 15 rep :( – Dave Melia Sep 6 '13 at 17:53
  • 9
    I'll remember September sixth as the first time in the history of the internet someone legitimately recommended executing rm -rf *. – Marcks Thomas Sep 6 '13 at 18:03
  • @DaveMelia if you can't upvote, please at least accept the answer (the tickmark on the left) so the question can be marked as answered. – terdon Sep 6 '13 at 18:22
  • 2
    One could note that hidden files and directories in the current directory won't be erased by rm -rf * (unless dotglob happens to be set). – Daniel Andersson Sep 6 '13 at 18:57
  • 1
    @justbrowsing true but that will just give an error message about not being able to delete . and ... I don't know if that is a GNU thing though so, I'll make that clear in the answer. – terdon Sep 8 '13 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.