LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 02-11-2005, 04:48 AM   #1
hq4ever
Member
 
Registered: May 2004
Location: Israel
Distribution: Debian
Posts: 98

Rep: Reputation: 15
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 ?
 
Old 02-11-2005, 05:10 AM   #2
sh4n
LQ Newbie
 
Registered: Feb 2005
Posts: 14

Rep: Reputation: 0
Does cp work?

cp /folder/fileorigin /folder/destination
 
Old 02-11-2005, 05:10 AM   #3
hamish
Member
 
Registered: Aug 2003
Location: Edinburgh
Distribution: Server: Gentoo2004; Desktop: Ubuntu
Posts: 720

Rep: Reputation: 30
try

$mv $(find . -mmin -120) /foo/bar

i'm not sure, I didn't try that.

hamish
 
Old 02-11-2005, 05:12 AM   #4
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
append

-exec mv {} target \;

to the command.
 
Old 02-11-2005, 05:24 AM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
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 05:42 AM.
 
Old 02-11-2005, 06:06 AM   #6
hq4ever
Member
 
Registered: May 2004
Location: Israel
Distribution: Debian
Posts: 98

Original Poster
Rep: Reputation: 15
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.
 
Old 02-11-2005, 06:09 AM   #7
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
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.
 
Old 02-11-2005, 06:29 AM   #8
hq4ever
Member
 
Registered: May 2004
Location: Israel
Distribution: Debian
Posts: 98

Original Poster
Rep: Reputation: 15
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/ \;
 
Old 12-29-2010, 09:44 AM   #9
brablc
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Rep: Reputation: 0
Quote:
Originally Posted by hq4ever View Post
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/
 
Old 12-29-2010, 01:32 PM   #10
hq4ever
Member
 
Registered: May 2004
Location: Israel
Distribution: Debian
Posts: 98

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by brablc View Post
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
 
Old 12-30-2010, 04:15 AM   #11
brablc
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Rep: Reputation: 0
Quote:
Originally Posted by hq4ever View Post
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.
 
  


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
cannot using FTP move command to move files adrianmak Linux - Networking 4 04-21-2009 01:01 PM
move folder to new partition blizunt7 Fedora 11 10-13-2005 08:16 AM
Move Choices-Folder from rox to different location Fonk Linux - Software 1 04-16-2005 09:50 PM
making a script that will move a file or files in a trash folder Paxmaster Programming 5 12-12-2004 07:00 PM
Cant move a folder to another path? dwarf007 Linux - Newbie 2 09-19-2004 03:28 AM


All times are GMT -5. The time now is 08:35 AM.

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