Results 1 to 5 of 5

Thread: Moving files listed in text file?

  1. #1
    Join Date
    Jun 2010
    Beans
    7

    Moving files listed in text file?

    I've got a text file listing 1823 files that need to be copied from their current locations, i.e.

    /media/blackhole/Audio/Music/whatever.mp3
    /media/blackhole/Audio/Music/sowhat.mp3
    To another folder, any idea how I should do this?

    Thanks.

  2. #2
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Moving files listed in text file?

    Code:
    while read file; do
      cp -vb "$file" /path/to/dir
    done < /path/to/file
    Last edited by sisco311; June 14th, 2010 at 09:11 PM.

  3. #3
    Join Date
    Jun 2010
    Beans
    7

    Re: Moving files listed in text file?

    Quote Originally Posted by sisco311 View Post
    Code:
    while read file; do
      cp -vb "$file" /path/to/dir
    done < /path/to/file
    I've got an idea how you mean for this to be used, but I'm kind of confused.

    I'm thinking drop that code in a text file as move.sh, change /path/to/dir to the intended destination for all those files, and /path/to/file to the path to the text file full of files? i.e. foobar.txt?

    so it'd look like

    Code:
    #hope I got this right
    while read file; do
      cp -vb "$file" /home/jay/test
    done < /home/jay/foobar.txt
    and then run it from the terminal, how far off base am I?

    Thanks for the help!

  4. #4
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Moving files listed in text file?

    Quote Originally Posted by Jay Colfer View Post
    I've got an idea how you mean for this to be used, but I'm kind of confused.

    I'm thinking drop that code in a text file as move.sh, change /path/to/dir to the intended destination for all those files, and /path/to/file to the path to the text file full of files? i.e. foobar.txt?
    Yep, you can create a scrip (move.sh) if you wish, but the code is very trivial an short you can type (copy/paste) it directly in the terminal. You can even write it in one line:
    Code:
    while read file; do cp -vb "$file" /home/jay/test; done < /home/jay/foobar.txt
    Of course, if you plan to run it multiple times, then create a script:
    Code:
    #!/bin/bash
    while read file; do
      cp -vb "$file" /home/jay/test
    done < /home/jay/foobar.txt
    Don't forget to make it executable:
    Code:
    chmod +x ./move.sh

  5. #5
    Join Date
    Jun 2010
    Beans
    7

    Re: Moving files listed in text file?

    Thanks, you're a life saver! I just moved all but a few of the files that had weird filenames that cp choked on, but that's easy enough to fix.

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
  •