Results 1 to 8 of 8

Thread: command that does the opposite of diff

  1. #1
    Join Date
    Dec 2007
    Beans
    217

    command that does the opposite of diff (solved)

    I have 2 folders with certain files. These files take up space, and there are a large amount of them in both folders. Going through them manually would take forever, so is there a command or flag for diff that i don't understand that can output any folders or files that are in both folders? I don't need recursive check, just in the top level of the 2 folders. I tried man diff, but couldn't come up with anything.
    Last edited by shortridge11; June 20th, 2009 at 07:03 PM. Reason: solved

  2. #2
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: command that does the opposite of diff

    How about this?
    Code:
    LANG=C diff -qs dir1/ dir2/
    LANG=C diff -qs dir1/ dir2/ | grep identical$

  3. #3
    Join Date
    Dec 2007
    Beans
    217

    Re: command that does the opposite of diff

    that didn't work. i put 2 folders with the same name in for testing purposes, and nothing was outputed

  4. #4
    Join Date
    Sep 2007
    Location
    over there
    Beans
    2,521
    Distro
    Ubuntu

    Re: command that does the opposite of diff

    There is a program called uniq that can report or omit repeated lines in a file. Check out its man page, maybe you can make it report repeated filenames in a directory.
    "All people are scum. No matter what they look like." ~ Spider Jerusalem, Transmetropolitan #4



  5. #5
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: command that does the opposite of diff

    Ah, well diff only compares the content of files. To find files and folders with the same name, you could try find like this:
    Code:
    cd dir1
    find . -exec test -e /path/to/dir2/{} \; -print

  6. #6
    Join Date
    Dec 2007
    Beans
    217

    Re: command that does the opposite of diff

    Quote Originally Posted by geirha View Post
    Ah, well diff only compares the content of files. To find files and folders with the same name, you could try find like this:
    Code:
    cd dir1
    find . -exec test -e /path/to/dir2/{} \; -print
    that worked and it also did the sub directories. is there a way to not do the sub directories?

  7. #7
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: command that does the opposite of diff

    Quote Originally Posted by shortridge11 View Post
    that worked and it also did the sub directories. is there a way to not do the sub directories?
    Yes, with find's -maxdepth option
    Code:
    cd dir1; find . -maxdepth 1 -exec test -e /path/to/dir2/{} \; -print

  8. #8
    Join Date
    Dec 2007
    Beans
    217

    Re: command that does the opposite of diff

    that is awesome, that worked amazingly, thanks a lot! =D

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
  •