V
V
Vasya Pupkin2019-07-03 08:45:36
linux
Vasya Pupkin, 2019-07-03 08:45:36

How to delete folders along with files in shell script?

You need to delete all the contents inside the folder, the folder itself should remain untouched. There is a script: It deletes all files in the Swap folder, but empty folders remain. Help to correct the script so that not only files but also folders inside are deleted.
find /volume1/Swap/ -mtime +0 -exec rm {} \;

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jcmvbkbc, 2019-07-03
@Desert-Eagle

Help to correct the script so that not only files but also folders inside are deleted.

Easily:
find /volume1/Swap/ -depth -mindepth 1 -mtime +0 -delete

S
Sergey, 2019-07-03
@feanor7

rm -rf /tmp/folder/*

V
Victor Taran, 2019-07-03
@shambler81

this is the most famous command in Linux,
even having its own page on lurk and on the wiki
wikireality.ru/wiki/Rm_-rf
lurkmore.to/Rm_-rf

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question