Remove the same files in two folders
有時在整理照片或文件時, 需要比對2個資料匣, 把重覆的檔案拿掉. Dwonload Source Here function usage(){ echo "Find the same file in two folders and remove it." echo "usage : ./comp-rm.sh target-dir source-dir" echo "remove the same files in target-dir." } if [ $# -ne 2 ]; then usage exit 1 fi target_dir=$1 source_dir=$2 f_list1=$(find "$target_dir" -type f) f_list2=$(find "$source_dir" -type f) for i in $f_list1; do echo $f_list2 | grep $(basename $i) >/dev/null && hit_str+=$i";" done if [ -z $hit_str ]; then echo "list is empty....