Operating System - Linux
1753876 Members
7145 Online
108809 Solutions
New Discussion юеВ

Remove all files except a file generated latest

 
file system
Frequent Advisor

Remove all files except a file generated latest

Hi all.
It's been a nice day.

it is very sticky problem. can you give tips?
I'm going to remove oracle archive log file but generated lastet log file before file system is going to be full.

I'm going to post shell prg related job above,
and give me the solution which is fit for that job.

*Shell #1

#DELETING ARCHIVE LOG.
df -k > c
value=`awk '/\/arch_ispbs/ {print $3}' c`
str=`ps -e|grep save|awk '{print $4}'`
if [ $value -gt 4242880 -a -z "$str" ]; then
(/usr/bin/sh /d) > /dev/null 2>&1
fi
============================================
*Shell #2

touch /arch_ispbs/temp
save -s online -b oracle -l full /arch_ispbs
find /arch_ispbs ! -newer /arch_ispbs/temp |xargs rm
2 REPLIES 2
RAC_1
Honored Contributor

Re: Remove all files except a file generated latest

last_file=$(ls -1tr|tail -1)
echo "Removing all others files now"
find . -type f ! -name "${last_file}" -exec ll -d {} \;
ll ${last_file}

Check this first and then replce -exec ll -d {} with -exec rm {}
There is no substitute to HARDWORK
file system
Frequent Advisor

Re: Remove all files except a file generated latest

Thank you RAC .
I got your help and, editted the shell progrm like this.

#1. Save file before remove all file.
save -s online -b oracle -l full /arch_ispbs

#2. Generate latest file
last_file=`find /arch_ispbs |ls -1|tail -1`

#3. And then remove except latest file had above line

find /arch_ispbs ! -name $last_file|xargs rm

Owe to you, I have glad morning. Thank you