LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 05-16-2007, 08:10 AM   #1
aeby
Member
 
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:

#!/bin/sh
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
do


cd $line
ls -lt > test

done

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


Regards,
Arsha

Last edited by aeby; 05-16-2007 at 09:41 AM.
 
Old 05-16-2007, 08:18 AM   #2
macemoneta
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: 326Reputation: 326Reputation: 326Reputation: 326
You could just ask for the list sorted by time:

ls -lt

or, reverse sorted:

ls -ltr

Try 'man ls' for more options.
 
  


Reply


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


All times are GMT -5. The time now is 11:06 PM.

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