Ronit Shrivastava
Ronit Shrivastava

Reputation: 41

I want to delete all the files under a directory using shell script, passing file directory as an argument

Sample command:

./delete.sh /path/to/location

|-Path |-to |-location |- file1 |- file2 |- file3 . . |- fileN

Need to delete all the files(file1,file2,file3.....fileN) inside location directory using script

Upvotes: 0

Views: 2351

Answers (1)

Raman Sailopal
Raman Sailopal

Reputation: 12917

Use the find command for this:

find "$1" -maxdepth 1 -type f -delete

Pass the directory as a parameter in the scripts ($1) and then ensure you are only searching the directory at one level with -maxdepth 1 and searching for files only with -f. Delete what ever is found with -delete.

Upvotes: 1

Related Questions