1832928 Members
2760 Online
110048 Solutions
New Discussion

delete

 
Indrajit Bhagat
Regular Advisor

delete

can you help me in a command to delete the file of Aug 31.
-rw-r--r-- 1 porabat prod 1004 Aug 31 07:40 IFCHAPSIN1070831072920310807074046.dat.Z
-rw-r--r-- 1 porabat prod 1695 Aug 31 07:41 IFCHAPSIN1070831070023310807074105.dat.Z
-rw-r--r-- 1 porabat prod 5095 Aug 31 07:41 IFCHAPSIN1070831062919310807074118.dat.Z
-rw-r--r-- 1 porabat prod 109 Aug 31 07:41 CHAPSIn_Error31AUG2007074117.csv.Z
-rw-r--r-- 1 porabat prod 109 Aug 31 07:41 CHAPSIn_Error31AUG2007074103.csv.Z
-rw-r--r-- 1 porabat prod 109 Aug 31 07:41 CHAPSIn_Error31AUG2007074134.csv.Z
-rw-r--r-- 1 porabat prod 1084 Aug 31 08:11 IFCHAPSIN1070831080002310807081111.dat.Z
5 REPLIES 5
Pete Randall
Outstanding Contributor

Re: delete

for FILE in `ll |grep "Aug31" |awk '{ print $9 }'`
do
rm $FILE
done

You might want to test by replacing "rm" with "ll" first.


Pete

Pete
Laurent Menase
Honored Contributor

Re: delete

ls -l | while read a b c d e f g h i
do
if [ ! -f $i ]
then
continue
fi
if [ "$f" != "Aug" -o "$g" != "31" ]
then
continue
fi
echo "# $(ls -l $i)"
echo "rm $i"
done > myfiletoexecute

check the myfiletoexecute, if it looks ok
sh myfiletoexecute
MarkSyder
Honored Contributor

Re: delete

Pete's suggestion is what I would use, except you appear to have more than one file dated 31 Aug. Your question implies that you only want to delete one file, so I would use rm -i so you will be asked to confirm deletion.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Pete Randall
Outstanding Contributor

Re: delete

Mark makes a good point concerning how many files are to be deleted. My answer assumes that all files dated Aug 31 are to be deleted. If that is not what was intended, then the question needs to be re-stated.


Pete

Pete
Arturo Galbiati
Esteemed Contributor

Re: delete

rm $(ls -l |awk '/ Aug / {print $9}')
use rm -i if you want to confirm each signle file.
HTH,
Art