LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-21-2015, 09:39 AM   #1
boby.kumar
Member
 
Registered: Mar 2013
Posts: 94

Rep: Reputation: Disabled
find all the current log file with date and copy to a specific folder.


Hi,
I want to fetch all the current updated files in a directory and copy them to another without using the name of each files.
PHP Code:
userls -head -n1 
This command only gives a file which is last updated. want to all the files with current date and time and copy them.

PHP Code:
userls -lrt
total 60
-rw-------   1 root     sys            0 Mar 17  2009 authlog
drwxr
-xr-x   2 root     sys          512 Oct  9  2009 pool
drwxr
-xr-x   2 root     sys          512 Oct  9  2009 swupas
-rw-r--r--   1 root     other         27 Oct  9  2009 brlog
-rw-r--r--   1 root     root        2192 Oct  9  2009 postrun.log
drwxr
-xr-x   3 root     sys          512 Oct 12  2009 webconsole
-rw-r--r--   1 root     other       1363 Dec 20  2011 sysidconfig.log
-rw-------   1 root     root       20262 Jun 17 16:11 in.iked.log
-rw-r--r--   1 root     root          23 Jun 17 16:11 snmpd.log 
for eg. last two files which is updated on the same time.

Can any one have the command to do this in shell ?

Thanks
 
Old 11-21-2015, 10:36 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,662

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Wow, this sounds familiar:http://www.linuxquestions.org/questi...pt-4175556776/

Again,post what you have tried.
 
Old 11-21-2015, 02:14 PM   #3
normanlinux
Member
 
Registered: Apr 2013
Location: S.E. England
Distribution: Arch
Posts: 161

Rep: Reputation: Disabled
Try looking at the options to the find command
 
Old 11-21-2015, 06:03 PM   #4
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,375

Rep: Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754
The 'touch' command using the '-t' option can create a file with an arbitrary date and time stamp.
The 'find' command in conjunction with the '-newer' option can make use of such a file.
 
Old 11-22-2015, 12:57 AM   #5
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by boby.kumar View Post
Hi,
I want to fetch all the current updated files in a directory and copy them to another without using the name of each files.
PHP Code:
userls -head -n1 
This command only gives a file which is last updated. want to all the files with current date and time and copy them.

PHP Code:
userls -lrt
total 60
-rw-------   1 root     sys            0 Mar 17  2009 authlog
drwxr
-xr-x   2 root     sys          512 Oct  9  2009 pool
drwxr
-xr-x   2 root     sys          512 Oct  9  2009 swupas
-rw-r--r--   1 root     other         27 Oct  9  2009 brlog
-rw-r--r--   1 root     root        2192 Oct  9  2009 postrun.log
drwxr
-xr-x   3 root     sys          512 Oct 12  2009 webconsole
-rw-r--r--   1 root     other       1363 Dec 20  2011 sysidconfig.log
-rw-------   1 root     root       20262 Jun 17 16:11 in.iked.log
-rw-r--r--   1 root     root          23 Jun 17 16:11 snmpd.log 
for eg. last two files which is updated on the same time.

Can any one have the command to do this in shell ?

Thanks
What do you mean by "current"? June 17 is not exactly the current date. Do you mean:
  • The files that were updated today
  • The files that were updated in the current minute
  • Something else?
 
Old 11-22-2015, 06:52 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by boby.kumar View Post
Hi,
I want to fetch all the current updated files in a directory and copy them to another without using the name of each files.
You could do this with syslog.
This way, the syslog-server host would always have the 'latest' copy of any file you choose. In fact, it updates the remote copy in near real-time.

Ask if you want more info on the specifics.
But here's a startup set for 2 files (apache2 access and error).
There's no reason it can't be done for files in /var/log also.
 
1 members found this post helpful.
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
copy a file with a specific date ust Linux - Newbie 3 06-26-2012 06:04 AM
[SOLVED] how to select date and some specific data from a log file shwhooda Linux - Newbie 2 06-25-2012 06:56 PM
Bash Script to Copy Modification Date from a file to his folder pjgm Programming 12 07-31-2011 08:33 AM
find a folder containing a specific file amicke Linux - General 3 04-20-2009 10:04 AM
find a folder not containing a specific file itzfritz Linux - Server 2 09-10-2008 11:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:28 PM.

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