1
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コマンド【touch】で、連番ファイルを作成する方法

Posted at

Linuxのtouchコマンドを利用したファイル作成、重複する内容を何回も打つのは面倒です。

terminal
# Before

例1)
desktop$ touch sample-1.txt
desktop$ touch sample-2.txt
desktop$ touch sample-3.txt
・
・
desktop$ touch sample-10.txt

例2)
desktop$ touch イヌ.txt
desktop$ touch サル.txt
desktop$ touch キジ.txt

解決策

{}を利用することで、簡潔に書くことができます。

  • 半角数字, 半角英数字の場合
    ⇨ { 1..10 } や { a..g } のように範囲指定による作成が可能

  • ひらがな、カタカナや漢字の場合
    ⇨ {イヌ,サル,キジ} のように,で区切ることによる作成が可能( 注:単語と,の間にスペースが入ると正しく認識されない)

terminal
# After

例1)
desktop$ touch sample-{1..10}.txt

例2)
desktop$ touch {イヌ,サル,キジ}.txt

おまけ)
# 「イヌファイル1-5, サルファイルは1-10, キジファイルはa-gの連番を作成」とすることも可能
desktop$ touch {イヌ-{1..10},サル-{1..5},キジ-{a..g}}.txt

# おまけの実行結果:
 イヌ-1.txt
 ・
 ・
 イヌ-10.txt
 サル-1.txt
 ・
 ・
 サル-5.txt
 キジ-a.txt
 ・
 ・
 キジ-g.txt

いつもお世話になっているQiita,初めて投稿してみました。
どなたかのお役に立てば嬉しいです。

1
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
1
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?