変更のキャプチャの実装

変更のキャプチャの実装

「前」と「後」という2つのディレクトリがあり、各ディレクトリにはサブディレクトリとファイルがあります。深さ1レベルでは、これら2つのフォルダ間のすべての増分変更を表示したいと思います。

What is I mean is to compare the outputs of the following  
commands and display the differences.

1. find before/ -mindepth 1
2. find after/ -mindepth 1

After cimparison I want to display the following:
a."A" before files/folders present ONLY in the after/ 
     hierarchy(these will be deemed as newly added 
      components)
b. "D" before files/folders present ONLY in the before/ 
     hierarchy(these will be deemed as deleted
      components)
c. "M" before files/folders present in BOTH before/  and 
     after/  hierarchies(these will be deemed as modified
      components)

ベストアンサー1

おそらくdiff-ingよりも良い出力は次のようになります。

#!/bin/sh -eux

find before -mindepth 1 -printf "%p D\n" | cut -d/ -f2- | sort > files-before
find after -mindepth 1 -printf "%p A\n" | cut -d/ -f2- | sort > files-after
join -a2 -a1 files-before files-after | sed 's/D A$/M'

どこ:

  • 私たちはすべてのbeforeファイルを検索しますafter
  • 省略beforeしてafterディレクトリ自体(-mindepth 1)、
  • D下のファイルbeforeA下のファイルに追加しますafter
  • 見つかったすべてのファイルからパス(cut)の最初のコンポーネントを削除します。
  • 結果は2つの別々のファイルにソートされて保存されます。

最後のコマンド:

  • 同じファイルについて説明する行をペアで連結し(参照man join)、各ファイル(検索ディレクトリを削除したため検索ディレクトリに相対的)が、そのファイルが存在する場合、またはその両方Dbefore存在するA場合は一度だけ表示されます。afterD A
  • -a1 -a2入力ファイル()の1つにのみ表示されるファイル名が含まれています。
  • 最後に、ファイルDAフラグの両方がある場合は、必要に応じて変更しますM

おすすめ記事