Listing file names as soon as they are created

Hi,

I have been looking for a method to list file names as soon as they are created. I have used the following command :

find . -name "*.xml" -mmin -2 -exec ls --full-time {} \; | sort -k6

this finds all xml files created in the last 2 minutes and orders them by time. The problem is that our unix system does not set the milliseconds for the file creation timestamp, so the ordering of files is done at the seconds scope, but i need the milliseconds in order to list the files in the correct order, because many are created at the same second.

I would need a command like "tail" that outputs the file names the moment they are created. either a command or a script would be great.

if any clarification is required please let me know.
thanks.

Since you're apparently using Linux, why not use the inotify interface.

Hi,

You are right, i am on a linux system : 2.6.9 kernel

inotify and dnotify are not installed.

would you have any other suggestions, would be much appreciated.

thanks.

---------- Post updated at 04:09 PM ---------- Previous update was at 03:24 PM ----------

In case anyone ever has the same question and stumbles across this post.

I just ended up reading the ls manual and listing the files by inode id, and sorting on this column. :b:

find . -name "*.xml" -mmin -2 -exec ls -i --full-time {} \; | sort -k1

But once you start deleting files, the inode number will not necessarily be larger for newer files.

That is fine for the situation i was needing this for.

I have a service call that generates multiple log files, many created at the same second. Since the milliseconds are not used on the system, i couldnt order it with that. The inode works for this situation, but i guess you are right that it will not work if there are files being deleted on the system elsewhere. For my situation though, i run the service, list the files, so there is almost no chance that other files have been deleted since.

Thanks for the warning though.

If all these files are being dropped into a single directory, how often do you delete and recreate the directory itself? There must be some file naming convention used to prevent duplicates, can it not be used in such way that listing by file name will also be chronological?

Jack

That's a fair enough approach of ordering files based on the filename. But that won't be case always. If there are 2 different systems without any protocol for filenaming/log filenaming convention, then this won't be always followed.

An example could be : a system that takes care of log files alone cannot request/demand other systems to create filenames in specific format.

That liberty is not there always ! :slight_smile:

My assumption was that in the original post, the term log was used to mean a transaction, and that each file contains a single transaction, in which case all sources of data have to follow the same file name convention, rather than a typical log file that has transactions appended to it.
Another concept might be to email the file, and have the email piped to a process. This would guarantee a first in first out sequence, based on the time the file was received, however, it might not mean first sent, first processed.