Created
April 25, 2020 20:08
-
-
Save WSAyan/99c13aac3ffcb7f0ccf5a3deb252f817 to your computer and use it in GitHub Desktop.
Rename all files with ascending number in a directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # rename all files with ascending number in a directory | |
| # sh rename.sh -e [extension] -f [first number] -name [optinal name in first] | |
| _ext="" | |
| _first=0 | |
| _name="" | |
| while getopts ":e:o:f:n:" opt; do | |
| case $opt in | |
| e) | |
| _ext="$OPTARG" | |
| ;; | |
| f) | |
| _first="$OPTARG" | |
| ;; | |
| n) | |
| _name="$OPTARG" | |
| ;; | |
| \?) | |
| echo "ERROR: Invalid option: -$OPTARG" >&2 | |
| exit | |
| ;; | |
| esac | |
| done | |
| i=$_first | |
| for file in *.$_ext; do | |
| mv "$file" "$_name$i.$_ext" | |
| i=$((i+1)) | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment