LoginSignup
3
0

More than 5 years have passed since last update.

tarコマンドのオプションが覚えられない人向けのエイリアス

Last updated at Posted at 2019-04-11

UNIX系では.zipの代わりに.tar.gzもよく使いますね。しかしオプションが複雑で毎回忘れていました。
tarについてちょちょっと調べてみました。

tarコマンドのオプション

オプション 意味
tar czvf 第2引数以下で指定したファイルから
第1引数で指定した名前で.tar.gz形式のファイルを作る
tar xzvf 第1引数で指定した.tar.gz形式のファイルを解凍する
tar tzvf 第1引数で指定した.tar.gz形式のファイルの中身を
解凍せずに確認する

参考: https://teppeis.hatenablog.com/entry/20080109/1199897258

man ページに乗っている公式仕様から上記で使っている部分も抜粋しておきます。

DESCRIPTION
     -c      Create a new archive containing the specified items.
     -x      Extract to disk from the archive.  If a file with the same name appears more than once in the archive, each copy
             will be extracted, with later copies overwriting (replacing) earlier copies.
     -t      List archive contents to stdout.

OPTIONS
     -z      (c mode only) Compress the resulting archive with gzip(1).  In extract or list modes, this option is ignored.  Note
             that, unlike other tar implementations, this implementation recognizes gzip compression automatically when reading
             archives.
     -v      Produce verbose output.  In create and extract modes, tar will list each file name as it is read from or written to
             the archive.  In list mode, tar will produce output similar to that of ls(1).  Additional -v options will provide
             additional detail.
     -f file
             Read the archive from or write the archive to the specified file.  The filename can be - for standard input or
             standard output.

エイリアスの考案

tarについて多少詳しくなりましたが、やはりこのオプションは忘れます。そこでエイリアスを考えてみます。

alias tarzip='tar czvf'
alias tarunzip='tar xzvf'
alias tarls='tar tzvf'

これだと直感的で分かりやすいんじゃないでしょうか。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0