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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-22-2009, 08:30 AM
|
#1
|
LQ Newbie
Registered: Jan 2009
Posts: 12
Rep:
|
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.
|
|
|
01-22-2009, 08:38 AM
|
#2
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
well that seems fine... have you not tried it?? :confused?
|
|
|
01-22-2009, 09:04 AM
|
#3
|
LQ Newbie
Registered: Jan 2009
Posts: 12
Original Poster
Rep:
|
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
|
|
|
01-22-2009, 09:04 AM
|
#4
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
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.
|
|
|
01-22-2009, 09:10 AM
|
#5
|
LQ Newbie
Registered: Jan 2009
Posts: 12
Original Poster
Rep:
|
i have many subdirectories under /source/dir
can you please give me example for the --parents option ?
thank.
|
|
|
01-22-2009, 09:28 AM
|
#6
|
LQ Newbie
Registered: Jan 2009
Posts: 12
Original Poster
Rep:
|
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.
|
|
|
01-24-2009, 09:54 AM
|
#7
|
Member
Registered: Jan 2009
Posts: 29
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 05:11 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|