LoginSignup
0
0

More than 3 years have passed since last update.

.bakを再帰的につけるバックアップスクリプト

Posted at
bak() (
    for file in "$@"; do
        bakfile="$file"'.bak'
        if [ -e "$bakfile" ]; then
            echo 'already exists: '"$bakfile"
            bak "$bakfile"
        fi
        cp "$file" "$bakfile"
    done
)

~/.bashrc などに追記すると、

fileA
This is A.

に対して

$ ls
fileA
$ bak fileA
$ ls
fileA fileA.bak
$ echo 'This is A!' > fileA # fileAの中身を This is A! に上書き
$ bak fileA
already exists: fileA.bak
$ ls
fileA fileA.bak fileA.bak.bak

とするとき、それぞれのファイルの中身は、

fileA fileA.bak fileA.bak.bak
This is A! This is A! This is A.

という調子で、より古いファイルに .bak がどんどんつきます。

0
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
0
0