I have a bunch of files in sub-directories that I want to move to a different directory.
The directories are organized in one parent directory like this: Apr1995 Apr1996 Aug1995 etc... (month then year)
so /Files/Apr1995 for example.
the files are formatted like this 1995___.info or 1995___.dat
I want to go into each sub directory and move files to a different directory where the sub directories are separated by year and then format. Something like this:
OtherFiles/1995/info, OtherFiles/1995/dat, OtherFiles/1996/info, etc.
The 1995 directory would have sub-directories named info and dat
In the end I want this organization for example:
Desktop/Files/Apr1995/1995__.info,
Desktop/Files/Apr1995/1995__.dat,
Desktop/OtherFiles/1995/info,
Desktop/OtherFiles/1995/dat and so on
I've tried quite a few options like a couple of one liners:
for d in ./*/ ; do (cd "$d" && mv 1995*.info /1995/info); done
or
find ./ -type f -execdir mv 1995*.info /1995/info {} \;
I just get mv errors or it doesn't recognize that their are files like those.
A shell script could help too.
I'm kind of at a loss for something that seems relatively easy. Any help would be appreciated.
EDIT: hopefully the added info can help
cd
in the loop, but nevercd
back to the parent. Is/1995/info
really the right path? – Sparhawk Mar 10 '18 at 08:37cd
happens in a subshell, so that's ok, but it seems to me that files might get overwritten if the names of all files for a year are e.g.1995___.info
. – Kusalananda Mar 10 '18 at 08:41