gzipで解凍時に元ファイルが消えないようにする ~ググる前にヘルプを見よう~
gzipで.gz
ファイルを解凍(展開よりも解凍という言い方の方が僕は好きです)すると、入力ファイルが消えてしまいます。消えない方法を探します。
目次
例
理想
$ gzip -d ./backup.dump.gz $ ls ./ backup.dump backup.dump.gz
理想としては、出力ファイルが生成されて、かつ、入力ファイルも残ってほしいわけです。しかし....
現実
$ gzip -d ./backup.dump.gz $ ls ./ backup.dump
(-d
は解凍するときにつけるオプションです。)
入力ファイルは残りません!!!
ググる
とりあえず「gzip 解凍 コマンド」でググってみました。
Google検索の上位2ヒットのページが以下になります。
見つかりませんねぇ...(○ω○)
残す方法はないのでしょうか?
ヘルプを見るべし!
上の例では日本語で検索していました。日本語で出ないときは英語で検索するのが定石(僕調べ)ですが、今回の場合は、それよりも手っ取り早い方法があります。
ヘルプを見ましょう。(もしくはmanual)
というわけでヘルプを以下に載せます。
$ gzip -h Usage: gzip [OPTION]... [FILE]... Compress or uncompress FILEs (by default, compress FILES in-place). Mandatory arguments to long options are mandatory for short options too. -a, --ascii ascii text; convert end-of-line using local conventions -c, --stdout write on standard output, keep original files unchanged -d, --decompress decompress -f, --force force overwrite of output file and compress links -h, --help give this help -k, --keep keep (don’t delete) input files -l, --list list compressed file contents -L, --license display software license -n, --no-name do not save or restore the original name and time stamp -N, --name save or restore the original name and time stamp -q, --quiet suppress all warnings -r, --recursive operate recursively on directories -S, --suffix=SUF use suffix SUF on compressed files -t, --test test compressed file integrity -v, --verbose verbose mode -V, --version display version number -1, --fast compress faster -9, --best compress better --rsyncable Make rsync-friendly archive With no FILE, or when FILE is -, read standard input. Report bugs to <bug-gzip@gnu.org>.
ありましたね。
-k
,--keep
keep (don't delete) input files
keep input files → 「入力ファイルを保持」ということですね。
さっそく実行してみます。
$ gzip -d -k ./backup.dump.gz $ ls ./ backup.dump backup.dump.gz
確かに入力ファイルが残っています!
結論
コマンドに関する疑問があったら-h
または--help
でヘルプを見ましょう!もしくはmanコマンドを使ってmanualを見ましょう。
きっと、検索する文言を考える時間もかからずに答えが見つかるはず