Results 1 to 3 of 3

Thread: mv files and structure

  1. #1
    Join Date
    Feb 2010
    Location
    Cobourg
    Beans
    163

    mv files and structure

    I'm looking to be able to find a bunch of pdfs, move those pdfs to another directory, keep the directory structure, and remove the previous structures.
    So far I have been able to use the find command and copy the files while keeping the structure:

    find /home/john/books1/ -regex ".*\(pdf\|epub\|mobi\)$" -type f -exec cp '{}' /home/john/temp/ ';'

    but if I use mv I get all the files in one directory...

    find /home/john/books1/ -regex ".*\(pdf\|epub\|mobi\)$" -type f -exec mv -b '{}' /home/john/temp/ ';'


    Am I stuck using 'cp'? Which is fine, I just need to find a way to then delete them...

    find /home/john/books1/ -regex ".*\(pdf\|epub\|mobi\)$" -type f -exec rm '{}' /home/john/temp/ ';'

    I plan to also have this in a cron job but that shouldn't be a problem once I have figured out the script

    Thanks for any help


  2. #2
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: mv files and structure

    If you use rsync, it will preserve directory hierarchies.

    Another option is to use tar like this:

    Code:
    tar cpf - /path/to/some/location | (cd /path/to/new/location; tar xf -)
    That creates a "tarball" of the source location and "pipes" it to another instance of tar that unpacks the tarball in the new location. The tarball itself is not perserved.

    @RayanaSmith
    Rayana, if I had posted an "i don't know the answer to that question" response in every thread to which it applies, my post count would easily be pushing 100,000.
    Last edited by SeijiSensei; July 13th, 2013 at 03:26 PM.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  3. #3
    Join Date
    Feb 2010
    Location
    Cobourg
    Beans
    163

    Re: mv files and structure

    I couldn't seem to get tar to be used with find but I was able to get rsync to work. so I'm happy

    rsync -r -R --include='*/' --include='*.pdf' --include='*.epub' --include='*.mobi' --exclude='*' --remove-source-files /storage/unsorted/ /home/john/Books/


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •