tarコマンドでファイルを展開する際に一番上のディレクトリを取り除く

たとえばApacheのソースコードを、直下のsrcに展開する際、

tar -xvf httpd-2.4.55.tar.gz -C src

とすると、

ls src/
httpd-2.4.55

とhttpd-2.4.54フォルダの下にコードが展開される

このhttpd-2.4.54を取り除いて、httpd-2.4.54フォルダの下位フォルダ、ファイルを展開したい場合は、tarコマンドの–strip-componentsオプションを使用する

tar -xvf httpd-2.4.55.tar.gz -C src --strip-components=1
ls src
ABOUT_APACHE     CMakeLists.txt  Makefile.win    README.platforms  build            docs         include       server
Apache-apr2.dsw  INSTALL         NOTICE          ROADMAP           buildconf        emacs-style  libhttpd.dep  srclib
Apache.dsw       InstallBin.dsp  NWGNUmakefile   VERSIONING        changes-entries  httpd.dep    libhttpd.dsp  support
BuildAll.dsp     LAYOUT          README          acinclude.m4      config.layout    httpd.dsp    libhttpd.mak  test
BuildBin.dsp     LICENSE         README.CHANGES  ap.d              configure        httpd.mak    modules
CHANGES          Makefile.in     README.cmake    apache_probes.d   configure.in     httpd.spec   os

参考