Bash

From Han Wiki
Revision as of 14:56, 9 September 2019 by Mhan (talk | contribs) (iwu)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Jump to navigation Jump to search

bash script snippets

file renaming

Rename all *.jpg files in a folder to 0001.jpg, 0002.jpg, etc.

#!/bin/bash
a=1
for i in *.jpg; do
  new=$(printf "%04d.jpg" "$a") #04 pad to length of 4
  mv -i -- "$i" "$new"
  let a=a+1
done