Jan. 1st, 2010

elfs: (Default)

This morning, for no reason that I’d care to discuss in public, I needed to rename every file in a directory to the index number of its position in the directory in asciibetical order, and add an extension.

The harmless version of this was:

ls | gawk 'BEGIN { c = 0; } c += 1 { print "mv", $0, c".jpg" }'

The version that actually does the work:

ls | gawk 'BEGIN { c = 0; } c += 1 { print "mv", $0, c".jpg" }' | bash

Better version (harmless):

ls | gawk '{ printf ("mv \"%s\" %02d.jpg\n", $0, NR) }'

Don’t use the second unless, well, you know, you intend on doing it.

This entry was automatically cross-posted from Elf's technical journal, ElfSternberg.com

Profile

elfs: (Default)
Elf Sternberg

May 2026

S M T W T F S
     12
3456789
10 111213141516
17181920212223
24252627282930
31      

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 22nd, 2026 12:13 am
Powered by Dreamwidth Studios