The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Auto copy for files from folder to folder upon instant writing Bashar UNIX for Advanced & Expert Users 2 08-21-2008 02:44 PM
Moving Files from one folder to another folder farooqpervaiz Shell Programming and Scripting 10 08-07-2008 02:20 AM
Finding Hidden files and protecting the folder containing hidden files from deletion pochaw Shell Programming and Scripting 4 12-22-2007 01:33 AM
read files from folder and then call another script girishnn UNIX and Linux Applications 1 11-08-2007 09:52 PM
read files from folder and then call another script girishnn Shell Programming and Scripting 3 11-06-2007 06:53 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-11-2008
satish2712 satish2712 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 9
script for Finding files in a folder and copying to another folder

Hi all,

I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt.

I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file data1.txt and if found have to copy it to some other file. This has to continue for any number of files (like till data1000.txt).

Please provide some shell script to do the same.

Thanks,
  #2 (permalink)  
Old 09-11-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
find /some/path -iname "data*.txt" -exec cp \"{}\" /other/path
  #3 (permalink)  
Old 09-11-2008
satish2712 satish2712 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 9
Quote:
Originally Posted by redoubtable View Post
find /some/path -iname "data*.txt" -exec cp \"{}\" /other/path

Hi,

thanks for the reply.

If i do this, it will copy all the data*.txt files in /saome/path to /other/path right ?
  #4 (permalink)  
Old 09-11-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
Precisely.
  #5 (permalink)  
Old 09-11-2008
satish2712 satish2712 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 9
Quote:
Originally Posted by redoubtable View Post
Precisely.
My exact requirement is...

Step1: Find if data*.txt files exist in some/path
Step2: If exists, copy the first such file (ex: data0.txt) to other/path
Step3: remove the data0.txt
Step4: Repeat step1

Hope this makes things more clear. Sorry, if i was not very clear in the beginning.
  #6 (permalink)  
Old 09-11-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
Then you could just use 'mv' instead of 'cp':

find /some/path -iname "data*.txt" -exec mv \"{}\" /other/path \;
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0