67

I use Ubuntu 14.04 LTS. I tried rm 'ls', rm rf but they did not work.

1
  • 1
    WARNING OF DELETION For just deletion of files on current directory: rm ./* and For deletion of files and folders inside in is rm -R ./* if you want no prompt mode, there is always -f parameter for that
    – Techjail
    Mar 1, 2016 at 13:46

2 Answers 2

82

Use rm * from within the specific directory. The * is a wildcard that matches all files.

It will not remove subdirectories or files inside them. If you want that too, use rm -r * instead.

But be careful! rm deletes, it does not move to trash!

To be sure you delete the right files, you can use the interactive mode and it will ask for confirmation on every file with rm -i *

2
  • 12
    * doesn't match hidden files. You'll need to explicitly reference .* for those. Aug 6, 2019 at 7:02
  • 1
    If you want to remove both visible and hidden files and folders you can call: rm -r * .* Jul 3, 2022 at 18:19
27

rm * will, by default, delete all files with names that don't begin with .. To delete all files and subdirectories from a directory, either enable the bash dotglob option so that * matches filenames beginning with .:

shopt -s dotglob
rm -r *

(The -r flag is needed to delete subdirectories and their contents as well.)

Or use find:

find . -mindepth 1 -delete
# or
find . -mindepth 1 -exec rm -r -- {} +

The -mindepth 1 option is to leave the directory itself alone.

5
  • Let's say i'm emptying a Trash folder. Would "find . -mindepth 1 -delete" follow symlinks, thus delete things in external folders?
    – Motsel
    Jun 13, 2018 at 22:36
  • 3
    rm -fr * .* does the job as well. .* does not match .. or ., to be safe. Aug 6, 2019 at 7:04
  • I never tried this, but Filename expansion allows regexes, thus excluding the .. reference: rm -rf * .[^.]* but this still omits unusual filenames beginning with 2 or more dots such as ..foobar.
    – eel ghEEz
    Nov 26, 2020 at 1:40
  • @eelghEEz Filename expansion most definitely does not allow regexes - it does have similarities in the syntax, but not in the semantics. Extended globbing does have regular semantics, but doesn't match the syntax.
    – muru
    Nov 26, 2020 at 1:57
  • 1
    @ArtemRussakovskii -- depends on your shell. for instance, bash excludes . and .. but sh includes them. but, TIL bash does not. Sep 21, 2022 at 11:56

Not the answer you're looking for? Browse other questions tagged .