
"이전"과 "이후"라는 두 개의 디렉토리가 있으며 각 디렉토리에는 하위 디렉토리와 파일이 있습니다. 깊이 1 수준에서 이 두 폴더 사이의 모든 증분 변경 사항을 표시하고 싶습니다.
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
아래에 있는 파일before
과A
아래에 있는 파일 에 추가합니다after
.- 발견된 모든 파일에서 경로(
cut
) 의 첫 번째 구성 요소를 제거합니다. - 결과는 두 개의 별도 파일로 정렬되어 저장됩니다.
마지막 명령:
- 동일한 파일에 대해 설명하는 행을 쌍으로 연결하여( 참조
man join
) 각 파일(검색 디렉토리를 제거했기 때문에 검색 디렉토리에 상대적)이 해당 파일이 또는D
둘before
다 에 있는A
경우 한 번만 나타나도록 합니다.after
D A
-a1 -a2
입력 파일( ) 중 하나에만 나타나는 파일 이름을 포함합니다 .- 마지막으로 파일에
D
및A
플래그가 모두 있으면 필요에 따라 이를 변경합니다M
.