Skip to content

Instantly share code, notes, and snippets.

@compor
Created February 25, 2013 15:23
Show Gist options
  • Select an option

  • Save compor/5030553 to your computer and use it in GitHub Desktop.

Select an option

Save compor/5030553 to your computer and use it in GitHub Desktop.
directory filename cleanup
# 1] convert all to lowercase letters
convmv --lower --notest *
# 2] remove naming defects such as :
# a] consecutive spaces
# b] weird characters like commas, parentheses, underscores, etc
# for a]
rename "s/\ +/ /g" *
# for b]
rename "s/,//g" *
# ps: i don't like file names with things like ".net" so i replace them with "dotnet"
# 3] if you have more than 1 dot in the file name apart from the file extension and
# you want to preserve the file extension but remove the rest of them, then
# a] find out what kind of extensions you have and fix appropriately (if you have to)
find . -maxdepth 1 -name '*\.????' -print
find . -maxdepth 1 -name '*\.???' -print
# b] replace the dot of the extension to a symbol that does not match any file e.g. the hash mark '#'
rename 's/\.(.{3}$)/#$1/g' *
c] replace all the dot characters not denoting a version number i.e. must have non-digit characters either before or after the dot
rename 's/(\D)(\.)(\D)/$1 $3/g' *
rename 's/(\D)(\.)(\d)/$1 $3/g' *
rename 's/(\d)(\.)(\D)/$1 $3/g' *
d] replace the odd character with the dot for a proper file extension naming
rename "s/#/./g" *
# important
# when using the rename command provide the following switches
# -v : for verbose mode
# -n : do not perform any renaming, just display them in combination with -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment