Skip to content

Instantly share code, notes, and snippets.

@chenghanc
Created December 12, 2024 10:13
Show Gist options
  • Select an option

  • Save chenghanc/89f460062e65fecf3494ad1fea9caff9 to your computer and use it in GitHub Desktop.

Select an option

Save chenghanc/89f460062e65fecf3494ad1fea9caff9 to your computer and use it in GitHub Desktop.
Renaming files in a folder to sequential numbers
# jpg files
a=1
for i in *.jpg; do
new=$(printf "%04d.jpg" "$a")
mv -i -- "$i" "$new"
let a="$a+1"
done
# xml files
a=1
for i in *.xml; do
new=$(printf "%04d.xml" "$a")
mv -i -- "$i" "$new"
let a="$a+1"
done
@chenghanc
Copy link
Author

Renaming files in a folder to img + sequential numbers

# jpg files
a=1
for i in *.jpg; do
  new=$(printf "img-%04d.jpg" "$a")
  mv -i -- "$i" "$new"
  let a="$a+1"
done

# txt files
a=1
for i in *.txt; do
  new=$(printf "img-%04d.txt" "$a")
  mv -i -- "$i" "$new"
  let a="$a+1"
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment