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:'

Happy Birthday! (part two)

19 06 2011

…and now…how often was my birthday on a monday (tuesday etc.)?
(example for 18th of june, 2001-1011)

for i in {2001..2011}; do date +%A --date=$i-06-18; done | sort -k 2 | uniq -c

happy birthday!

18 06 2011

ever wanted to know on which day of the week your birthday was in the past years (or will be in the future)? here you go!
(example for 18th of june, 2001-1011)

 for i in {2001..2011}; do date +%Y%t%A --date=$i-06-18; done

play local music

17 06 2011

$ playall $1 [noshuffle]

…and don’t forget change line 6, according to the place your music is in

# play all files in subdirectories containing $1 in file- or directory name
# noshuffle option is optional =)
# requires mplayer (alternate choice possible)
# switch to music directory
cd /media/data/music
# look for files containing $1, create playlist
echo ...looking for music files...
find | grep -i $1 > $1.pls
echo ...files found:
cat $1.pls
# calculate the number of files found
numfiles=$(echo "$(wc -l $1.pls | sed 's/[a-z]*.pls//g')-1" | bc -l)
echo ...$numfiles files were found...
echo ...starting playback...
# play files, output only main information (via grep)
if [ "$2" = "noshuffle" ]
        then mplayer -playlist $1.pls | grep Playing
        exit 1
        else mplayer -shuffle -playlist $1.pls | grep Playing
# tidy up
rm $1.pls

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

Hello world!

17 06 2011

This is my new blog concerning bash scripts useful in daily life.

Hope it helps.