LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-22-2009, 08:30 AM   #1
OrC82
LQ Newbie
 
Registered: Jan 2009
Posts: 12

Rep: Reputation: 0
find command


hi,
is this line make sense ?

find /source/dir/ -mtime -10 -exec cp -rf '{}' /destination/dir/ \;

my goal is to copy all files from /source/dir/ that was created in the last 10 days, to /destination/dir/

the /source/dir/ is something like 40GB with many little files and directories inside.
i think it copy all file and directories from /source/dir/

is this line written right ?
if someone have a better solution for me it will be great.

thanks.
 
Old 01-22-2009, 08:38 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well that seems fine... have you not tried it?? :confused?
 
Old 01-22-2009, 09:04 AM   #3
OrC82
LQ Newbie
 
Registered: Jan 2009
Posts: 12

Original Poster
Rep: Reputation: 0
i have tried it, but it seems like it copy all files from /source/dir/
i can't check if it works, because it change the date of the files it copy to /destination/dir
and as i mentioned i have so many folders and files in the /source/dir. it is not possible to check if it work or not.
so, i just need another opinion to be sure it's OK.

OrC
 
Old 01-22-2009, 09:04 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The only potential problem is if you have subdirectories under /source/dir. Consider using the --parents option.

Consider the -a (archive) option to preserve permissions and ownership. You will need to run it as root to preserve the ownership if it isn't you. If you are a member of the group owner of the file, it will copy to the saved file with the -a option.

Using the -ap option, you want to be in the /source directory and use "find /dir -type f -mtime -10 -exec cp -a --parents '{}' /destination/ \;

The /dir/ will be created due to the --parents option.

To check if the script will select the correct file, add an echo before cp command. The commands will be echoed to the screen instead of being executed.

Last edited by jschiwal; 01-22-2009 at 09:18 AM.
 
Old 01-22-2009, 09:10 AM   #5
OrC82
LQ Newbie
 
Registered: Jan 2009
Posts: 12

Original Poster
Rep: Reputation: 0
i have many subdirectories under /source/dir
can you please give me example for the --parents option ?

thank.
 
Old 01-22-2009, 09:28 AM   #6
OrC82
LQ Newbie
 
Registered: Jan 2009
Posts: 12

Original Poster
Rep: Reputation: 0
Hi jschiwal
now i can see the original date of the folders, and it look like it's making the job like i needed.
thank a lot.
 
Old 01-24-2009, 09:54 AM   #7
renjithrajasekaran
Member
 
Registered: Jan 2009
Posts: 29

Rep: Reputation: 15
This script should also do the trick:


find -mtime 10 /source_folder/ >> ~/files_move.txt

for i in 'cat ~/files_move.txt'
do
cp -v $i ~/target_folder/
done

Linux Archive

Last edited by renjithrajasekaran; 01-25-2009 at 04:02 AM.
 
  


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
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 06:30 PM
Using a single "Find" Command to find files bases on multiple criteria roboxooo Linux - Newbie 6 01-15-2009 05:13 AM
can't find my find command! how to replace? dave247 Debian 4 11-19-2008 11:51 AM
find and mv command nirmit Linux - Newbie 2 06-27-2008 06:45 AM
find command George2 Linux - General 2 08-30-2007 02:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:11 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