LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-26-2006, 11:03 AM   #1
steinz
Member
 
Registered: Mar 2006
Posts: 58

Rep: Reputation: 16
cp by date


Hi,

I have many files in a directory all starting with the same string. I want to copy only the most recent 3 files to another directory. Can this be done on the command line using cp?

Thanks
 
Old 09-26-2006, 11:09 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

This: ls -tr <firstpartoffile>* | tail -3 gives you the most recent 3 files.

cp `ls -tr <firstpartoffile>* | tail -3` DIRECTORY copies these 3 files to DIRECTORY.

Hope this helps.
 
Old 09-26-2006, 11:16 AM   #3
steinz
Member
 
Registered: Mar 2006
Posts: 58

Original Poster
Rep: Reputation: 16
yes that helps alot. Thanks so much.

Randy
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
current date - yesterday's date newbie_adm Linux - Newbie 4 09-04-2006 03:56 PM
Setting date namit Linux - Newbie 3 04-03-2006 11:02 PM
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 10:17 AM
about the date bigapple Programming 6 08-07-2005 05:33 AM
lastlog date does not match system date? jcmj Linux - Networking 6 10-22-2002 12:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration