Skip to content

Instantly share code, notes, and snippets.

@CLCL
Last active January 4, 2021 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CLCL/55f9e6cd71a14ad79e4dded44d03abf5 to your computer and use it in GitHub Desktop.
Save CLCL/55f9e6cd71a14ad79e4dded44d03abf5 to your computer and use it in GitHub Desktop.
bashでカレントディレクトリ内にあるファイルのリネーム
# カレントディレクトリのScreenShot hoge.png を hoge.pngにリネーム
# bashでリネーム 変数 $FILE は ${FILE}とも書ける
# ${FILE##ScreenShot }とすると文頭から最長マッチでその文字列を除去した文字列を値として持つ
for FILE in *; do mv "${FILE}" "${FILE##ScreenShot }"; done
# カレントディレクトリのhoge_HD-1.mp4 を hoge_mp4にリネーム
# bashでリネーム 変数 $FILE は ${FILE}とも書ける
# ${FILE%HD-1.mp4 }とすると文末から最短マッチでその文字列を除去した文字列を値として持つ
for FILE in *; do mv "${FILE}" "${FILE%_HD-1.mp4}.mp4"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment