Move files into different folders based on its month | Unix Linux Forums | Solaris

  Go Back    


Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Move files into different folders based on its month

Solaris


Tags
script from ksh, solaris 10

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-04-2012
velava velava is offline
Registered User
 
Join Date: Jun 2010
Last Activity: 10 November 2012, 5:43 AM EST
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
Java Move files into different folders based on its month

Hi All,

I want to move the files in to different folders based on the files month in the file timestamp.

For example

All the september files in the directory should moves into the folder "sep_bkp_files" , August files in to aug_bkp_files folder...

Please help me to achive the above issue. I am using solaris OS.

Thanks,
Velava
Sponsored Links
    #2  
Old 10-04-2012
itkamaraj's Avatar
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 3 October 2014, 8:50 AM EDT
Posts: 3,059
Thanks: 33
Thanked 659 Times in 638 Posts
post the output of ls -lrt

or is the filename having the timestamp ?
Sponsored Links
    #3  
Old 10-04-2012
velava velava is offline
Registered User
 
Join Date: Jun 2010
Last Activity: 10 November 2012, 5:43 AM EST
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by itkamaraj View Post
post the output of ls -lrt

or is the filename having the timestamp ?

Yes, the fiename having the timestamp.
    #4  
Old 10-04-2012
itkamaraj's Avatar
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 3 October 2014, 8:50 AM EDT
Posts: 3,059
Thanks: 33
Thanked 659 Times in 638 Posts
if u provide the example filename, then i can help u
Sponsored Links
    #5  
Old 10-04-2012
velava velava is offline
Registered User
 
Join Date: Jun 2010
Last Activity: 10 November 2012, 5:43 AM EST
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by itkamaraj View Post
if u provide the example filename, then i can help u

filenames will be,

-rw-rw-r-- 1 b2binta1 b2badmin 16515066 Sep 18 00:57 test1.txt
-rw-rw-r-- 1 b2binta1 b2badmin 22824 Sep 18 01:30 test2.txt
-rw-rw-r-- 1 b2binta1 b2badmin 41844 Sep 18 01:30 test3.txt
-rw-rw-r-- 1 b2binta1 b2badmin 22824 Sep 18 01:36 sample1.txt
-rw-rw-r-- 1 b2binta1 b2badmin 213024 Sep 18 01:36 sample2.txt
-rw-rw-r-- 1 b2binta1 b2badmin 60864 Sep 18 04:34 hello.csv

Thanks
Sponsored Links
    #6  
Old 10-04-2012
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 25 October 2014, 4:18 AM EDT
Location: NM
Posts: 10,251
Thanks: 283
Thanked 803 Times in 747 Posts

Code:
dest=/path/to/september/
touch -t 201209010000 /tmp/d1
touch -t 201209305959 /tmp/d2
find /path/to/files -type f |
while read fname
do
     mv $fname $dest
done

try that.
Sponsored Links
    #7  
Old 10-04-2012
velava velava is offline
Registered User
 
Join Date: Jun 2010
Last Activity: 10 November 2012, 5:43 AM EST
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by jim mcnamara View Post
Code:
dest=/path/to/september/
touch -t 201209010000 /tmp/d1
touch -t 201209305959 /tmp/d2
find /path/to/files -type f |
while read fname
do
     mv $fname $dest
done

try that.
based on the month present in the file time stamp i have to move its respective folders.

it is not working as expected and it is moving all other month files as well.

Thanks
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Move files to Folders diva_thilak Shell Programming and Scripting 5 07-23-2009 01:53 AM
Move folders containing certain files xavix UNIX for Dummies Questions & Answers 3 02-21-2009 05:43 AM
How do you move lines of numbers based on the month terryporter51 Shell Programming and Scripting 11 06-15-2008 12:54 AM
how to move files into different folders based on filename italia5 UNIX for Dummies Questions & Answers 7 08-23-2006 10:04 AM



All times are GMT -4. The time now is 04:37 PM.