19

SVNの使用に移る前は、/develop/ディレクトリを保持し、そこでファイルを編集およびテストしてから、それらを/main/ディレクトリに移動するだけでプロジェクトを管理していました。SVNに移行することを決めたとき、ディレクトリが実際に同期していることを確認する必要がありました。

では、2つの異なるディレクトリにある同じ名前のファイルを再帰的に比較するシェルスクリプト[bash]を作成する良い方法は何でしょうか。

注:上記で使用されているディレクトリー名は、サンプルのみです。コードをトップレベルに保存することはお勧めしません:)。

4

6 に答える 6

33

diffコマンドには、ディレクトリを再帰的に比較するための-rオプションがあります。

diff -r /develop /main
于 2008-09-23T08:21:57.610 に答える
8
diff -rqu /develop /main

そのように変更の概要のみを提供します:)

新しい/不足しているファイルのみを表示したい場合

diff -rqu /develop /main | grep "^Only

それらをむき出しにしたい場合:

diff -rqu /develop /main | sed -rn "/^Only/s/^Only in (.+?): /\1/p"
于 2008-09-23T08:46:22.700 に答える
5

私が利用できるdiffは、再帰的な違いを可能にします。

diff -r main develop

しかし、シェルスクリプトを使用すると:

( cd main ; find . -type f -exec diff {} ../develop/{} ';' )
于 2008-09-23T08:26:17.490 に答える
1

[私はどこかであなた自身の質問に答えることは大丈夫だと読んだので、ここに行きます:)]

私はこれを試しました、そしてそれはかなりうまくいきました

[/]$ cd /develop/
[/develop/]$ find | while read line; do diff -ruN "/main/$line" $line; done |less

上記の行を次のように編集することで、特定のファイルのみ(たとえば、.phpファイルのみ)を比較することを選択できます。

[/]$ cd /develop/
[/develop/]$ find -name "*.php" | while read line; do diff -ruN "/main/$line" $line; done |less

他のアイデアはありますか?

于 2008-09-23T08:22:06.673 に答える
1

これは、私の(やや面倒な)スクリプトdircompare.shの例です。

  • 2 つの再帰パスで、ファイルとディレクトリが発生するディレクトリ (または両方) に応じて、配列内のファイルとディレクトリを並べ替えます。
  • diff -q両方のディレクトリにあるファイルは、異なるかどうかによって、2 つの配列に再度並べ替えられます。
  • 等しいと主張するファイルについてdiffは、タイムスタンプを表示して比較します

役に立つことを願っています - 乾杯!

EDIT2:(実際には、リモートファイルで正常に動作します-問題は、ローカルファイルとリモートファイル間の差分操作中にCtrl-C信号が処理されなかったため、時間がかかる場合があります;スクリプトはそれを処理するトラップで更新されました-ただし、参照用に以下の以前の編集):

編集:...リモート ssh ディレクトリのサーバーがクラッシュするように見えることを除いて(これを使用してみました~/.gvfs)...これはもうありませbashんが、代わりに を使用することをrsyncお勧めします。例を次に示します。

$ # get example revision 4527 as testdir1
$ svn co https://openbabel.svn.sf.net/svnroot/openbabel/openbabel/trunk/data@4527 testdir1

$ # get earlier example revision 2729 as testdir2
$ svn co https://openbabel.svn.sf.net/svnroot/openbabel/openbabel/trunk/data@2729 testdir2

$ # use rsync to generate a list 
$ rsync -ivr --times --cvs-exclude --dry-run testdir1/ testdir2/
sending incremental file list
.d..t...... ./
>f.st...... CMakeLists.txt
>f.st...... MACCS.txt
>f..t...... SMARTS_InteLigand.txt
...
>f.st...... atomtyp.txt
>f+++++++++ babel_povray3.inc
>f.st...... bin2hex.pl
>f.st...... bondtyp.h
>f..t...... bondtyp.txt
...

ご了承ください:

  • /上記を取得するには、ディレクトリ名の末尾にある末尾のスラッシュを忘れてはなりませんrsync
  • --dry-run- シミュレーションのみ、ファイルを更新/転送しない
  • -r- ディレクトリに再帰する
  • -v- 詳細 (ただし、ファイル変更情報とは関係ありません)
  • --cvs-exclude.svn-ファイルを無視
  • -i- "--itemize-changes: すべての更新の変更概要を出力"

によって表示される情報(たとえば、上記の文字列) man rsyncを説明する短い抜粋を次に示します。-i>f.st......

The  "%i"  escape  has a cryptic output that is 11 letters long.
The general format is like the string YXcstpoguax,  where  Y  is
replaced  by the type of update being done, X is replaced by the
file-type, and the other letters represent attributes  that  may
be output if they are being modified.

The update types that replace the Y are as follows:

o      A  < means that a file is being transferred to the remote
       host (sent).

o      A > means that a file is being transferred to  the  local
       host (received).

o      A  c  means that a local change/creation is occurring for
       the item (such as the creation  of  a  directory  or  the
       changing of a symlink, etc.).

...
The file-types that replace the X are: f for a file, a d  for  a
directory,  an  L for a symlink, a D for a device, and a S for a
special file (e.g. named sockets and fifos).

The other letters in the string above  are  the  actual  letters
that  will be output if the associated attribute for the item is
being updated or a "." for no change.  Three exceptions to  this
are:  (1)  a newly created item replaces each letter with a "+",
(2) an identical item replaces the dots with spaces, and (3)  an
....

確かに少し不可解ですが、少なくとも基本的なディレクトリ比較を示していsshます。乾杯!

于 2011-07-18T23:55:50.940 に答える
0

古典的な (System V Unix) の答えは ですdircmp dir1 dir2。これは、開始時に dir1 にあるが dir2 にはない、または dir2 にあるが dir1 にはないファイルを一覧表示するシェル スクリプトです (prコマンドからの出力の最初のページなので、見出しで改ページされます)。 )、続いて各共通ファイルと分析の比較 (同じ、異なる、ディレクトリが最も一般的な結果でした)。

これは消滅の過程にあるようです - 必要に応じて、独立した再実装を利用できます。それはロケット科学ではありません (cmpはあなたの友達です )。

于 2008-10-18T18:45:54.133 に答える