Search code examples
linuxdelete-filerm

Remove all files in a directory but not the subdirectories without getting the display "cannot remove directories


rm -f dirname/* will remove all and only files without prompting for each file.

This is what I want,

but this will also display "cannnot remove 'subdirname': Is a directory" for each sub directory.

I want to avoid this.


Solution

  • rm -f dirname/* &> /dev/null