파일 리스트(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님 과 황병희씨 덕분에 큰 도움이 되고있습니다.

--
ㄱㅅㅎㄴㄷ!

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.