Results 1 to 4 of 4

Thread: BASH Script: Compare two directories, if they differ, run code

  1. #1
    Join Date
    Dec 2008
    Location
    127.0.0.1
    Beans
    187
    Distro
    Ubuntu Development Release

    BASH Script: Compare two directories, if they differ, run code

    Title pretty much explains it all, basically trying to figure out how to compare dir1 to dir2, if dir2 is different from dir1, copy missing files...that at all possible?

    Thanks in advance

  2. #2
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,263
    Distro
    Ubuntu

    Re: BASH Script: Compare two directories, if they differ, run code

    Why not just copy the missing files?
    Code:
    cp --no-clobber dir1 dir2
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  3. #3
    Join Date
    Dec 2008
    Location
    127.0.0.1
    Beans
    187
    Distro
    Ubuntu Development Release

    Re: BASH Script: Compare two directories, if they differ, run code

    I...did not know that command existed...thanks!

  4. #4
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,263
    Distro
    Ubuntu

    Re: BASH Script: Compare two directories, if they differ, run code

    Quote Originally Posted by dmillerw View Post
    I...did not know that command existed...thanks!
    The man command is your friend. I too did not know that the option existed until you asked the question.

    I thought, "I wonder whether you can copy without overwriting?" I went to the terminal and entered:
    Code:
    man cp
    Nice 'n' easy.
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

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
  •