LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-08-2009, 03:02 PM   #1
CharlieMike73
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Rep: Reputation: 0
Post Sort files in directories based on the files date...


I need a script that will take all the files in a given directory and create new monthly sub-directories and sort all the files based on the creation date into the appropriate directory.

For example, all files created between 01/01/09 and 01/31/09 will be placed in 'JAN-2009'

Thank you,
Charlie
 
Old 09-08-2009, 03:20 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by CharlieMike73 View Post
I need a script that will take all the files in a given directory and create new monthly sub-directories and sort all the files based on the creation date into the appropriate directory.

For example, all files created between 01/01/09 and 01/31/09 will be placed in 'JAN-2009'

Thank you,
Charlie
man find

?
 
Old 09-09-2009, 07:41 AM   #3
CharlieMike73
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Original Poster
Rep: Reputation: 0
I'm sure that response was an informative one to anyone that knows/uses Linux, but I don't; I'm just covering for a college who is out sick... well trying to anyway!

Can you go into a little more detail and explain. Sorry to be a nuisance, Linux is not the platform I work on and I just need to sort these files one time so dont want to spend too much time learning something I cannot see 'myself' using again.
 
Old 09-09-2009, 11:55 AM   #4
CharlieMike73
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Hello folks. I have read the forum here but there's too much info so I need a little nudge.

I printed out the "man find" manual but it didn't make much sense as it says nothing of how to create new directories and then move the files to the appropriate month-year directory.

I also read something about "exec" but really do need some help here.

Any assistance is appreciated!
 
Old 09-09-2009, 12:13 PM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by CharlieMike73 View Post
Hello folks. I have read the forum here but there's too much info so I need a little nudge.

I printed out the "man find" manual but it didn't make much sense as it says nothing of how to create new directories and then move the files to the appropriate month-year directory.

I also read something about "exec" but really do need some help here.

Any assistance is appreciated!
Does 'find' command give you the ability to choose files based their modification date ?

The answer is in 'man find'.
 
Old 09-09-2009, 10:04 PM   #6
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Took me about 12 lines to accomplish this, without using find, and I'd post the script but this sounds too much like a school project.

Pull the filename and date from the output of ls -l
Loop over the output:
Reformat the date, to your desired directory name, using the date command and format specifier
Test to see if the directory exists and create the directory if it does not
move the file to the directory
end loop
 
  


Reply

Tags
date, directories, files, sort


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sort files inside a directory and sub-directories by latest created walidaly Linux - Software 8 07-25-2009 02:45 PM
Sort files under a folder by created date Kunsheng Programming 3 05-11-2009 04:58 AM
bash sort files by date in file name thedude2010 Programming 6 05-12-2006 11:07 AM
How to sort files in a directory by date in KDE? Ace_Azzameen Linux - Software 7 05-24-2004 02:49 PM
Listing Files based on date axero Linux - Newbie 2 10-19-2003 04:58 PM


All times are GMT -5. The time now is 08:18 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration