Create folder by script & move files in it | Unix Linux Forums | Linux

  Go Back    


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

Create folder by script & move files in it

Linux


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-28-2011
paragnehete paragnehete is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 19 May 2014, 11:31 PM EDT
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
Create folder by script & move files in it

Hi Team,

I have over 1 lakh pdf files.

I want to create folders like Disk-1, Disk-2 ..... & want to move 3000 pdfs per folder. Can i do it by script? Please help me.

Thanks & Regards
Parag Nehete
Sponsored Links
    #2  
Old 10-28-2011
amitranjansahu's Avatar
amitranjansahu amitranjansahu is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 6 February 2014, 9:06 AM EST
Location: Bangalore,INDIA
Posts: 507
Thanks: 4
Thanked 27 Times in 27 Posts
Yes it can be done . First try out yourself . The logic is in script is first try to creat the Folder "DISK1" here the number can be a variablke and after transfering the 3000 file increase the variable by 1.
say

PHP Code:
# start with a loop to check if the files are still remaining to be transfered 
dn=1
 
mkdir DISK$dn
 
i
=1
while [ $i -le 3000 ];do 
# here your logic to move the files to the DISK folder
i=$(( $i ))
done 
Sponsored Links
    #3  
Old 10-28-2011
jayan_jay's Avatar
jayan_jay jayan_jay is offline Forum Advisor  
Forum Advisor
 
Join Date: Jul 2008
Last Activity: 21 April 2014, 7:19 AM EDT
Posts: 833
Thanks: 9
Thanked 185 Times in 176 Posts

Code:
#!/bin/bash
pdf_path='/your/pdf/files/full/path'
find $pdf_path -type f -name "*.pdf" -print > filecon
split -3000 filecon
disk=1
for i in x*
do
        mkdir $pdf_path/Disk-$disk
        nawk -F/ 'BEGIN{OFS="/"} {print "mv "$0; $NF=""; print}' $i | paste - - | nawk -v diskno="Disk-$disk" '{print $0diskno}' | sh
        disk=`expr $disk + 1`
done

    #4  
Old 10-29-2011
mark54g mark54g is offline Forum Advisor  
Registered User
 
Join Date: May 2008
Last Activity: 26 July 2013, 11:43 AM EDT
Location: Northeastern United States
Posts: 918
Thanks: 1
Thanked 61 Times in 58 Posts
And just what is a lakh?
Sponsored Links
    #5  
Old 10-29-2011
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 21 October 2014, 8:20 AM EDT
Location: Foxborough, MA
Posts: 7,667
Thanks: 152
Thanked 586 Times in 551 Posts
Quote:
Originally Posted by mark54g View Post
And just what is a lakh?
And the winner is.... Lakh.
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 only files to a folder brnl_basu Shell Programming and Scripting 4 06-23-2011 04:40 AM
Script to move files with similar names to folder glev2005 Shell Programming and Scripting 7 04-01-2011 09:42 AM
Move files & folder structure SOCLA_CELT Shell Programming and Scripting 3 08-26-2010 06:47 PM
move files to some folder learnbash Shell Programming and Scripting 2 07-20-2010 04:37 AM
move files from folder thats are not empty Steven UNIX for Dummies Questions & Answers 8 11-21-2001 09:05 AM



All times are GMT -4. The time now is 11:10 AM.