Find the answer to your Linux question:
Results 1 to 7 of 7
I have files in /src/ that I copied to /dst/ I encountered some I/O errors. All of the files from /src/ exist in /dst/, but they are not 100% exact ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    3

    copy file if file size differs


    I have files in /src/ that I copied to /dst/
    I encountered some I/O errors. All of the files from /src/ exist in /dst/, but they are not 100% exact copies. (some data is missing in the files in /dst/)

    cp -u /src/ /dst/ only moves files from /src/ to /dst/ if A. the files does not exist in /dst/ or B. the file in /src/ is "newer" (involving time stamp) than the existing file in /dst/

    How can I move all of the files (and directories containing files) from /src/ (recursively) to /dst/ if the file size of the file in /dst/ differs from the file in /src/?

  2. #2
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    119
    Why not just recopy them regardless?

    Other than that, I think you would need to make a script to compare sizes and then cp based on that. IIRC, there isn't a way to check size using "cp"

  3. #3
    Just Joined!
    Join Date
    Jul 2010
    Posts
    3
    Quote Originally Posted by markcole View Post
    Why not just recopy them regardless?

    Other than that, I think you would need to make a script to compare sizes and then cp based on that. IIRC, there isn't a way to check size using "cp"
    Because it took me about 4 hours to copy all of the data. I copied the data from a FTP server wirelessly to a USB storage device and I only have USB 1.0 ports.

    How can I compare file sizes? du?

  4. #4
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    You probably could use rsync.

  5. #5
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    119
    Quote Originally Posted by MuffinFlavored View Post
    Because it took me about 4 hours to copy all of the data. I copied the data from a FTP server wirelessly to a USB storage device and I only have USB 1.0 ports.

    How can I compare file sizes? du?
    ls -l filename | awk '{print $5}'

  6. #6
    Just Joined!
    Join Date
    Jul 2010
    Posts
    3
    Quote Originally Posted by markcole View Post
    ls -l filename | awk '{print $5}'
    I think I am looking at a complicated bash script here.

    I can't even explain it.

    Recursively list all files and their file sizes, compare to recursively listed files of another directory and their file sizes, if different, copy?

  7. #7
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    119
    Quote Originally Posted by lomcevak View Post
    You probably could use rsync.
    Quote Originally Posted by MuffinFlavored View Post
    I think I am looking at a complicated bash script here.

    I can't even explain it.

    Recursively list all files and their file sizes, compare to recursively listed files of another directory and their file sizes, if different, copy?
    You should actually follow lomcevak's advise and look at rsync. You can specify size only updates.

Posting Permissions

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