LoginSignup
9

More than 5 years have passed since last update.

現在の日付を追加してファイルのバックアップをとるコマンド

Last updated at Posted at 2015-01-07

やりたいこと

cpコマンドでバックアップファイルを取るのが面倒なので、バックアップを取るだけのコマンドが欲しい。

背景

サーバ内の設定ファイルなどを直接変更したい場合、バックアップを取る習慣がある。

$ cp -p hoge hoge.20150108

コマンド:bkup

この時、いちいちこんなコマンドを打つのが面倒でしょうがなかったので、簡単ではあるがコマンドを作った。

$ more ~/.zshrc
function bkup(){ cp -p $1 $1."`date '+%Y%m%d'`" }

$ zsh
$ ls
hoge

$ bkup hoge
$ ls
hoge hoge.20150108

まとめ

今回はzshでやったが、bashでも.bashrcとかに書き込めば出来ると思う。bashの場合はコメント参照。

あと引数なしのときはサボってるので完成度は低いです。あくまで簡易的。

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
9