Operating System - HP-UX
1828258 Members
2886 Online
109975 Solutions
New Discussion

Help on the shell script.

 
Gulam Mohiuddin
Regular Advisor

Help on the shell script.

My following command is working fine, but now the number of directory names I need to prune is getting bigger in turns this command is getting larger and larger.

find /psoft -mtime +30 -name "PSDSTSRVLOG" -prune -o -name "PSPRCSRVLOG" -prune -o -name "TUXLOG" -prune -o -print | xargs rm -rf


Is there any way I can shorten this command while accommodating more directory names?

for examles.

prune_dir_list=PSDSTSRVLOG PSPRCSRVLOG TUXLOG TUXLOG2 TUXLOG3 TUXLOG4..

find /psoft -mtime +30 -name $prune_dir_list -prune -o -print | xargs rm -rf


Thanks,

Gulam.
Everyday Learning.
4 REPLIES 4
Joseph C. Denman
Honored Contributor

Re: Help on the shell script.

You should have no problems.

prune_dir_list="PSDSTSRVLOG PSPRCSRVLOG TUXLOG TUXLOG2 TUXLOG3 TUXLOG4"
for x in $prune_dir_list
do
find /psoft -mtime +30 -name ${x} -prune -o -print | xargs rm -rf
done


...jcd...
If I had only read the instructions first??
James R. Ferguson
Acclaimed Contributor

Re: Help on the shell script.

Hi Gulam:

You could use a pattern file with 'grep' to perform filtration, something like:

# find /path -xdev -type f -mtime +30 | grep -v -f /tmp/skippatterns | xargs ls -l

Regards!

...JRF...
Peter Godron
Honored Contributor

Re: Help on the shell script.

Gulam,
you may also want to have a look at the gnu version of find, which has a wide range of additional useful parameters, documented at:
http://www.gnu.org/software/findutils/manual/html_mono/find.html
Peter Nikitka
Honored Contributor

Re: Help on the shell script.

Hi,

you can generate an option list for find:

prune_dir_list='PSDSTSRVLOG PSPRCSRVLOG TUXLOG TUXLOG2 TUXLOG3 TUXLOG4'

findopt='-mtime +30'
for entry in $prune_dir_list
do findopt=$findopt" -name $entry -prune -o"
done

find /psoft $findopt -print ...


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"