tar 를 사용해서 파일을 복사하려고 하는데 * 는 사용 못하나요?

hancar01의 이미지

tmp/backup/aaa/etc 에는 test.txt 라는 파일이 있습니다.
여러 파일을 선택적으로 옮겨야 하는 상황인데
모든 txt 파일을 옮기려고 아래의 명령어로 실행을 하였습니다.

[root@localhost ~]#tar c -O -C /tmp/backup/ aaa/etc/*.txt | tar x -C /
tar: aaa/etc/*.txt: Warning: Cannot stat: No such file or directory

디렉토리를 찾지 못하네요..

그런데..
[root@localhost ~]#tar c -O -C /tmp/backup/ aaa/etc/test.txt | tar x -C /
위에서 처럼 * 대신에 파일명을 적어주면 잘 되네요..

* 를 인식하게 할 방법은 없을까요??

whitelka의 이미지

특정 파일을 확인하나보네요. cannot stat이라는 말이 뜨는걸 보니깐요.

tar 명령어 옵션을 바꿔보시거나
tar 소스를 확인해 보시는게 어떨까요^^;

익명 사용자의 이미지

그건 tar가 할 일이 아니라 쉘이 할 일인데요.
저것만 봐서는 무슨 쉘을 쓰는지는 모르지만 쉘 매뉴얼을 보면 (C 쉘의) noglob같이 그거 조정하는 쉘 변수가 있을겁니다.

익명 사용자의 이미지

안되는 이유는 "aaa/etc/*.txt"는 shell이 현재 디렉토리에서 expand하려고 하니
없어서 "aaa/etc/*.txt" 그대로 tar 에 넘기기때문입니다.
tar 입장에서는 *.txt를 문자 그대로 해석하려고 시도하고요..

이런 경우는 보통 find + tar 조합을 써서 합니다.
그런데 미리 /tmp/backup 디렉토리로 이동한 후에 하면 간단한데, 옮기지 않고 하자니
좀 복잡해지네요..

$ find /tmp/backup -name "*.txt" -printf "%P\n" | xargs tar c -O -C /tmp/backup |  tar x -C /

그런데 /에 바로 쓰는거라 좀 위험하네요.. 충분히 확인해보고 시도하세요
또 *.txt 파일이 많다면 xargs와 tar c의 조합은 잘 동작 안할 수도 있습니다.
이경우에는 또 -O 옵션이 있어서 어떻게 될지 잘 모르겠네요..

익명 사용자의 이미지

그냥 "*.txt" 가 아니라 "aaa/etc/*.txt" 군요...
그러면 중간에 grep을 한번더 넣어야겠네요..

$ find /tmp/backup -name "*.txt" -printf "%P\n" | grep "^aaa/etc/" | xargs tar c -O -C /tmp/backup |  tar x -C /

xargs + tar c 조합의 문제는 없을 것 같습니다. (-O때문에)

익명 사용자의 이미지

또 오류가 있네요..

원글자의 의도는

/tmp/backup/aaa/etc/a.txt
/tmp/backup/aaa/etc/b.txt
/tmp/backup/aaa/etc/subdir/c.txt

가 있으면 이걸

/aaa/etc/a.txt
/aaa/etc/b.txt

로 카피하기를 원하는 건데, 위 코드는 /etc/subdir/c.txt도 되네요..

그런데 디렉토리 recursive하게 안하려면, 그냥 cp를 쓰는게 낫지 않나요??

mkdir -p /aaa/etc; cp /tmp/backup/aaa/etc/*.txt /aaa/etc

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.