LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-07-2010, 02:09 AM   #1
thangappan
Member
 
Registered: May 2009
Posts: 52

Rep: Reputation: 16
Cool Way to sort a files based on the creation time


Dear all,

$>file
$>file1
$>file2

The above commands are created the files one by one in order.
So if I used ls -lrt ( that is not "l" that is "1(one)"

It listed out
file
file1
file2


If the file is created at the same time, consider the following case
$tea file file1 file2

If I used ls -lrt
# it listed out
file2
file1
file

But I want to get the files in order which they created like file, file1 and file2

Any way to obtain this?

Thanks in advance.....
 
Old 07-07-2010, 02:43 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I'm afraid it's not possible since the files have been actually created at the same time or at least below the time resolution of the filesystem. For example consider the following:
Code:
$ touch file file1 file2
$ ls -lc --full-time
total 12
-rw-r--r-- 1 colucix users 0 2010-07-07 09:35:14.000000000 +0200 file
-rw-r--r-- 1 colucix users 0 2010-07-07 09:35:14.000000000 +0200 file1
-rw-r--r-- 1 colucix users 0 2010-07-07 09:35:14.000000000 +0200 file2
there is no difference in nanoseconds among the timestamps because this information is not stored in the filesystem (ext3 in my example). I'm not sure about this, but the resolution of the ext4 filesystem should lower to 1 nanosecond.
 
Old 07-07-2010, 11:32 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
Note also that there is no 'file creation' time in Unix: it's atime (file access), mtime (file content modified), ctime (inode info Change time ie change of content in owning dir file eg owner, perms etc).
 
Old 07-08-2010, 12:22 AM   #4
thangappan
Member
 
Registered: May 2009
Posts: 52

Original Poster
Rep: Reputation: 16
Way to sort a files based on the creation time

Let me entered into one more level for explaining my requirement.
One process is putting files(file.start and file.end) in common directory. That process will create file.start at first then only file.end.

As of now using "ls -1(one)rt" command getting the files which the way the process created. Process the file.start file and followed by file.end

I should not process file.end at first ( Expected one)

Sometime it may create the files(file.start and file.end) at the same time. ( This can't be controlled )
At that time I need to parse the file.start file first and file.end file next.

So give me some mechanism (programming ,commands..etc) to achieve this in Unix?

NOTE: Doing the development in C programming language.
 
Old 07-08-2010, 11:27 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
Loosely speaking , there are (at least) 3 ways to process files in order

1. by timestamp, if a diff in timestamp exists

2. by filename if the filenaming convention allows eg names are created to a pattern that evolves predictably. Typically this would mean the date/time is part of the filename, but any serial num etc in the name would suffice (eg your example filenames is an easy one)
Obviously there must be some differences in the filenames or it'd be overwriting the one file.

3. by file content; again if the content allows it
 
Old 07-08-2010, 11:59 PM   #6
thangappan
Member
 
Registered: May 2009
Posts: 52

Original Poster
Rep: Reputation: 16
Way to sort a files based on the creation time

In that particular directory there might chance of 100 files with the extensions (.start and .end) with different id.

Example:

1_file.start
1_file.end
test.start
test.end
Thread.start
Thread.end

Expected one :
First need to parse .start extension file and wait for .end file this is one cycle. Here the problem is that if the files are created at the same time then going to parse .end extension file at first. because of relying on the ls -lrt command.It shouldn't be.

NOTE: Don't want to change the things in the process who put the files in the directory. Give me suggestion to the place where the files are being obtained.

Also note that it should be LIVE . It should not take more time to get the .end extension file for the relevance file.
 
Old 07-09-2010, 02:18 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If I understand the requirement well, why not listing only the .start files, then looking for the matching .end? E.g. something like:
Code:
startfile=$(ls -t *.start | head -n1)
# parse file .start here
# now wait for matching file .end to appear
endfile=${startfile/.start/}.end
while [[ ! -f $endfile ]]
do
  sleep 5
done
# parse file .end now

Last edited by colucix; 07-09-2010 at 02:20 AM.
 
  


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
sort oldest 5 files in a directory tree recursively based on timestamp Linux abhelp Programming 1 06-04-2010 04:58 AM
will it be poosile to sort the output of ls command based on timestamp of files. shad.ithbti Linux - Newbie 1 09-15-2009 01:51 AM
Sort files in directories based on the files date... CharlieMike73 Programming 5 09-09-2009 10:04 PM
linux newbie...Q: how to find files and sort by time chucker8 Linux - General 6 05-12-2006 05:01 PM
Comparing files on creation time StarTux Programming 2 08-29-2003 01:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:06 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration