Listing file names as soon as they are created


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing file names as soon as they are created
# 1  
Old 01-22-2010
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.
# 2  
Old 01-22-2010
Since you're apparently using Linux, why not use the inotify interface.
# 3  
Old 01-22-2010
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. Smilie

find . -name "*.xml" -mmin -2 -exec ls -i --full-time {} \; | sort -k1
# 4  
Old 01-22-2010
But once you start deleting files, the inode number will not necessarily be larger for newer files.
# 5  
Old 01-23-2010
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.
# 6  
Old 01-23-2010
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
# 7  
Old 01-23-2010
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 ! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Listing column names in CSV file

Hi, I have a .csv file that has ~600 columns and thousands of rows. I would like to create a numerical list of the column names (so that I can later easily select the columns I want to extract). The format that I would hope for is something like: 1 "ID" 2 "X" 3 "Y" .. 600 "Z" ... (4 Replies)
Discussion started by: aberg
4 Replies

2. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

3. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

4. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

5. Shell Programming and Scripting

Listing latest modified or created files recursively

Hi, I want to display latest files (created or modified) recursively in a path. I tried in different ways, but didn't get any desired output: find $path -type f -exec ls -lt {} \; | sort -n -r find $path -type f -printf %p";" | xargs -d ";" ls -t Second one is giving the error:... (21 Replies)
Discussion started by: karumudi7
21 Replies

6. Shell Programming and Scripting

Shell script variable names created dynamically

Hi, I'm trying to use a config file to define frequencies for checking log files. If the config file contains a frequency it will be used else a default value. The format of the config file (and hence the environment variable) is FREQ_log_logname=value A test shell script as below:... (2 Replies)
Discussion started by: u671296
2 Replies

7. UNIX for Advanced & Expert Users

script regarding listing long group names

Hello, When listing the file systems (using ls -ltr) , if the group names are longer the group name is getting truncated. Can someone help with the script which would display the truncated group name? I appreciate if someone could help in this regard. (1 Reply)
Discussion started by: mike12
1 Replies

8. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

9. UNIX for Dummies Questions & Answers

Listing full file names with the exact length of 3 characters

This is what I have to do: Display the full file name (including the full path) and file size of all files whose name (excluding the path) is exactly 3 characters long. This is the code I have: find / -printf "Name: %f Path: %h Size: %s (bytes)\n" 2>/dev/null | grep -E "Name: .{3,} Path" |... (7 Replies)
Discussion started by: Joesgrrrl
7 Replies

10. UNIX for Dummies Questions & Answers

Listing all the files names not starting as

hello all, iam new to shell scripting.I have searched the forum and could'nd find a close enough answer and hence this post: I want to list all the file names whose names don't start as abc. For example if my folder constains files with names: abc123.txt,erdf23.rdf,ed45r.fmb i want a... (13 Replies)
Discussion started by: valluvan
13 Replies
Login or Register to Ask a Question