Skip to main content

Romove Remove files and subdirectories of particular folder

deleted 3 characters in body
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228

I need to remove files and sub-directories in a particular folder but not that folder itself.

I am using below command:

find . -type d -depth -mtime +7 -exec rm -rf {} \;

But it throws following error message:

rm: refusing to remove ‘.’ or ‘..’ directory: skipping ‘.’

What should be the correct command I avoid or handle this error message? Is it happening because of option "-depth" in my find command?

Linux version: 
NAME="Red Hat Enterprise Linux Server" 
VERSION="7.1 (Maipo)"

Thanks!

I need to remove files and sub-directories in a particular folder but not that folder itself.

I am using below command:

find . -type d -depth -mtime +7 -exec rm -rf {} \;

But it throws following error message:

rm: refusing to remove ‘.’ or ‘..’ directory: skipping ‘.’

What should be the correct command I avoid or handle this error message? Is it happening because of option "-depth" in my find command?

Linux version: NAME="Red Hat Enterprise Linux Server" VERSION="7.1 (Maipo)"

Thanks!

I need to remove files and sub-directories in a particular folder but not that folder itself.

I am using below command:

find . -type d -depth -mtime +7 -exec rm -rf {} \;

But it throws following error message:

rm: refusing to remove ‘.’ or ‘..’ directory: skipping ‘.’

What should be the correct command I avoid or handle this error message? Is it happening because of option "-depth" in my find command?

Linux version: 
NAME="Red Hat Enterprise Linux Server" 
VERSION="7.1 (Maipo)"

Source Link
Nitin
  • 33
  • 1
  • 1
  • 3

Romove files and subdirectories

I need to remove files and sub-directories in a particular folder but not that folder itself.

I am using below command:

find . -type d -depth -mtime +7 -exec rm -rf {} \;

But it throws following error message:

rm: refusing to remove ‘.’ or ‘..’ directory: skipping ‘.’

What should be the correct command I avoid or handle this error message? Is it happening because of option "-depth" in my find command?

Linux version: NAME="Red Hat Enterprise Linux Server" VERSION="7.1 (Maipo)"

Thanks!