I have two directory, Faces
and Faces_v2
, I want to delete every file in Faces
directory that does exist in Faces_v2
directory. This is a output from fdupes
.
383051 bytes each:
livecpk/Faces_v2/Asset/model/character/face/real/153809/sourceimages/#windx11/face_srm.ftex
livecpk/Faces/Asset/model/character/face/real/153809/sourceimages/#windx11/face_srm.ftex
6410 bytes each:
livecpk/Faces_v2/Asset/model/character/face/real/153809/sourceimages/#windx11/eye_occlusion_alp.ftex
livecpk/Faces/Asset/model/character/face/real/153809/sourceimages/#windx11/eye_occlusion_alp.ftex
327654 bytes each:
livecpk/Faces_v2/Asset/model/character/face/real/153809/sourceimages/#windx11/face_bsm_alp.ftex
livecpk/Faces/Asset/model/character/face/real/153809/sourceimages/#windx11/face_bsm_alp.ftex
452968 bytes each:
livecpk/Faces_v2/Asset/model/character/face/real/110651/sourceimages/#windx11/face_trm.ftex
livecpk/Faces/Asset/model/character/face/real/110651/sourceimages/#windx11/face_trm.ftex
640680 bytes each:
livecpk/Faces_v2/Asset/model/character/face/real/110651/sourceimages/#windx11/face_srm.ftex
livecpk/Faces/Asset/model/character/face/real/110651/sourceimages/#windx11/face_srm.ftex
849208 bytes each:
livecpk/Faces_v2/Asset/model/character/face/real/110651/sourceimages/#windx11/face_bsm_alp.ftex
livecpk/Faces/Asset/model/character/face/real/110651/sourceimages/#windx11/face_bsm_alp.ftex
Take above as an example, I want to delete.
livecpk/Faces/Asset/model/character/face/real/153809
livecpk/Faces/Asset/model/character/face/real/110651
Because the directory already exist in livecpk/Faces_v2
.
So basically I accidentally paste some file that was meant for Faces_v2
directory into Faces
, now I want to clear those duplicate data without bothering other non-duplicate files. How would I do that ?
The fdupes output can probably be manipulated fairly easily to extract just the files to be deleted. Some extra information is needed to do this safely.
Complications to writing the code include:
livecpk/Faces_v2
but not livecpck/Faces
(or vice versa) ? (ie. groups that should be ignored)livecpk/Faces
be handled if it contains files that are in livecpk/Faces_v2
but also others that are not?With fdupes.out
of form exactly as shown, files could be deleted by just using grep
to extract the relevant lines and piping to xargs rm
.
You could also start from scratch. One idea:
top=$(pwd -P)
dir2="$top/livecpk/Faces"
dir2="$top/livecpk/Faces_v2"
(
if cd "$dir1"; then
find . -type f \
-exec test -f "$dir2"/{} \; \
-exec cmp -s "$dir2"/{} {} \; \
-exec echo rm {} \;
find . -depth -type d \
-exec test -d "$dir2"/{} \; \
-exec echo rmdir {} \;
fi
)
dir1
:
dir2
; thendir1
(processed depth-first):
dir2
; thenThis spawns a lot of test
processes but that is probably not important since the bit-comparisons are much more expensive.