Go Job Hunting at the LQ Job Marketplace
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-16-2007, 09:10 AM   #1
Registered: Mar 2007
Posts: 109

Rep: Reputation: 15
script to sort files according to timestamp

Hi ,

I am planning to write a script to sort the directories in a directory according to the timestamp and then cd into that directory . Retrieve the file with the latest time stamp in that directory .

the script so far is:

a=$(ls /home/test/ab/list | wc -l)
echo "number of files is $a"

ls /home/test/ab/list > /home/test/ab/list/nu

exec < /home/test/ab/list/nu
while read line

cd $line
ls -lt > test


but i dont know why it is not cding into the directory please can you tell me why.


Last edited by aeby; 05-16-2007 at 10:41 AM.
Old 05-16-2007, 09:18 AM   #2
Senior Member
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
You could just ask for the list sorted by time:

ls -lt

or, reverse sorted:

ls -ltr

Try 'man ls' for more options.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to sort image files dtcs Programming 5 09-26-2006 10:50 PM
Script for unpacking archives of any sort? Whiskerz Linux - General 9 09-13-2006 09:38 PM
bash script to sort files by extension otheralex Programming 7 08-19-2005 03:40 AM
Help - My Samba share changes the timestamp when copying files to it.. Preserve Time. hheejj Linux - Software 2 06-28-2005 10:34 AM
Files being created with GMT timestamp Locura Slackware 0 12-07-2004 09:54 AM

All times are GMT -5. The time now is 05:49 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration