muaddib
December 12th, 2007, 04:02 AM
Is there any easy/uniform way to access the last-modified time of a file from either bash or perl?
I wrote a bash script to back up files individually, which parses the command ls -l and strips out the date. It has worked perfectly for a while: it copies a file like 'file2.txt' to 'file2.txt.old-20071128', (where 20071128 is the date 'November 28, 2007'). Unfortunately, my script broke on the new system (note: both are ubuntu):
On the old system, the command 'ls -l' results in:
-rw------- 1 username username 0 2007-12-12 01:40 file1
-rw-r--r-- 1 username username 0 2007-12-12 01:40 file2.txt
On the new system, the same command shows:
-rw------- 1 username username 0 Dec 12 07:45 file1
-rw-r--r-- 1 username username 0 Dec 12 07:45 file2.txt
As you can see, the new system does not show the year, and the date is displayed in a difficult-to-parse format, which I cannot easily change. I think that there must be some easy way of accessing the last-modified date of a file (preferably in perl or bash). Anyone know how?
I wrote a bash script to back up files individually, which parses the command ls -l and strips out the date. It has worked perfectly for a while: it copies a file like 'file2.txt' to 'file2.txt.old-20071128', (where 20071128 is the date 'November 28, 2007'). Unfortunately, my script broke on the new system (note: both are ubuntu):
On the old system, the command 'ls -l' results in:
-rw------- 1 username username 0 2007-12-12 01:40 file1
-rw-r--r-- 1 username username 0 2007-12-12 01:40 file2.txt
On the new system, the same command shows:
-rw------- 1 username username 0 Dec 12 07:45 file1
-rw-r--r-- 1 username username 0 Dec 12 07:45 file2.txt
As you can see, the new system does not show the year, and the date is displayed in a difficult-to-parse format, which I cannot easily change. I think that there must be some easy way of accessing the last-modified date of a file (preferably in perl or bash). Anyone know how?