최상위 디렉토리를 생략하여 디렉토리에서 tar 파일 생성

최상위 디렉토리를 생략하여 디렉토리에서 tar 파일 생성

tar를 사용하여 디렉토리를 생성/추출하고 헤더/최상위 디렉토리 이름을 생략하거나 제거하려면 어떻게 해야 합니까?

답변1

man tar(GNU tar 1.34)의 몇 가지 유용한 옵션:

   -C, --directory=DIR
          Change to DIR before performing any operations.  This option
          is order-sensitive, i.e. it affects all options that follow.

   -P, --absolute-names
          Don't strip leading slashes from file names when creating archives.

   --strip-components=NUMBER
          Strip NUMBER leading components from file names on extraction.

   --transform=EXPRESSION, --xform=EXPRESSION
          Use sed replace EXPRESSION to transform file names.

man bsdtar(bsdtar 3.6.2)의 동등한 옵션:

 -C directory, --cd directory, --directory directory
         In c and r mode, this changes the directory before adding the
         following files.  In x mode, change directories after opening
         the archive but before extracting entries from the archive.

 -P, --absolute-paths
         Preserve pathnames.  By default, absolute pathnames (those that
         begin with a / character) have the leading slash removed both
         when creating archives and extracting from them.  Also, tar will
         refuse to extract archive entries whose pathnames contain .. or
         whose target directory would be altered by a symlink.  This option
         suppresses these behaviors.

 -s pattern
         Modify file or archive member names according to pattern.
         ...

 --strip-components count
         Remove the specified number of leading path elements.  Pathnames
         with fewer elements will be silently skipped.  Note that the
         pathname is edited after checking inclusion/exclusion patterns
         but before security checks.

busybox tar --help(busybox tar 1.34.1) 에서 :

    -C DIR  Change to DIR before operation

    --strip-components NUM  NUM of leading components to strip

관련 정보