Filename => Creation date

21 06 2011

bored by manually sorting your photos? just rename all .jpg (or whatever filetype) files in the current directory to yymmdd_HHMMSS.jpg (or whatever filetype).
usage: $ filetodate $1
The passed variable ($1) is the filetype you want to rename. To be exact, the files in the current directory are filtered by $1. So beware that if you use ‘filetodate jpg’ and have a file named ‘ilovejpgs.txt’, this file will also be renamed.
This script can be easily adapted to your needs by changing the ‘d=$(date +…)’-line.

files=$(ls | grep -i $1 )
echo 'Files:' $files
for i in ${files}
    d=$(date -r $i +%y%m%d_%H%M%S.$e)
    echo 'renaming' $i' to '$d
    mv $i $d
    echo 'new files:'

remove all spaces in filenames of the current directory

17 06 2011

$ removespaces

for file in *
do mv "$file" `echo $file | sed -e 's/ */_/g' -e 's/_-_/-/g'`
# alternative:
# for files in *.mp3; do mv “$files” `echo $files | tr ‘ ‘ ‘_’`; done