0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ファイルの変更時刻に基づいて名前変更 (Linux)

0
Posted at

ファイルの変更時刻に基づいて名前変更

コマンド

LOGFILE にファイル名を変更したいファイル名が入っているとして

if [ -e $LOGFILE ]; then
   TIMESTAMP=$(date -r $LOGFILE "+%Y-%m-%d_%H_%M_%S")
   mv $LOGFILE $LOGFILE.$TIMESTAMP
fi

とすればよい。

説明

date -r ファイル名ファイル名 で指定したファイルの変更時刻を取得できる。
"+%Y-%m-%d_%H_%M_%S"date -r で返す形式をしているしている。

$(コマンド) を使うことにより コマンド の実行結果を変数に代入できる。

mv で実際の名前変更を実行する。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?