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.

ディレクトリ中のファイルを任意の数値から始まる連番にリネームする方法

Last updated at Posted at 2018-11-06

環境

  • macOS 10.13 (High Sierra)
  • zsh 5.3.1

コマンド

11個あるファイルを,拡張子はそのままに129から始まる連番にリネームしています.

$ ls
0e5f3ae0.jpg  63a62a6f.jpg  97077661.jpg  e416494c.jpg  f35dc873.jpg  f56c0eaf.jpg
4f50958b.jpg  81a05a5c.jpg  c4e3c9bd.jpg  e73c2b8f.jpg  f4fc4ef0.jpg

$ i=129; for f in *; do mv $f $i.${f##*.}; i=`expr $i + 1`; done

$ ls
129.jpg  130.jpg  131.jpg  132.jpg  133.jpg  134.jpg  135.jpg  136.jpg  137.jpg  138.jpg  139.jpg

0埋めする場合は次のような感じです(6桁に揃える場合).

$ ls
0e5f3ae0.jpg  63a62a6f.jpg  97077661.jpg  e416494c.jpg  f35dc873.jpg  f56c0eaf.jpg
4f50958b.jpg  81a05a5c.jpg  c4e3c9bd.jpg  e73c2b8f.jpg  f4fc4ef0.jpg

$ i=129; for f in *; do mv $f `printf "%06d" $i`.${f##*.}; i=`expr $i + 1`; done

$ ls
000129.jpg  000130.jpg  000131.jpg  000132.jpg  000133.jpg  000134.jpg  000135.jpg  000136.jpg  000137.jpg  000138.jpg  000139.jpg
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?