Register
It is currently Sun Dec 21, 2014 2:25 pm

Sort files by date created


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Jul 28, 2010 5:53 am   

Joined: Wed Jul 28, 2010 5:45 am
Posts: 1
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


Top
 Profile  
 PostPosted: Wed Jul 28, 2010 7:03 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
hey,

first, cd is rarely useful in scripts
second, don't use commands with for loops
last, why not just use ls -1t


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP