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 |
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-11-2005, 03:48 AM
|
#1
|
|
Member
Registered: May 2004
Location: Israel
Distribution: Debian
Posts: 98
Rep:
|
how to tell bash to move files to another folder?
I get my files using find . -mmin -120 but now how can I tell mv to move them to another place ?
|
|
|
|
02-11-2005, 04:10 AM
|
#2
|
|
LQ Newbie
Registered: Feb 2005
Posts: 14
Rep:
|
Does cp work?
cp /folder/fileorigin /folder/destination
|
|
|
|
02-11-2005, 04:10 AM
|
#3
|
|
Member
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720
Rep:
|
try
$mv $(find . -mmin -120) /foo/bar
i'm not sure, I didn't try that.
hamish
|
|
|
|
02-11-2005, 04:12 AM
|
#4
|
|
Senior Member
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113
Rep: 
|
append
-exec mv {} target \;
to the command.
|
|
|
|
02-11-2005, 04:24 AM
|
#5
|
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,780
|
Add an exec to your find; example:
Code:
find . -name "*.txt" -exec cp {} /mydir \;
This example copies all text-files that have been found to the directory /mydir.
You will probably use mv instead of cp, but the principle is the same.
Please note that if /mydir is part of the searchpath of find, you will get error messages (or warnings) from cp (and probably mv) that source and destination are the same file.
The curly braces indicate to exec to use the result of the find operation.
Last edited by Wim Sturkenboom; 02-11-2005 at 04:42 AM.
|
|
|
|
02-11-2005, 05:06 AM
|
#6
|
|
Member
Registered: May 2004
Location: Israel
Distribution: Debian
Posts: 98
Original Poster
Rep:
|
Quote:
Originally posted by Wim Sturkenboom
The curly braces indicate to exec to use the result of the find operation.
|
Could you please explain this a bit more, it's not the first time that I see this way of bash scripting and it's quite confusing because I haven't seen in no manual what so ever.
Thank you.
|
|
|
|
02-11-2005, 05:09 AM
|
#7
|
|
Senior Member
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113
Rep: 
|
man find (/-exec)
Code:
-exec command ;
Execute command; true if 0 status is returned. All
following arguments to find are taken to be argu_
ments to the command until an argument consisting
of `;' is encountered. The string `{}' is replaced
by the current file name being processed everywhere
it occurs in the arguments to the command, not just
in arguments where it is alone, as in some versions
of find. Both of these constructions might need to
be escaped (with a `\') or quoted to protect them
from expansion by the shell. The command is exe_
cuted in the starting directory.
|
|
|
|
02-11-2005, 05:29 AM
|
#8
|
|
Member
Registered: May 2004
Location: Israel
Distribution: Debian
Posts: 98
Original Poster
Rep:
|
Thanks
Yes, oops would be quite appropriate here.
Thank you.
This is what is did at the end:
Code:
find . ! -path './pathname' -maxdepth 1 -mmin -360 -exec mv {} ../newname/ \;
|
|
|
|
12-29-2010, 08:44 AM
|
#9
|
|
LQ Newbie
Registered: Dec 2010
Posts: 2
Rep:
|
Quote:
Originally Posted by hq4ever
Yes, oops would be quite appropriate here.
Thank you.
This is what is did at the end:
Code:
find . ! -path './pathname' -maxdepth 1 -mmin -360 -exec mv {} ../newname/ \;
|
I have found this topic on Google when searching for "bash move folder contents only" and I think I have a better solution, which saves CPU a lot, maybe Google will take someone here again in the future:
Code:
# not working version with too many files - this gives "/bin/mv: Argument list too long"
mv source/* target/
# too slow version with find and too many child processes
find source/ -exec mv {} target/ \;
# CPU nicer version - find your own limit instead of 1000
find source/ | xargs -L1000 mv -t target/
|
|
|
|
12-29-2010, 12:32 PM
|
#10
|
|
Member
Registered: May 2004
Location: Israel
Distribution: Debian
Posts: 98
Original Poster
Rep:
|
Quote:
Originally Posted by brablc
I have found this topic on Google when searching for "bash move folder contents only" and I think I have a better solution, which saves CPU a lot, maybe Google will take someone here again in the future:
Code:
# not working version with too many files - this gives "/bin/mv: Argument list too long"
mv source/* target/
# too slow version with find and too many child processes
find source/ -exec mv {} target/ \;
# CPU nicer version - find your own limit instead of 1000
find source/ | xargs -L1000 mv -t target/
|
Lot's of water have flowed in the river since this question was posted.
The optimal solution, based on your example would be
Code:
find source/ -exec mv '{}' target +
The plus sign causes find to use the maximum parameter limit allows on each mv invocation.
on a side note, I've learned it from a question / answer I've posted on SO, see http://serverfault.com/questions/688...ps/68898#68898
|
|
|
|
12-30-2010, 03:15 AM
|
#11
|
|
LQ Newbie
Registered: Dec 2010
Posts: 2
Rep:
|
Quote:
Originally Posted by hq4ever
Lot's of water have flowed in the river since this question was posted.
...
The plus sign causes find to use the maximum parameter limit allows on each mv invocation.
...
|
Thanks for sharing this tip. My CentOS supports it. This makes find much better tool.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:22 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
|
|