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?

現在の年月日を表す正規表現

Posted at

概要

Linuxでバックアップファイル作成時等に逐一日付を入力するのは少し手間ということで、それを表す正規表現になります。
正直覚えるのはキツイので何かにコピペしてすぐ使える様にすると便利だと思います。

正規表現

{,.$(date "+%Y%m%d")}

実行例

dateファイルのバックアップファイルを今日の日付で作ってみます

a@iMac-PC-0079 ~ % touch date
a@iMac-PC-0079 ~ % ll date 
-rw-r--r--  1 a  staff  0  9  3 09:56 date
a@iMac-PC-0079 ~ % cp date{,.$(date "+%Y%m%d")}
a@iMac-PC-0079 ~ % ll | grep date
-rw-r--r--    1 a  staff      0  9  3 09:56 date
-rw-r--r--    1 a  staff      0  9  3 09:56 date.20250903

20250903の日付で作られましたね
シェルスクリプトとかではこの正規表現がよく使われますね

※記事執筆時は2025年9月3日

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?