• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

how to delete files recursively

Hi Folks,

Could you please help me with a command which can deletes file under a particular level?
I have folder structure like below:
/home/ja361203/A/data
/home/ja361203/B/data
/home/ja361203/C/data
/home/ja361203/D/data
/home/ja361203/E/data

what i want is to deleted the all the files under all data folders?
Is it possible to do that?
Please help.
0
jayatallen
Asked:
jayatallen
  • 3
  • 2
  • 2
  • +1
3 Solutions
 
PapertripCommented:
rm -rf /home/ja361203/*/data/*

Open in new window

0
 
jayatallenAuthor Commented:
thank you for your reply.
is there anyway to see what will be deleted? something like verbose?
or something like we get when we use OK flag with find command.
like :

find ./ type -f -ok rm {} \;

this asks if its Ok to delete a file or not?
0
 
PapertripCommented:
To have rm prompt you for each file before deleting, add -i to the syntax
rm -irf /home/ja361203/*/data/*

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
PapertripCommented:
Oh on second thought, -f and -i probably won't play well together.
rm -ir /home/ja361203/*/data/*

Open in new window

0
 
farzanjCommented:
Try this:


rm -f /home/ja361203/{A,B,C,D,E}/data/*

Open in new window

0
 
icenickCommented:
You mentioned deleting files to a certain depth.

The command "find" has the options maxdepth and mindepth. You can find info regarding those options under here:

http://linux.about.com/od/commands/l/blcmdl1_find.htm

In order to see what rm is deleting, you have to specify the option "v", i.e. verbose. For quick deleting of files, pipe the output of find to "xargs", eg:

find /path/ -maxdepth 4 -mindepth 1 -type f | xargs rm -rv

Open in new window


Good Luck!
0
 
farzanjCommented:
You can include  -level with your find command.

0
 
jayatallenAuthor Commented:
thank you guys for your help..all answers are helpful.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now