File creation time in seconds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File creation time in seconds
# 1  
Old 04-24-2010
Java File creation time in seconds

Hi All,

Cany any one help me in solving this..
Problem statement: I have a requirement to find the time from which there are no files created in a given directory. For this I am assuming that I need to get the file creation time in seconds, then the current time in seconds using `date +%s`. Then calculating the time by subtracting file creation time from date.

Please, help me in getting the file creation time in seconds..


Thanks in advance..
# 2  
Old 04-24-2010
Hi.

If a file is created in a directory, then the timestamp of the directory is updated.

You can get the timestamp of that (seconds since epoch) using the perl stat function, something like:

Code:
perl -e '$epoch = (stat("."))[9]; print "$epoch";'

(. is the current directory)

Subtracting that from date '+%s' would give the difference in seconds.
# 3  
Old 04-24-2010
Java

Hi,

I am new to Perl scripting can you suggest me if there is an option using unix shell scripting ..
or can you please help me with an example script
# 4  
Old 04-24-2010
scottn's code is fine for what you want

You may want to revisit your assumption: for performance reasons, file metadata is not always updated every time an open file is written to. Depending upon a lot of factors the directory could be stale and your test would think no file writes had occurred, when in fact they have.

See the attached white paper.
# 5  
Old 04-24-2010
Java

Thank You for helping me..
# 6  
Old 04-24-2010
Quote:
Originally Posted by chary
Hi,

I am new to Perl scripting can you suggest me if there is an option using unix shell scripting ..
or can you please help me with an example script
It always smells of homework when someone, when given a "solution" that is perfectly simple asks to have it by a specific means.

I'm not familiar with the controls of an Airbus A340, but I still use one to fly to where I want to get to!

Last edited by Scott; 04-24-2010 at 10:59 PM..
# 7  
Old 04-24-2010
Code:
filesec()
{
   perl -e '$epoch = (stat("$ARGV[0]"))[9]; print "$epoch";'  "$1"

}

find /somepath -type d | 
while read fname 
do
     now=$(date "+%s" )
     filetime=$( filesec "$fname")
     echo "Directory $fname last updated $(( $now - $filetime ))"
done

-- this code won't work on Solaris, Solaris date does not like %s

scottn - It may be homework, but I kinda doubt it. We get this question a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sftp file creation time

Hi Team, Could you please let me know ,how to find the file creation date time in SFTP server. i tred like , ls -ltr command only availble and not available like ls --full-time test.txt please help? Thanks (7 Replies)
Discussion started by: bmk123
7 Replies

2. AIX

Getting files through find command and listing file modification time upto seconds

I have to list the files of particular directory using file filter like find -name abc* something and if multiple file exist I also want time of each file up to seconds. Currently we are getting time up to minutes in AIX is there any way I can get file last modification time up to seconds. (4 Replies)
Discussion started by: Nitesh sahu
4 Replies

3. Shell Programming and Scripting

Time take between first and last file creation

Hi , In a folder I have multiple files. I want total time taken to write those files. Can you please suggest what will be the best way to go for it? (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

4. Red Hat

File creation time

Hi Everybody, I would like to know file creation date and time in linux. I went throgh google and forums got some information but from that i am not sure for my question. Please check the following information. "ls -l" ==> but it is just gives the last modified time and date of the file.... (2 Replies)
Discussion started by: mastansaheb
2 Replies

5. Programming

How to search a file based on a time stamp backwards 10 seconds

Hi all, I'm after some help with this small issue which i'm struggling to work out a fix for. I have a file that contains records that all have a time stamp for each individual record, i need to search the file for a specific time stamp and then search back 10 seconds to see if the number... (2 Replies)
Discussion started by: sp3arsy
2 Replies

6. UNIX for Advanced & Expert Users

How to get access time of a file upto the precision of seconds?

Hi , How can I get the last access time of a file upto the precesion of seconds in Unix. I cannot use stat as this is not supported. (10 Replies)
Discussion started by: kanus
10 Replies

7. Shell Programming and Scripting

find file creation time

Hello folks, I have a file, but it change every seconds, i use stats command to check its creation time, but it shows access,modify and change time same. Is there any other way to see the file creation date/time? Thanks (2 Replies)
Discussion started by: learnbash
2 Replies

8. Programming

File creation time

Hi Everybody, Is their any functions to find out the file creation time in 'C' (2 Replies)
Discussion started by: mr_manii
2 Replies

9. UNIX for Advanced & Expert Users

file creation date including seconds

Hi, Is anybody can help me to get the file creation date with seconds? -rw-r--r-- 1 opsc system 422550845 Aug 22 15:41 StatData.20020821 Thanks in advance Krishna (7 Replies)
Discussion started by: krishna
7 Replies

10. UNIX for Dummies Questions & Answers

file creation time

i have to delete some files that were created on a particular date. is there any way to do that without affecting the files that were modified on the same date? (1 Reply)
Discussion started by: sskb
1 Replies
Login or Register to Ask a Question