LoginSignup
3
3

More than 5 years have passed since last update.

*.confとかバックアップファイルを複数纏めてワンライナー

Last updated at Posted at 2015-08-06

あらまし

  • 設定変更する時にリビジョン管理してればいいよね
    • してない!
    • 困った!
    • cp -p で頑張るか…
    • それコンフィグファイルが無数にあっても頑張れる?

大体の例

  • よくあるパターン
    $ sudo cp -p hogehoge.conf hogehoge.conf.YYYMMDD
    $ sudo cp -p hogehoge.cfg{,.org}

  • 3つくらいとかなら頑張れる

こうしてみる

  • for文の条件式にfindの結果を投げる
  • dateコマンドで日付は自動入力
$ mkdir ./OLD/
$ ls 
OLD commands.cfg  contacts.cfg  localhost.cfg  printer.cfg  switch.cfg  templates.cfg  timeperiods.cfg  windows.cfg
$ for cfg in $(find ./ -name "*.cfg"); do  sudo -S cp -p ${cfg} ./OLD/${cfg}.`date +%Y%m%d`; done
$ ls OLD/
commands.cfg.20150806  localhost.cfg.20150806  switch.cfg.20150806     timeperiods.cfg.20150806
contacts.cfg.20150806  printer.cfg.20150806    templates.cfg.20150806  windows.cfg.20150806

結論

  • シェルスクリプト慣れると便利
3
3
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
3