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
#1
i have thousands of images named by the time they were taken and i need to move them into directories to make them more manageable.

for instance, all files named starting with 91108 need to go into 2009-11/08/

i know mv is the command, i know * is the wildcard, but i don't know how to put it all together.

do you?

thx!
Reply
#2
How about output redirection.

For example, you can redirect the output of the "ls" command from the monitor to a file that you create on the fly like so:

ls > filename

Can this also be used to create directories on the fly?
Reply
#3
Assuming you are in the directory where all the photo files reside, and that you want to add directories in the same directory:

$ mkdir -p 2009-11/08
$ mv 91108* 2009-11/08

will create the new directory (actually a new directory 2009-11 and a subdirectory 08 within that) and move all files beginning 91108 into the new (sub)directory.

I'll have to think a bit about processing all of 2009 ...
Reply
#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
#5
These GUI-based utilities may do:

Hazel: http://www.noodlesoft.com/hazel.php
Automaton: http://www.tech.com.au/Site/Home.html
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)