Retrieving accurate file timestamp


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Retrieving accurate file timestamp
# 1  
Old 04-30-2009
Retrieving accurate file timestamp

Hi Gurus,

The requirement is to collect the timestamp of soft links and collect it in a file in the following pattern:

This is the expected output:

Pattern:
MM/DD/YYYY hh:mi:ss filename

Example:
12/26/2008 10:31:09 <Filename>.zip

The closest way I could get was this:
Code:
ls -lrt | awk -F" " '{print $6"-" $7" ", $8" ", $9}'  > $AUDIT_FILE

But, the output was:

Pattern:
MMM-DD HH:mi filename
Sample:
Apr-29 18:45 <FileName>.zip

Can I get the seconds and the year when the file was changed.

Thanks,
Jiddvish.
# 2  
Old 04-30-2009
Are you using Linux? If so check out the stat command.
# 3  
Old 04-30-2009
I am on Solaris and programming through ksh.

Code:
uname -a
SunOS <ServerName> 5.9 Generic_118558-35 sun4u sparc SUNW,Sun-Fire-V490

# 4  
Old 04-30-2009
this could be done with a small perl script or one liner using stat() and localtime().

check this out. https://www.unix.com/tips-tutorials/2...ime-atime.html

There are may other examples on the forum you can search for.
# 5  
Old 05-01-2009
Hi Frank,
Thanks for the solution, works superbly for me, but I have another issue. The files whose timestamps are being collected are soft links and the timestamps that are getting generated are of the actual file. I need to collect the timestamp of the link file that is getting created.

Code:
for LINKS in `ls`
do
    TIMESTAMP=`perl -e '@d=localtime ((stat(shift))[8]); printf "%02d/%02d/%4d %02d:%02d:%02d\n", $d[4]+1,$d[3],$d[5]+190
0,$d[2],$d[1],$d[0]' $LINKS`
     echo $TIMESTAMP $LINKS
done

Also, is there any way I can pass the filenames directly in a single command without using the for loop. I tried

Code:
find ./ -type f <perl command> {} \;

but it does not work.

any help here is really great.
# 6  
Old 05-01-2009
Code:
ls -l --time-style=full-iso | awk '{print $6,substr($7,1,8),$9}'

cheers,
Devaraj Takhellambam
# 7  
Old 05-01-2009
Quote:
Originally Posted by jidsh
Hi Frank,
Thanks for the solution, works superbly for me, but I have another issue. The files whose timestamps are being collected are soft links and the timestamps that are getting generated are of the actual file. I need to collect the timestamp of the link file that is getting created.

Code:
for LINKS in `ls`
do
    TIMESTAMP=`perl -e '@d=localtime ((stat(shift))[8]); printf "%02d/%02d/%4d %02d:%02d:%02d\n", $d[4]+1,$d[3],$d[5]+190
0,$d[2],$d[1],$d[0]' $LINKS`
     echo $TIMESTAMP $LINKS
done

Also, is there any way I can pass the filenames directly in a single command without using the for loop. I tried

Code:
find ./ -type f <perl command> {} \;

but it does not work.

any help here is really great.
Code:
find ./ -type f -print -exec command '{}' \; 


cheers,
Devaraj Takhellambam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retrieving sequence data from other file

Hello experts :cool:, I am new to programming and will need your help.. I have 2 very large files with the following format: FILE1: >MLP1019 PL4 >MLP7456 PL3 >MLP9268 PL9 >MLP6245 PL1 FILE2: >MLP1019 STNAPLQTSNTWVSYQPSMMMSLQ >MLP7456 PPYWYWNSAVMIFYVQPLSLLAVLLA >MLP9268... (2 Replies)
Discussion started by: narachaid
2 Replies

2. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

3. Shell Programming and Scripting

Retrieving File name

Hi All.. I have a Filename as FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_20110622-161429_07_WFR12345_20110622-161429_20110712-125228.data.dis I want to get the result as... (5 Replies)
Discussion started by: asheshrocky
5 Replies

4. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

5. Shell Programming and Scripting

Retrieving Information From A Syslog File

Hi, I have a number of firewalls that send there traffic logs to a syslog server. Each log entry takes up about 3 lines and the text within the log entry is delimited by a space. There are parts of the three lines that I need from every traffic log entry. I have been using a combination of sed,... (2 Replies)
Discussion started by: andyblaylock
2 Replies

6. UNIX for Dummies Questions & Answers

Retrieving particular row from a dat file

Hi.. I have a dat file containing both column names and data. Now I want to get only Particular row along with the column names. My dat fiel is as below EmpName Dept Salary Shally Admin 20000 Swati HR 15000 Deepali IT 45000 Preetika EEE 60000 Now I want to display only row 3rd along... (5 Replies)
Discussion started by: Mayuri P R
5 Replies

7. Shell Programming and Scripting

Retrieving File's Mime-type

Alright, so I am trying to use perl (or any other shell scripting language, awk/sed/bash for instance), to retrieve the mime-type of a file. I want to keep it in one file, and most of the modules that are on cpan that check for mime types (Magic), aren't installed on these boxes. Anyone have... (2 Replies)
Discussion started by: Rhije
2 Replies

8. UNIX for Dummies Questions & Answers

Retrieving PID from a file

Hello I need to retrieve the content of a file in the shell script file(.sh file). I store the Process ID of the a process in file.Only the PID is available in that file. Inside the shell script i want to retireve the content(PID) and need to check for the existence of the Process.Basically... (5 Replies)
Discussion started by: appleforme1415
5 Replies

9. Shell Programming and Scripting

Automating Rlogin and File Retrieving

Hi, I'm a begginer in Unix Scripting and i'm trying to write a script that performs this functions.. 1. Rlogin to a system 2. Copy a Perl script inTO the system 3. Run the Perl Script 4. Retrieve the result(file) of the Perl Script 5. Copy the result file to a single system 6. Logout of... (3 Replies)
Discussion started by: vicesjr
3 Replies

10. UNIX for Advanced & Expert Users

retrieving a deleted file

hi!, is there any way to retrieve a file that I have deleted few minutes back?? I am using Solaris- 5.6.. :rolleyes: (2 Replies)
Discussion started by: jyotipg
2 Replies
Login or Register to Ask a Question