파일 리스트(txt)에 있는 파일을 제외하고 제거하기

익명 사용자의 이미지

받갑습니다. 리눅스 공부중인 취준생입니다.

텍스트 파일안에 수만개의 파일이 한 줄 씩 나열되어 있고, 그 파일들을 제외시키고 나머지 것들을 삭제하고 싶습니다.

find 명령어로 활용해서 특정 확장자나 이름을 지정하여 수행하기에는 너무 많다보니 골치입니다;;

스크립트를 이용해야 좋을까요?

ymir의 이미지

$ cat list.txt
rand_err.c
rand_win.c
rand_egd.c
rand_unix.c
rand_lib.c
randfile.c
md_rand.c
rand_vms.c
$ find crypto -type f -name \*.c | grep -f list.txt -
crypto/rand/rand_err.c
crypto/rand/rand_win.c
crypto/rand/rand_egd.c
crypto/rand/rand_unix.c
crypto/rand/rand_lib.c
crypto/rand/randfile.c
crypto/rand/md_rand.c
crypto/rand/rand_vms.c
$ find crypto -type f -name \*.c | grep -f list.txt - | tar cvf list.tar -T -
crypto/rand/rand_err.c
crypto/rand/rand_win.c
crypto/rand/rand_egd.c
crypto/rand/rand_unix.c
crypto/rand/rand_lib.c
crypto/rand/randfile.c
crypto/rand/md_rand.c
crypto/rand/rand_vms.c
$ tar tvf list.tar
-rw-r--r-- ymir/ymir      1102 2018-11-20 22:41 crypto/rand/rand_err.c
-rw-r--r-- ymir/ymir      3488 2018-11-20 22:41 crypto/rand/rand_win.c
-rw-r--r-- ymir/ymir      7123 2018-11-20 22:41 crypto/rand/rand_egd.c
-rw-r--r-- ymir/ymir      9659 2018-11-20 22:41 crypto/rand/rand_unix.c
-rw-r--r-- ymir/ymir      4168 2018-11-20 22:41 crypto/rand/rand_lib.c
-rw-r--r-- ymir/ymir     10476 2018-11-20 22:41 crypto/rand/randfile.c
-rw-r--r-- ymir/ymir     18977 2018-11-20 22:41 crypto/rand/md_rand.c
-rw-r--r-- ymir/ymir      3865 2018-11-20 22:41 crypto/rand/rand_vms.c
$ \rm -rf crypto
$ tar xvf list.tar
...

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

황병희의 이미지

백업을 해두고 테스트 부탁드려요 실제로 지워집니다...;;;
견본을 제시해주신 ymir님께 감사드립니다^^^

소스코드(파이썬3.7): https://gitlab.com/soyeomul/test/blob/master/161857.py

[ibus-hangul(서라운딩 패치판)에서 작성했씁니다]

--
^고맙습니다 감사합니다_^))//

익명 사용자의 이미지

ymir님 과 황병희씨 덕분에 큰 도움이 되고있습니다.

--
ㄱㅅㅎㄴㄷ!