Move files into different folders based on its month - Page 2 | 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
    #8  
Old 10-04-2012
elixir_sinari's Avatar
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 9 October 2014, 4:50 PM EDT
Location: India
Posts: 1,412
Thanks: 101
Thanked 496 Times in 473 Posts
May be Jim missed something...

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

Sponsored Links
    #9  
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
Thanks elixir!

It is working fine for the september files. I need to move the other month files also needs to be moved to the respective folders.

Please help me to do this.

---------- Post updated at 09:03 AM ---------- Previous update was at 08:59 AM ----------

Quote:
Originally Posted by elixir_sinari View Post
May be Jim missed something...

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

I have an idea like first we have to find the list of files from the directory. then we have to get the month of the file using awk {print $6} and based on the month we have to move our files.

pls help me such a way to resolve this issue. Thanks!
Sponsored Links
    #10  
Old 10-05-2012
itkamaraj's Avatar
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 14 November 2014, 7:56 AM EST
Posts: 3,059
Thanks: 33
Thanked 659 Times in 638 Posts

Code:
ls -lrt | awk -v '/^\-/{print $6,$NF}' | while read month filename
do
        mkdirp -p /full/path/${month}_bkp_files
        mv ${filename} /full/path/${month}_bkp_files
done

    #11  
Old 10-05-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
Code:
ls -lrt | awk -v '/^\-/{print $6,$NF}' | while read month filename
do
        mkdirp -p /full/path/${month}_bkp_files
        mv ${filename} /full/path/${month}_bkp_files
done

Thanks!

mv: cannot stat 'test.edi': No such file or directory

getting the above error
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 02:53 AM
Move folders containing certain files xavix UNIX for Dummies Questions & Answers 3 02-21-2009 06:43 AM
How do you move lines of numbers based on the month terryporter51 Shell Programming and Scripting 11 06-15-2008 01:54 AM
how to move files into different folders based on filename italia5 UNIX for Dummies Questions & Answers 7 08-23-2006 11:04 AM



All times are GMT -4. The time now is 11:41 PM.