Move files of a certain year to other directory

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Move files of a certain year to other directory
# 1  
Old 04-22-2010
Move files of a certain year to other directory

Hi all,

I have a massive amount of recording files in .WAV format stored in a directory, files dating back to 2006.

It is a huge amount of files as Linux cannot even do a listing of it all, it states: "argument list too long"

What I would like to do is the following:
Find all the files of each specific year, zip them individually in type .gz, and move them to a folder, like move all files for the year 2006 into a folder called "Rec_2006", but also zip them while moving if at all possible.
Same for 2007 and onwards ...
If they cannot be zipped it is not a train smash.

As from there I will back them up to tape to be able to free up some space on the server.

Any help at being able to do this will be much appreciated.


Thanks.
# 2  
Old 04-22-2010
Is there a naming convention for the files, or is the distinction based on the modification time of the files? Or something else?
# 3  
Old 04-22-2010
Apologies

The distinction is based on creation date of the files.

Examples will look similar to this:
Code:
Aug  3  2007 20070803-142942-1186144182.202734.WAV.gz
Aug  3  2007 20070803-154033-1186148433.204958.WAV.gz
Aug  3  2007 20070803-155954-1186149594.205511.WAV.gz
Aug  3  2007 20070803-162047-1186150831.206103.WAV.gz
Aug  6  2007 20070806-085914-1186383554.212839.WAV.gz
Aug  6  2007 20070806-090509-1186383909.213104.WAV.gz
Aug  6  2007 20070806-092228-1186384928.213627.WAV.gz
Aug  6  2007 20070806-100016-1186387199.383.WAV.gz

I then basically want to move all the files from 1 January to 31 December 2007 into a folder, and so on for each year.

Last edited by pludi; 04-22-2010 at 04:41 PM..
# 4  
Old 04-22-2010
So the file names are already based on the recording date? Or should the result be named as such? Because from what information you've given that's not clear.
# 5  
Old 04-22-2010
That was a bad example as those were results, with the date pre-pended to the existing file names.
The date in the filename is not really needed, as long as the files for a specific year is moved to the correct folder.

Better file examples might be:

Code:
Apr 16 12:36 q1234--1271413803.344399.WAV
Apr 16 12:32 q1234--1271413847.344480.WAV
Apr 22 09:22 OUT1391--1271920802.559720.WAV
Apr 22 09:29 OUT1391--1271921281.560443.WAV
Apr 22 09:34 OUT1391--1271921538.560845.WAV


Thanks

Last edited by pludi; 04-22-2010 at 04:41 PM..
# 6  
Old 04-22-2010
Quote:
Originally Posted by codenjanod
That was a bad example as those were results, with the date pre-pended to the existing file names.
The date in the filename is not really needed, as long as the files for a specific year is moved to the correct folder.

Better file examples might be:

Code:
Apr 16 12:36 q1234--1271413803.344399.WAV
Apr 16 12:32 q1234--1271413847.344480.WAV
Apr 22 09:22 OUT1391--1271920802.559720.WAV
Apr 22 09:29 OUT1391--1271921281.560443.WAV
Apr 22 09:34 OUT1391--1271921538.560845.WAV


Thanks
How can you recognize the year of the files?
# 7  
Old 04-22-2010
Since I don't have your environment, this is more or less untested:
Code:
for (( year=2000; year<=2011; year++ )); do
    echo mkdir -p rec_${year}
    touch -t "${year}01010000" reference
    find . -maxdepth 1 -iname '*.wav' '!' -newer reference \
        -exec echo mv {} rec_${year}/. \; \
        -exec echo gzip -9 rec_${year}/{} \;
done

Try it first like this, and if the results look reasonable, remove the echos.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How Create new directory and move files to that directory.?

Hi All, We have main directory called "head" under this we have several sub directories and under these directories we have sub directories. My requirement is I have to find the SQL files which are having the string "procedure" under "head" directory and sub directories as well. And create... (14 Replies)
Discussion started by: ROCK_PLSQL
14 Replies

2. UNIX for Dummies Questions & Answers

How to move gz files from one source directory to destination directory?

Hi All, Daily i am doing the house keeping in one of my server and manually moving the files which were older than 90 days and moving to destination folder. using the find command . Could you please assist me how to put the automation using the shell script . ... (11 Replies)
Discussion started by: venkat918
11 Replies

3. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

4. UNIX for Dummies Questions & Answers

Zip all files in a directory and move to another directory

Hi, need to zip all files in a directory and move to another directory after the zip.. i am using this one but didnt help me... zip -r my_proj_`date +%Y%m%d%H%MS`.zip /path/my_proj mv in_proj_`date +%Y%m%d%H%M%S`.zip /path/source/ i am trying to zip all the files in my_proj... (0 Replies)
Discussion started by: dssyadav
0 Replies

5. UNIX for Dummies Questions & Answers

move all 2008 year's file to destination directory

I am trying to move file created/modified in 2008 year to <new directory>. But trapped badly in Xargs {}. Looks like mv is not getting destination file properly. It assumes source file s to be destination directory n gives me erroir. "Target must be a directory" Run- #/home/mktrisk: find... (4 Replies)
Discussion started by: kedar.mehta
4 Replies

6. UNIX for Dummies Questions & Answers

Move files based on year

Hi All, I have a directory which has crores of files since from 2003. I want to move ony the 2003 files to another directory. Please help (9 Replies)
Discussion started by: IHK
9 Replies

7. Shell Programming and Scripting

Move files based on year of creation

Hi All, I have a directory which has crores of files since from 2003 till now. I want to move only the 2003 files to another directory. Please help. Thanks (2 Replies)
Discussion started by: IHK
2 Replies

8. UNIX for Dummies Questions & Answers

Move files based on year

I have a directory which has crores of files since from 2003. I want to move only the 2003 files to another directory. Please help in doing this. Thanks (1 Reply)
Discussion started by: IHK
1 Replies

9. UNIX for Dummies Questions & Answers

Move all files in a directory tree to a signal directory?

Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management. Thanks in advance- Brian- (2 Replies)
Discussion started by: briandanielz
2 Replies
Login or Register to Ask a Question