Lico_w
asked on
Unix BASH Scripting - Removing unreferenced files
I have the following script which has been created below. The idea is to identify any 'war' files within a directory that haven't got a symbolic link pointing to them and remove them.
So first it needs to find the name of the link file, to store it to a temporary location, then finds war files and compares.....
However I cant get the first line to work and am getting the following error:
find: bad option -ls
Any suggestions anyone?
So first it needs to find the name of the link file, to store it to a temporary location, then finds war files and compares.....
However I cant get the first line to work and am getting the following error:
find: bad option -ls
Any suggestions anyone?
#/usr/bin/ksh
cd /home/T104AHE
find . -type l -ls |awk '{print $NF}' >/tmp/$$
find. -name *.war -type f | while read file
do
file=${file##./}
echo $file | grep -qf /tmp/$$ && rm -f $file
done
rm -f /tmp$$
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Correct, sorry!
ASKER
Perfect thanks. I had to update me script a tad also as it was removing those files that WERE linked whereas I wanted to remove those that WEREN'T.
One thing I get the below message when I run the script, is this anything to be worried about?
sh: ./new_tidy.sh:: not found.
One thing I get the below message when I run the script, is this anything to be worried about?
sh: ./new_tidy.sh:: not found.
OK,
the "&&" should have been "||", right?
As for the other problem:
Look at the first line of your script:
#/usr/bin/ksh
should be:
#!/usr/bin/ksh
the "&&" should have been "||", right?
As for the other problem:
Look at the first line of your script:
#/usr/bin/ksh
should be:
#!/usr/bin/ksh
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect many thanks!!!!
What OS are you running this on?
ASKER
It's a HP Unix box, if I do uname -a it shows:
B.11.23 U
I assume that's the version no?
B.11.23 U
I assume that's the version no?
OK, that explains why you have a different version of find.
ASKER