LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 10:39 AM   #1
boby.kumar
Member
 
Registered: Mar 2013
Posts: 92

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, 11:36 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,944

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

Again,post what you have tried.
 
Old 11-21-2015, 03:14 PM   #3
normanlinux
Member
 
Registered: Apr 2013
Distribution: Arch and SuSE
Posts: 135

Rep: Reputation: Disabled
Try looking at the options to the find command
 
Old 11-21-2015, 07:03 PM   #4
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,433

Rep: Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352Reputation: 1352
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, 01:57 AM   #5
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,687

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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, 07:52 AM   #6
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,179
Blog Entries: 10

Rep: Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:04 AM
[SOLVED] how to select date and some specific data from a log file shwhooda Linux - Newbie 2 06-25-2012 07:56 PM
Bash Script to Copy Modification Date from a file to his folder pjgm Programming 12 07-31-2011 09:33 AM
find a folder containing a specific file amicke Linux - General 3 04-20-2009 11:04 AM
find a folder not containing a specific file itzfritz Linux - Server 2 09-10-2008 12:23 PM


All times are GMT -5. The time now is 12:47 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration