Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The closest I've gotten is

# rm /path/to/directory/*.*

but that doesn't work for files that don't have an extension...

share|improve this question
up vote 98 down vote accepted

Linux does not use extensions. It is up to the creator of the file to decide if he wants the name to have an extension. Linux looks at the 1st byte to figure out what kind of file it is dealing with.

To remove everything in a directory use:

rm /path/to/directory/*

You can use the -r option to also remove any directories inside the directory you are removing the content of. Otherwise it will show an error informing you it is not removing the directory.

share|improve this answer
If you also want to delete hidden files run shopt -s dotglob before running rm (...) – danjjl Sep 6 '11 at 8:10
Wow that's pretty incredible that you know that off the top of your head. What exactly does the asterisk mean? – user784637 Sep 6 '11 at 8:12
The * means all files ;) *.* means all files containing a . somewhere in the name – Rinzwind Sep 6 '11 at 8:20
@Rinzwind, more accurately, the asterisk means "zero or more of any character". So *a* means zero or more characters, followed by a followed by zero or more characters. It would match the filenames happy, apple, a or la. – DisgruntledGoat Sep 6 '11 at 13:43
@user784637 you are too easily impressed – barlop Sep 3 '14 at 16:10
  • To remove the folder with all its contents(including all interior folders):
    rm -rf /path/to/directory

  • To remove all the contents of the folder(including all interior folders) but not the folder itself:
    rm -rf /path/to/directory/*

  • To remove all the "files" from inside a folder(not removing interior folders):
    rm -f /path/to/directory/*

rm - stands for "remove"
-f - stands for "force" which is helpful when you don't want to be asked/prompted if you want to remove an archive, for example.
-r - stands for "recursive" which means that you want to go recursively down every folder and remove everything.

share|improve this answer

If you also want to remove all subdirectories and the directory itself, you can use rm -rf /path/to/directory. But always double-check your line before pressing return, rm -rf can cause lots of havock as well, e.g. if you accidentally insert a space after the first slash while having superuser permissions...

share|improve this answer

If you want to delete only files in /path/to/directory you can do

find /path/to/directory -type f -print0| xargs -0 rm


find /path/to/directory -type f -exec rm {} \;

You can do loads with find, the advantage is you can list what is found without piping it to rm so you can see what will be deleted before you start.

share|improve this answer
GNU find as a -delete predicate. If you still want to use -exec, substituting \; with + will gather rm calls together, increasing efficiency. – enzotib Sep 6 '11 at 12:19
large amount of files with '+' will cause problems, since list will be too large, same as rm -f *. and when removing large amounts of files from same folder (talking in millons) both of them are not good :) In the end C++ came along and removed files in order of inodes in dir-tree. – Osis Sep 6 '11 at 12:53
You really ought to add a -- after the rm. Without that if you have a file names -rf or similar will be interpreted as arguments to rm. e.g. xargs -0 rm -- or -exec rm -- {} \; – Richm Sep 6 '11 at 13:52
you can also provide the -n argument to xargs. That will cause it to split the rm commands to having a maximum number of arguments i.e. 'xargs -n 100 -0 rm --' will remove files in chunks of 100. – Richm Sep 6 '11 at 13:54
You can also add -maxdepth 1 to ensure that find does not return files from any subdirectories. i.e. find /path/to/directory -maxdepth 1 -type f – Richm Sep 6 '11 at 14:10

To remove all files in directory (including hidden files and subdirectories) run:

rm -rf /path/to/directory/{*,.*}
share|improve this answer

You can cd into the directory and then run the command rm *.* just like in DOS if you remember.

share|improve this answer
DOS is DEL for files and RMDIR for emptied directories- and hidden and system files must have those ATTRIB attributes removed first. Not nearly as simple ;) – Eric Jun 10 '15 at 13:03

To delete all files and directories(including the hidden ones) in a directory, you can try the following:

  • delete the folder, then recreate it

    \rm -rf dir_name && mkdir dir_name

  • use find

    find dir_name -mindepth 1 -delete

Here we specify -mindepth 1 to exclude the directory dir_name itself.
Take a look at the following link:

share|improve this answer
Thanks for your advice and I've added more explanation for the links. – zeekvfu Nov 28 '13 at 5:04
Be careful, since deleting and re-creating the folder might result in different/wrong permissions for this folder! – einjohn Aug 29 '15 at 12:20

a simple way to remove all the files from directory

  1. simply go to that directory in command-line
  2. use the command

    rm `ls`
share|improve this answer
That will not work itf you have fuile names containing e.g. space characters. It doesn't have any advantages over a simple rm *. – Florian Diesch May 27 '14 at 15:07
rm -rf /path/to/directory/*

This will delete the entire directory. If we use

rm -r /path/to/directory/*

it will only delete sub-directories inside the directory and if we use

rm /path/to/directory/*

it will only delete the files present inside the directory. And if a sub-directory is present it will throw an error stating it's a directory.

share|improve this answer
-1 This is plain wrong. rm -r path/* and rm -rf path/* both delete all (non-hidden) entries of path whether they're directories or not. path itself isn't deleted by any of those commands. Please see rm(1). – David Foerster Nov 23 '14 at 9:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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