LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-29-2010, 07:33 AM   #1
SriniKlr
LQ Newbie
 
Registered: Dec 2010
Posts: 13

Rep: Reputation: 0
copy all the files in the directory based on the modification date


Quote:
Originally Posted by Kenny_Strawn View Post
Please wrap [CODE] tags aroung any code posted here. The full source that way could still be posted.
Hi All,

I am trying to copy all the files in the directory based on the modification date (i.e created on Dec 29). Not able to find the proper command for this. This is what I have tried.

'

(none) login: root
#
# cd /mnt/hd/
#
# ls *.log
dbg_0.log dbg_13.log dbg_18.log dbg_22.log dbg_27.log dbg_6.log
dbg_1.log dbg_14.log dbg_19.log dbg_23.log dbg_28.log dbg_7.log
dbg_10.log dbg_15.log dbg_2.log dbg_24.log dbg_3.log dbg_8.log
dbg_11.log dbg_16.log dbg_20.log dbg_25.log dbg_4.log dbg_9.log
dbg_12.log dbg_17.log dbg_21.log dbg_26.log dbg_5.log

# ls -l *.log | grep 'Dec 29'
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_20.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_21.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_22.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_23.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_24.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_25.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_26.log
-rwxr-xr-x 1 root root 52297728 Dec 29 2010 dbg_27.log
-rwxr-xr-x 1 root root 23068672 Dec 29 2010 dbg_28.log

# ls -l | grep 'Dec 29' | cp /mnt/usb/
BusyBox v1.11.1 (2010-12-07 11:33:09 IST) multi-call binary

Usage: cp [OPTION]... SOURCE DEST

Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY

Options:
-a Same as -dpR
-d,-P Preserve links
-H,-L Dereference all symlinks (default)
-p Preserve file attributes if possible
-f Force overwrite
-i Prompt before overwrite
-R,-r Recurse directories
-l,-s Create (sym)links

Any hint??

Thanks, SriniKlr
 
Old 12-29-2010, 09:06 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,561

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
@SriniKlr - Do not hijack someone else's question!! Please create your own.
 
Old 12-29-2010, 09:07 AM   #3
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 3,910

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
Quote:
Originally Posted by SriniKlr View Post
Hi All,

I am trying to copy all the files in the directory based on the modification date (i.e created on Dec 29). Not able to find the proper command for this. This is what I have tried.

'

(none) login: root
#
# cd /mnt/hd/
#
# ls *.log
dbg_0.log dbg_13.log dbg_18.log dbg_22.log dbg_27.log dbg_6.log
dbg_1.log dbg_14.log dbg_19.log dbg_23.log dbg_28.log dbg_7.log
dbg_10.log dbg_15.log dbg_2.log dbg_24.log dbg_3.log dbg_8.log
dbg_11.log dbg_16.log dbg_20.log dbg_25.log dbg_4.log dbg_9.log
dbg_12.log dbg_17.log dbg_21.log dbg_26.log dbg_5.log

# ls -l *.log | grep 'Dec 29'
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_20.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_21.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_22.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_23.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_24.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_25.log
-rwxr-xr-x 1 root root 52428800 Dec 29 2010 dbg_26.log
-rwxr-xr-x 1 root root 52297728 Dec 29 2010 dbg_27.log
-rwxr-xr-x 1 root root 23068672 Dec 29 2010 dbg_28.log

# ls -l | grep 'Dec 29' | cp /mnt/usb/
BusyBox v1.11.1 (2010-12-07 11:33:09 IST) multi-call binary

Usage: cp [OPTION]... SOURCE DEST

Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY

Options:
-a Same as -dpR
-d,-P Preserve links
-H,-L Dereference all symlinks (default)
-p Preserve file attributes if possible
-f Force overwrite
-i Prompt before overwrite
-R,-r Recurse directories
-l,-s Create (sym)links

Any hint??

Thanks, SriniKlr
hints? Well, not the sort that help directly, but may help indirectly:
  • This is a thread hijack. Hijacking is where you take someone else's thread and divert it to your own problem. This is possibly acceptable if your problem is very closely related to the original problem, but your problem isn't. The original thread was about writing your own shell and yours about file permissions and copying. Given that, ab defintio, your problem won't be related to the thread title of the original thread, it, cough, won't get the attention that it deserves. (So, you should have started your own thread.)
  • Additionally, the idea of quoting a bit of text that advises you to use code tags, to improve clarity and then not using seems a bit odd, did you actually think about what the part that you read was saying?
 
Old 12-30-2010, 12:05 AM   #4
SriniKlr
LQ Newbie
 
Registered: Dec 2010
Posts: 13

Original Poster
Rep: Reputation: 0
My Apologies for the interrupting the already in progress thread. Advice is noted will be taken care

Thanks SriniKlr
 
Old 01-26-2011, 10:08 AM   #5
Julian Andrews
LQ Newbie
 
Registered: Jan 2011
Distribution: Ubuntu
Posts: 21

Rep: Reputation: 13
Hi SriniKlr

I think you're looking for the find command.

Code:
find /mnt/hd -mtime n -exec cp {} /mnt/usb/ \;
Where n is the number of days ago the file was modified. If you want to automate this, of course, you'll need code to come up with n, but that shouldn't be too hard.
 
  


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
[SOLVED] copying files according to modification date and extension SriniKlr Linux - Newbie 5 01-03-2011 03:45 AM
[SOLVED] merge files by creation/modification date? andre.fm Linux - Newbie 5 10-04-2010 06:41 PM
Bash Script - adding file modification date to end of filenames in directory themonkman Programming 2 09-01-2009 11:45 PM
copy folder/files according to modification date bkcreddy17 Programming 14 10-15-2008 07:24 PM
Date-based copy AdmiralThrawn Linux - General 2 02-23-2004 09:03 AM


All times are GMT -5. The time now is 09:24 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration