Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 48

Thread: Find files from text file and move them to folder

  1. #11
    Join Date
    Jun 2009
    Beans
    192

    Re: Find files from text file and move them to folder

    OK made a copy.txt script in it I have

    Code:
    while read file
    do 
    echo "$file"
    find /home/**/recordings -name "*$file" -exec cp "{}" /home/temp 
    done < /home/**/recordings/missing_files.txt
    and it reads the file and for each file name it gives an error and nothing is copied, even the files that I know are there.
    Code:
    find: missing argument to '-exec'

  2. #12
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Find files from text file and move them to folder

    while multiline script removes the need to separate the commands with ;, you still need that \; for exec - it tells find where exec part ends

  3. #13
    Join Date
    Jun 2009
    Beans
    192

    Re: Find files from text file and move them to folder

    Ok added the \; back in and it prints all the file names on the screen but nothing is copied over to temp

    Code:
    while read file
    do 
    echo "$file"
    find /home/**/recordings -name "*$file" -exec cp "{}" /home/temp \;
    done < /home/**/recordings/missing_files.txt
    I changed the echo "$file" line to echo "$file" > /home/temp/echo.txt as it was scrolling off the screen to fast to read what it was saying. When I check the file all it has in it is the name of the last file in the missing_files.txt file.


    EDIT: I may not have saved the script after commenting out the -exec part because now it doesn't print anything to the screen, it creates the echo.txt file but still nothing is copied over.

    EDIT2: It stopped printing to the screen because I changed the echo line to output to a file, still doesn't copy any files over
    Last edited by KLStringer; November 2nd, 2011 at 05:43 PM.

  4. #14
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Find files from text file and move them to folder

    when you redirect output to file you can either overwrite it with > or append to it with >>
    you used > so each loop iteration overwrote your test output file.

    add -v parameter (verbose) to cp command so you get a visual clue in case something is being copied (cp -v "{}" /home/temp)

  5. #15
    Join Date
    Jun 2009
    Beans
    192

    Re: Find files from text file and move them to folder

    *Homer*
    D'OH!
    */Homer*

    I forgot that the /home/**/recordings "folder" is a link to a different location and I don't think find was following the link so I've changed the pathing and rerunning, fingers crossed that solved the problem.
    Last edited by KLStringer; November 2nd, 2011 at 05:55 PM.

  6. #16
    Join Date
    Jun 2009
    Beans
    192

    Re: Find files from text file and move them to folder

    I let it run over night and it only read 2 file names out of 4351 in the file, there is a lot of recordings to search through though (about 6.5TB) but can't imagine it would only make it through 2 in 24 hours.

    Code:
    while read file
     do
      echo "$file" >> /home/temp/echo.txt
             find /media/recordings -name "*$file" -exec cp -v "{}" /home/temp \;
      done < /media/recordings/HarpUMGMissing.txt

  7. #17
    Join Date
    Jun 2009
    Beans
    192

    Re: Find files from text file and move them to folder

    Is there anyway to speed up this process? It's been running or about a week now and has only made it through 365/4351 and I have another list of 475 recordings to find.


    EDIT: How does find treat * in a file name? Does it treat it as a wildcard or as a * character? I ask because I'm only given the part of the file name that's unique to the recordings I need.
    Last edited by KLStringer; November 11th, 2011 at 05:25 PM.

  8. #18
    Join Date
    Jun 2009
    Beans
    192

    Re: Find files from text file and move them to folder

    Somethings not working correctly it's moving files that are not in the file of recordings to copy.

    [code]
    while read file
    do
    echo "$file" >> /home/temp/echo.txt
    find /home/**/recordings -name "*$file" -exec cp "{}" /home/temp \;
    done < /media/recordings/Move.txt
    [code]

  9. #19
    Join Date
    May 2010
    Location
    uk
    Beans
    9,249
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Find files from text file and move them to folder

    Hi

    Somethings not working correctly it's moving files that are not in the file of recordings to copy.
    Code:
    while read file
     do
      echo "$file" >> /home/temp/echo.txt
             find /home/**/recordings -name "*$file" -exec cp "{}" /home/temp \;
      done < /media/recordings/Move.txt
    Remove the * before $FILE. That may be the cause of your problem.

    Code:
    while read file
     do
      echo "$file" >> /home/temp/echo.txt
             find /home/**/recordings -name "$file" -exec cp "{}" /home/temp \;
      done < /media/recordings/Move.txt
    /home/**/recordings/. This may also be a problem depending on your directory structure.

    Kind regards
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

    Thinking about becoming an Ubuntu Member?

  10. #20
    Join Date
    Jun 2009
    Beans
    192

    Re: Find files from text file and move them to folder

    Thanks for tip, I'll take the * out and re-run it, I censored the /home/**/recordings I have the full path in the script.

Page 2 of 5 FirstFirst 1234 ... LastLast

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
  •