Share your knowledge at the LQ Wiki.
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, 08: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 09:41 AM.
Old 05-16-2007, 08: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: 344Reputation: 344Reputation: 344Reputation: 344
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 09:50 PM
Script for unpacking archives of any sort? Whiskerz Linux - General 9 09-13-2006 08:38 PM
bash script to sort files by extension otheralex Programming 7 08-19-2005 02:40 AM
Help - My Samba share changes the timestamp when copying files to it.. Preserve Time. hheejj Linux - Software 2 06-28-2005 09:34 AM
Files being created with GMT timestamp Locura Slackware 0 12-07-2004 08:54 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:21 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
Open Source Consulting | Domain Registration