Results 1 to 6 of 6

Thread: [SOLVED] using the shell for mass file manipulation

  1. #1
    Join Date
    Dec 2007
    Location
    Atlanta
    Beans
    28
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Lightbulb [SOLVED] using the shell for mass file manipulation

    I'm trying to move a large set of files in a large directory which meet certain criteria to a different directory. I think that the easiest way to do this is with 'nested' functions on the command line. Following some online tutorials and howtos, this is what I have have tried so far:

    Code:
    mv $(find . -name '*.m4p') /home/user/shared/DRMed/
    but that returns this output:

    Code:
    mv: cannot stat /example.m4p no such file or directory
    mv: cannot stat exmample/otherexample no such file or directory
    I know that the 'find' portion of this works fine, it locates all of the correct files and lists them in 1 per line format. The problem (I think) is in how mv parses the output from the find command. Perhaps there is a simple option for find that will allow mv to properly interpret the results? (-print0 does not work). Am I missing something obvious? Tried the man pages, but couldn't find anything about linking mv and find there...please help!

  2. #2
    Join Date
    Nov 2006
    Location
    OE
    Beans
    2,774
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: using the shell for mass file manipulation

    Maybe you want to sort through/have CLI select the files you want to move before you invoke the mv command? Take a look at man grep and man cat too.
    Alternate (psychocats.net) Ubuntu info resource

    Helping isn't what the logical mind thinks it is because when you help others you're really helping yourself.

  3. #3
    Join Date
    Dec 2007
    Location
    Atlanta
    Beans
    28
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: using the shell for mass file manipulation

    Quote Originally Posted by phidia View Post
    Maybe you want to sort through/have CLI select the files you want to move before you invoke the mv command? Take a look at man grep and man cat too.
    I thought that's what the
    Code:
    $(find ...)
    portion did. It is my understanding that commands inside the $( ) are run in a subshell as part of a while-do sort of loop.

  4. #4
    Join Date
    Dec 2007
    Location
    Atlanta
    Beans
    28
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: using the shell for mass file manipulation

    Well it took me all day, but I finally figured it out. In case anyone else has this problem, here is the code that worked for me:
    Code:
    /shared/music$ find . -name '*.m4p' -print0 | xargs -0 /bin/mv -t /home/user/shared/DRMed/
    Just to describe what happens....
    1. Find all files in the current directory with the .m4p extension
    2. Print a list of the output adding a /null character to the end of the line instead of a carriage return
    3. Pipe the results into xargs with /null appended again
    4. move all of the files in the list to the directory specified


    Hope it helps someone.

  5. #5
    Join Date
    Apr 2006
    Beans
    313

    Re: [SOLVED] using the shell for mass file manipulation

    EDIT: Never mind, I see what I missed. DUH.
    Last edited by munkyeetr; August 27th, 2008 at 07:03 AM.
    If the advice you're given in this forum solves your issue, please mark the post as [SOLVED] in consideration to others.
    Registered Linux User: 448689 | How To: Secure the GRUB Boot Loader
    [ Acer Aspire 5535 | Arch Linux x86_64 | Compiz WM ]

  6. #6
    Join Date
    Dec 2007
    Location
    Atlanta
    Beans
    28
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [SOLVED] using the shell for mass file manipulation

    Yeah, I saw your original message in my email. No worries. My heart sunk when I thought it could have been done so much easier! But I'm glad to know that all of my work wasn't in vain.

    Just in case anyone else has the same thought, the problem with munkyeetr's original suggestion was that the *.m4p files were spread out in different directories and subdirectories under music/. The command
    Code:
    mv *.mp4 /home/user/shared/DRMed/
    would have only moved the *m4p files in the current directory. So my only options were to use that command and repeat it as many times as the number of directories which contained any .m4p files (which wasn't really feasible given that there were over 200 individual .m4p files spread out in different subdirectories under the 40GB music/ directory) or to use some sort of combination of pipes (| for the newbies), nested functions (see my first post here), and redirects (>) to find all of the .m4p files by searching music/ recursively and moving them in a single command line entry. I'm quite pleased with the results. Perhaps I'll do a quick howto...

    For more information on the commands I used, please read the man pages for find & xargs.

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
  •