Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
who's good at the terminal? need to move a bunch of files into directories
#4
Here's a bash shell script that should do what you want.
copy the lines inside (not including) the ==snipsnip== into a file
called, say foo.sh
=========snipsnip=================
#!/bin/bash
#
debug=1 # set debug to 0 to run for real
if (( $debug )) ; then
ECHO=echo
else
ECHO=
fi
#
hath=( 00 31 28 31 30 31 30 31 31 30 31 30 31 )
for (( m=1 ; m <= 12 ; ++m )) ; do
if (( $m < 10 )) ; then
mm=
0$m
else
mm=$m
fi
for (( d=1 ; d <= hath[m] ; ++d )) ; do
if (( $d < 10 )) ; then
dd=
0$d
else
dd=$d
fi
nd=
2009-$mm/$dd
$ECHO mkdir -p $nd
$ECHO mv -f 9${mm}${dd}* $nd
done
done
echo All done.
#
=========snipsnip================

make foo.sh executable:

$ chmod +x foo.sh

and put it in the directory where the photos reside, and where the
new month directories (and their respective day subdirectories) will be.

$ ./foo.sh

will run the new script.

The script is set to only echo the commands it would do to create each directory and move files to it. (debug=1 at the beginning).

To make it run for real, edit the script and change debug=1 to debug=0
and run the script. Directories will be created and files moved.

Test it first. Make a directory with copies of a few photo files of different dates.
(or you can just sit in the new empty test directory 'touch' some file names to create empty files to be moved).
Reply


Messages In This Thread
Re: who's good at the terminal? need to move a bunch of files into directories - by TheCaber - 12-04-2009, 06:08 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)