Hi,
I just want to ask if you have an idea on how to sort files by date in bash script?
I have a bash script but i don't know how to put sort command on it.
Here is my script below:
Code:
Code:
#!/bin/bash
DATESTRING=`date +%m%d%Y`
#read directory
cd /home/mitch/project
echo "LAST BACKUP: "
for file in `dir -d *`;
do
s=`echo $file | cut -c 6-12` #extract the date on the file
echo "$s"
done
echo "-------------"
echo "RESULT"
if [ $s = "$DATESTRING" ]; then
echo "BACKUP SUCCESSFULLY"
else
echo "No Backup: $DATESTRING"
fi
Your help is very much appreciated.
Thanks