Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-10-2006, 02:43 PM
|
#1
|
Member
Registered: May 2005
Location: Kraków, PL
Distribution: Slackware
Posts: 33
Rep:
|
file age checking
Hi!
Sorry for such noob question, but how to check which of two files is newer?
Thx
|
|
|
03-10-2006, 02:45 PM
|
#2
|
Member
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 929
Rep:
|
ls -l <filename> (lower-case L, not the number 1). All files get a date/timestamp when they're created, and it's updated whenever they're updated (written to).
|
|
|
03-10-2006, 02:47 PM
|
#3
|
Member
Registered: May 2005
Location: Kraków, PL
Distribution: Slackware
Posts: 33
Original Poster
Rep:
|
Can i do it with regexp? I mean: I have two files a.txt and b.txt and want to know whether a.txt is newer (mod. time) then b.txt and then do sth with newer file. ls -l is known to me, but I don't find this much helpful in automated updater (?!?), but thx any way.
Last edited by Oinopion; 03-10-2006 at 02:50 PM.
|
|
|
03-10-2006, 03:00 PM
|
#4
|
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141
Rep: 
|
ls -lt will sort files by modification time so you could use the following to return the listing for the new file:
Code:
ls -lt a.txt b.txt | head -1
If you just want the name:
Code:
ls -lt a.txt b.txt | head -1 | awk '{ print $8}'
or
Code:
ls -lt a.txt b.txt | head -1 | cut -d' ' -f9
|
|
|
03-10-2006, 03:03 PM
|
#5
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Read the "info bash" manual for more.
Quote:
`FILE1 -nt FILE2'
True if FILE1 is newer (according to modification date) than
FILE2, or if FILE1 exists and FILE2 does not.
`FILE1 -ot FILE2'
True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
does not.
|
|
|
|
03-10-2006, 03:11 PM
|
#6
|
Member
Registered: May 2005
Location: Kraków, PL
Distribution: Slackware
Posts: 33
Original Poster
Rep:
|
So why does in not work:
Code:
if 'a -nt b' then echo "aaa" else echo "bbb" fi;
|
|
|
03-10-2006, 03:19 PM
|
#7
|
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141
Rep: 
|
Try the following instead:
Code:
if [ a -nt b ]; then echo "aaa"; else echo "bbb"; fi
|
|
|
03-10-2006, 03:23 PM
|
#8
|
Member
Registered: May 2005
Location: Kraków, PL
Distribution: Slackware
Posts: 33
Original Poster
Rep:
|
Quote:
Originally Posted by gilead
Try the following instead  ...)
|
BIG THX. Thas right what I was looking for. And I'll read man bash! 
|
|
|
03-11-2006, 06:37 AM
|
#9
|
Senior Member
Registered: Jan 2004
Posts: 1,420
Rep: 
|
I'm in the habit of using
all of the time...
|
|
|
All times are GMT -5. The time now is 07:55 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|