Skip to content

Instantly share code, notes, and snippets.

@cubapp
Last active October 14, 2020 20:10
Show Gist options
  • Save cubapp/a71e9988a0a8cafb9564f9fd612d9363 to your computer and use it in GitHub Desktop.
Save cubapp/a71e9988a0a8cafb9564f9fd612d9363 to your computer and use it in GitHub Desktop.
Rename files in subdirectories according to the directory name. Dirty - files with spaces does not work (grrrr)
for i in $(ls -1); { echo $i; (cd $i; for ff in * ; { aa=$((aa+1)) ; mv "$ff" ${i}-${aa}.jpg } ) }
@cubapp
Copy link
Author

cubapp commented Oct 14, 2020

file structure before:


$ find .
.
./a
./a/eroit
./a/ert
./b
./b/adsflkjadslfjadsf
./b/asdfasdf
./c
./c/3400
./c/4353
./d
./ef
./ef/asdfasdfsadfsadfsadfsaf
./ef/asdflkasdf
./ef/rreoijweroiuwerowueroiwueroiuwer
./rg
./rg/1
./rg/2323
./thn
./thn/bla
./thn/cvbx
./thn/qwe
./thn/sadfa


and after:


$ find .
.
./a
./a/a-1.jpg
./a/a-2.jpg
./b
./b/b-1.jpg
./b/b-2.jpg
./c
./c/c-1.jpg
./c/c-2.jpg
./d
./ef
./ef/ef-1.jpg
./ef/ef-2.jpg
./ef/ef-3.jpg
./rg
./rg/rg-1.jpg
./rg/rg-2.jpg
./thn
./thn/thn-1.jpg
./thn/thn-2.jpg
./thn/thn-3.jpg
./thn/thn-4.jpg


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