Computing.Net > Forums > Linux > find exec mv

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

find exec mv

Reply to Message Icon

Name: buddhikah
Date: March 16, 2009 at 02:30:33 Pacific
OS: Windows XP
Subcategory: Configurations
Comment:

Hi

Im trying to find a directory as

find / -type d -name "Maildir"

and move the find results as per the

mv -f {}/../../ `pwd` \;

Please note that this command returns an error as “Device or resource busy”.

Please advice how can I accomplish this as complete;

find / -type d -name "Maildir" -exec mv -f {}/../../ `pwd` \;




Sponsored Link
Ads by Google

Response Number 1
Name: jefro
Date: March 16, 2009 at 14:02:08 Pacific
Reply:

My guess may be wrong.

Seems like you would pipe output from find to another command.

"Best Practices", Event viewer, host file, perfmon, antivirus, anti-spyware, Live CD's, backups, are in my top 10


0

Response Number 2
Name: nails
Date: March 16, 2009 at 21:26:18 Pacific
Reply:

I've only seen this error "Device or resource busy" when trying to move directories across file systems. It can mean you are trying to move a directory that is being used by another user or process. It can also mean that the version of Linux or Unix won't allow moving directories across file systems.

In my experience, it's best to copy a source directory structure from one location to another destination. Then, you can remove the source directory if you wish.

The tape archive command, tar, can be used to copy all files and directories from one location to another. To copy all files and directories from under /usr/nails to /usr/fred, type:

cd /usr/nails; tar cf - .|(cd /usr/fred; tar xf - )

This command changes to the source directory and creates a tar archive. The "f" option with a dash means use standard output and the period includes the current directory in the archive. Since this command is piped, the standard output of the archive becomes the standard input of the tar extraction creating the required copy. The parenthesis groups commands before the tar extraction takes place.

Instead of tar, the copy input-output command, cpio, can also be used to copy directories:

cd /usr/nails; find . -depth -print|cpio -pd /usr/fred

The pass mode, "-p," of cpio allows a list of files piped from the standard input to be copied to the target directory, /usr/fred. Be sure to change to the source directory and then do a find.

In your case, you might consider doing something like this:

# untested script
find . -type d -name "Maildir" -print|while read mydir
do
    cd "$mydir"; tar cf - .|(cd <your destination>; tar xf - )
done

Let me know if you have any questions.



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: find exec mv

DHCP AND specity gateway www.computing.net/answers/linux/dhcp-and-specity-gateway/13239.html

find string and copy file script www.computing.net/answers/linux/find-string-and-copy-file-script/29609.html

prepend text to all files in dir www.computing.net/answers/linux/prepend-text-to-all-files-in-dir/28993.html