Results 1 to 6 of 6

Thread: arrgg!  I need to copy files from....

  1. #1

    arrgg!  I need to copy files from....

    Hi All,
    This sounds like it would great for ruby, (I know you will read this GnuVince) but I don't have ruby installed, this is running under cygwin, i have perl and bash shell scripts at my disposal. I am sure C could also do it pretty easily, but I know damn little about C system calls, we just can't use 'em in an embedded environment.

    The problem:
    I have a directory will 1500+ files in it, they get updated frequently. I have sorted out many of these files in seperate directories to make it a bit more managable in about 15 directories. when the updates come in i need to find each file and put it in the correct directroy. I did a ls > fileslist thinking my awk skills were 1/10 what they used to be, unfortunaltey what I tried failed miserably.

    the question:
    How do I have the files listed in the list get copied to a another directory without doing each one by hand? I tried an awk thing but failed, a couple of redirection commands, a pipe....

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re: arrgg!  I need to copy files from....

    How about some shell scripting ?

    If you wan't to keep the files that has been changed, but also like the new ones to be attended, and you want to look the whole drictory tree through..

    Code:
    #!/bin/bash
    
    # first make sure no files that were touched on last run will be moved.
    cp -f new_file_list old_file_list
    
    # find the new files there
    ls -l > new_file_list
    
    # sort out, which are the new ones 
    # or have been changed since last and do what ever
    for i in `ls -l | grep -v --file=old_file_list | awk '{print $NF}' \
             | grep -v old_file_list | grep -v new_file_list`; do
      # what ever command you want done to $i
    done
    I know theres a better way to do the final `grep -v` thingys.. But I can't remember the correct syntax.

    [edit]
    I forgot, this will also catch the directories, if you want to omit them, then use `ls -lF | grep -v / ` instead of the `ls -l`

  3. #3

    Re: arrgg! *I need to copy files from....

    Thanks redhead!!!

  4. #4

    Re: arrgg!  I need to copy files from....

    I'm not 100% if this is what you wanted to do...

    1. You have a dir with subdirs containing files to be updated
    2. You have a bunch of new versions of these files in ./
    3. You want to find where the old version is and copy a new version over it
    4. ./filelist contains the list of new files

    This will do the job I've described (hopefully what you wanted ? ).

    $ cat filelist | ./myscript

    Code:
    #!/bin/bash
    while read in_arg 
       do {
       find /path/to/oldfiles -name $in_arg -exec cp $in_arg '{}' \;
       }
    done
    First real bash shell script in my life

  5. #5

    Re: arrgg! *I need to copy files from....


    the question: *
    How do I have the files listed in the list get copied to a another directory without doing each one by hand? *I tried an awk thing but failed, *a couple of redirection commands, *a pipe....
    You must suffer. Just kidding. I'd use xargs for such a task.

    cat list | xargs -i{} cp {} /new/dir

  6. #6
    Senior Member
    Join Date
    May 2001
    Posts
    472

    Re: arrgg! *I need to copy files from....

    If you are in win32, why bother with the cygwin and whatnot.. .just do it as a batch file (foo.bat)

    Code:
    Echo on
    
    REM * Create a list of files
    
    DIR \your\path\to\dir\*.* /B > files.txt
    
    REM * Create a file to hold the results of each process 
    Echo > log.txt
    
    FOR /F %%A IN (files.txt) DO CALL copy %%A \apth\to\new\place >> backup_log.txt
    
    DEL files.txt

Similar Threads

  1. Copy Cds
    By mugs in forum Linux - Hardware, Networking & Security
    Replies: 0
    Last Post: 06-16-2004, 11:33 AM
  2. vi : copy and pasting
    By Blaqb0x in forum Linux - Software, Applications & Programming
    Replies: 6
    Last Post: 09-03-2002, 11:54 AM
  3. arrgg!! mp3 to ogg script is not going well...
    By pbharris in forum Programming
    Replies: 19
    Last Post: 08-03-2002, 03:27 PM
  4. FTP into home dir.  hidden files visible/editable
    By Blaqb0x in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 05-19-2002, 05:16 AM
  5. mandrake 8.0  missing files
    By danvitt in forum Mandriva
    Replies: 5
    Last Post: 09-30-2001, 01:01 AM

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
  •