I understood the question in a different way than Kent. I thought that you wanted to create a new tree of directories from each original one and move all files that it contained. You could try following perl script if that was what you were looking for:
perl -MFile::Path=make_path -MFile::Copy=move -e '
for ( grep { -d } @ARGV ) {
@date = m/\A(\d{4})-(\d{2})-(\d{2})/;
next unless @date;
$outdir = join q{/}, @date;
make_path( $outdir );
move( $_, $outdir );
}
' *
It reads every file from current directory (*
passed as argument) and does two step filter. The first one is the grep
for no-directories files and the second one is an undefined @date
for those that don't begin with it. Then it joins date's components into a path, creates it if doesn't exist and move the old one with all its files to the new one.
A test:
Here the result of ls -lR
to show initial state:
.:
total 24
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:56 1993-02-22 - The Moon - Tallahassee, FL
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:56 1993-02-23 - The Moon - Tallahassee, FL
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:56 1993-02-24 - The Moon - Tallahassee, FL
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:57 1993-02-25 - The Moon - Tallahassee, FL
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:57 1993-03-01 - The Test - Null, FL
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:47 dummy_dir
-rw-r--r-- 1 dcg dcg 0 sep 7 00:47 dummy_file
./1993-02-22 - The Moon - Tallahassee, FL:
total 0
-rw-r--r-- 1 dcg dcg 0 sep 7 00:56 file1
-rw-r--r-- 1 dcg dcg 0 sep 7 00:56 file2
./1993-02-23 - The Moon - Tallahassee, FL:
total 0
-rw-r--r-- 1 dcg dcg 0 sep 7 00:56 file3
./1993-02-24 - The Moon - Tallahassee, FL:
total 0
-rw-r--r-- 1 dcg dcg 0 sep 7 00:56 file4
./1993-02-25 - The Moon - Tallahassee, FL:
total 0
-rw-r--r-- 1 dcg dcg 0 sep 7 00:57 file5
-rw-r--r-- 1 dcg dcg 0 sep 7 00:57 file6
./1993-03-01 - The Test - Null, FL:
total 0
-rw-r--r-- 1 dcg dcg 0 sep 7 00:57 file7
./dummy_dir:
total 0
And after running the previous script note that the base directory only keeps dummy files and the root of the tree created (1993
). Running the same ls -lR
yields:
.:
total 8
drwxr-xr-x 4 dcg dcg 4096 sep 7 00:59 1993
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:47 dummy_dir
-rw-r--r-- 1 dcg dcg 0 sep 7 00:47 dummy_file
./1993:
total 8
drwxr-xr-x 6 dcg dcg 4096 sep 7 00:59 02
drwxr-xr-x 3 dcg dcg 4096 sep 7 00:59 03
./1993/02:
total 16
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:56 22
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:56 23
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:56 24
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:57 25
./1993/02/22:
total 0
-rw-r--r-- 1 dcg dcg 0 sep 7 00:56 file1
-rw-r--r-- 1 dcg dcg 0 sep 7 00:56 file2
./1993/02/23:
total 0
-rw-r--r-- 1 dcg dcg 0 sep 7 00:56 file3
./1993/02/24:
total 0
-rw-r--r-- 1 dcg dcg 0 sep 7 00:56 file4
./1993/02/25:
total 0
-rw-r--r-- 1 dcg dcg 0 sep 7 00:57 file5
-rw-r--r-- 1 dcg dcg 0 sep 7 00:57 file6
./1993/03:
total 4
drwxr-xr-x 2 dcg dcg 4096 sep 7 00:57 01
./1993/03/01:
total 0
-rw-r--r-- 1 dcg dcg 0 sep 7 00:57 file7
./dummy_dir:
total 0