Skip to main content
added 24 characters in body
Source Link
heemayl
  • 58.1k
  • 9
  • 129
  • 144

InodeApart from hardlink(s), inode of a file is guaranteed to be unique, within the same filesystem. Iterating over the .JPG files in the current directory, and renaming (mv-ing) with help from stat to get the inode:

for i in *.JPG; do echo mv -- "$i" "$(stat -c '%i' "$i")"; done 

echo will spit out the mv command that would be run. Remove echo for actual action:

for i in *.JPG; do mv -- "$i" "$(stat -c '%i' "$i")"; done 

Also, if you want the final filenames to have the .JPG extension too:

for i in *.JPG; do mv -- "$i" "$(stat -c '%i' "$i").JPG"; done 

Inode of a file is guaranteed to be unique, within the same filesystem. Iterating over the .JPG files in the current directory, and renaming (mv-ing) with help from stat to get the inode:

for i in *.JPG; do echo mv -- "$i" "$(stat -c '%i' "$i")"; done 

echo will spit out the mv command that would be run. Remove echo for actual action:

for i in *.JPG; do mv -- "$i" "$(stat -c '%i' "$i")"; done 

Also, if you want the final filenames to have the .JPG extension too:

for i in *.JPG; do mv -- "$i" "$(stat -c '%i' "$i").JPG"; done 

Apart from hardlink(s), inode of a file is guaranteed to be unique, within the same filesystem. Iterating over the .JPG files in the current directory, and renaming (mv-ing) with help from stat to get the inode:

for i in *.JPG; do echo mv -- "$i" "$(stat -c '%i' "$i")"; done 

echo will spit out the mv command that would be run. Remove echo for actual action:

for i in *.JPG; do mv -- "$i" "$(stat -c '%i' "$i")"; done 

Also, if you want the final filenames to have the .JPG extension too:

for i in *.JPG; do mv -- "$i" "$(stat -c '%i' "$i").JPG"; done 
Source Link
heemayl
  • 58.1k
  • 9
  • 129
  • 144

Inode of a file is guaranteed to be unique, within the same filesystem. Iterating over the .JPG files in the current directory, and renaming (mv-ing) with help from stat to get the inode:

for i in *.JPG; do echo mv -- "$i" "$(stat -c '%i' "$i")"; done 

echo will spit out the mv command that would be run. Remove echo for actual action:

for i in *.JPG; do mv -- "$i" "$(stat -c '%i' "$i")"; done 

Also, if you want the final filenames to have the .JPG extension too:

for i in *.JPG; do mv -- "$i" "$(stat -c '%i' "$i").JPG"; done