10

I have a sample dir as follows:

/path/to/dir/
- f1.txt
- f2.txt
- f3.txt

I want to clear or remove all the files under /path/to/dir without actually deleting the directory /path/to/dir itself.

How to do it?

Currently, I am just using the rm -rf /path/to/dir command to remove the directory and the creating the directory again using mkdir /path/to/dir. But this command deletes the directory also.

Eliah Kagan
  • 119,640

2 Answers2

8

Use wildcard (*)

rm /path/to/dir/*

Will remove all file under /path/to/dir directory.

Liso
  • 15,677
6

Remove all files and directories in directory dir/ including .dot files.

$ find /path/to/dir/ -mindepth 1 -delete