Operating System - HP-UX
1833011 Members
2920 Online
110048 Solutions
New Discussion

script to walk through subdirectoy

 
SOLVED
Go to solution
kholikt
Super Advisor

script to walk through subdirectoy

I need to walk through all the subdirectory of /Data
for each subdirectory I need to purge out somefile if it is older than 30 days.

The deletion I have done but just wondering how could I walk thourgh each subdirectory of /Data. I have only one level of subdirectory to wallk through
abc
4 REPLIES 4
Rajeev  Shukla
Honored Contributor
Solution

Re: script to walk through subdirectoy

try using find command with -type f -mtime +30 -exec rm {} \;

This will go within subdirectories. Or before actually deleting you can just list them using find command with -exec ll

Vijaya Kumar_3
Respected Contributor

Re: script to walk through subdirectoy

Also, you can use "ls -lR" which is recursive long listing for examining the content. Also "du" command will list all the files including subdirectories and files with their size.

Also, use find command with -mtime option, (best way to find and delete) as posted by previous poster.

Thanks
Vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
T G Manikandan
Honored Contributor

Re: script to walk through subdirectoy

List all the files
#find -type f -mtime +30 -exec ll {} \;
#find -type d -mtime +30 -exec ll {} \;


Make sure those files are not required then you can remove them using

#find -type f -mtime +30 -exec rm {} \;
Jeroen Peereboom
Honored Contributor

Re: script to walk through subdirectoy

A minor note:

It's more efficient to pipe find's output to xargs. (find ... | xargs rm -f).

If you have many files, xargs will only be invoked a few times, whereas rm (from -exec rm) will be invoked many times.

Just a minor note.

JP.