64

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

muru
  • 193,181
  • 53
  • 473
  • 722
alhelal
  • 2,541
  • 6
  • 26
  • 44
  • 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 01 '16 at 13:46

2 Answers2

76

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 *

Byte Commander
  • 105,631
  • 46
  • 284
  • 425
24

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.

muru
  • 193,181
  • 53
  • 473
  • 722
  • 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 '18 at 22:36
  • 2
    `rm -fr * .*` does the job as well. `.*` does not match `..` or `.`, to be safe. – Artem Russakovskii Aug 06 '19 at 07:04
  • I never tried this, but [Filename expansion](https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html#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 '20 at 01: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 '20 at 01:57
  • @ArtemRussakovskii -- depends on your shell. for instance, bash excludes `.` and `..` but `sh` includes them. but, TIL bash does not. – keithpjolley Sep 21 '22 at 11:56