directories comparision - Unix

This is a discussion on directories comparision - Unix ; is possible with a command or only with external tool?...

+ Reply to Thread
Results 1 to 4 of 4

Thread: directories comparision

  1. directories comparision

    is possible with a command or only with external tool?

  2. Re: directories comparision

    In nawfer writes:

    > is possible with a command or only with external tool?


    That depends on what you mean by "compare directories". Are you
    comparing only filenames? Dates and sizes? Subdirectories?

    If you're just comparing filenames, then you could do a simple ls on
    each directory, save those results to a file, and run "diff" on the two
    files.

    --
    John Gordon A is for Amy, who fell down the stairs
    gordon@panix.com B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"


  3. Re: directories comparision

    On Thu, 26 Apr 2007 18:55:43 +0000, John Gordon wrote:

    > In nawfer
    > writes:
    >
    >> is possible with a command or only with external tool?

    >
    > That depends on what you mean by "compare directories". Are you
    > comparing only filenames? Dates and sizes? Subdirectories?
    >
    > If you're just comparing filenames, then you could do a simple ls on
    > each directory, save those results to a file, and run "diff" on the two
    > files.


    You don't even need to save the results. This works in bash:

    diff <(ls foodirectory) <(ls bardirectory)

    It's called process substitution. See the Advanced Bash-Scripting guide,
    Chap. 22, at http://tldp.org/LDP/abs/html/process-sub.html

  4. Re: directories comparision

    2007-05-18, 11:08(+01), Barney:
    > On Thu, 26 Apr 2007 18:55:43 +0000, John Gordon wrote:
    >
    >> In nawfer
    >> writes:
    >>
    >>> is possible with a command or only with external tool?

    >>
    >> That depends on what you mean by "compare directories". Are you
    >> comparing only filenames? Dates and sizes? Subdirectories?
    >>
    >> If you're just comparing filenames, then you could do a simple ls on
    >> each directory, save those results to a file, and run "diff" on the two
    >> files.

    >
    > You don't even need to save the results. This works in bash:
    >
    > diff <(ls foodirectory) <(ls bardirectory)


    Only on systems that support /dev/fd/ or named pipes.

    Note that that (non-standard) feature comes from ksh and can be
    found in bash and zsh (though not all ksh
    versions/implementations support and ksh won't use named pipes
    for that).

    On systems that have /dev/fd/, you can do write it in
    standard sh as:

    ls foo | { ls bar | diff /dev/fd/3 -; } 3<&0

    --
    Stéphane

+ Reply to Thread