script for Finding files in a folder and copying to another folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script for Finding files in a folder and copying to another folder
# 1  
Old 09-11-2008
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  
Old 09-11-2008
find /some/path -iname "data*.txt" -exec cp \"{}\" /other/path
# 3  
Old 09-11-2008
Quote:
Originally Posted by redoubtable
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  
Old 09-11-2008
Precisely.
# 5  
Old 09-11-2008
Quote:
Originally Posted by redoubtable
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. Smilie
# 6  
Old 09-11-2008
Then you could just use 'mv' instead of 'cp':

find /some/path -iname "data*.txt" -exec mv \"{}\" /other/path \;
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

3. Shell Programming and Scripting

Copying files from various folders to similar folder structure in another location

Hi, I need to write a script the has to copy the files from folders and subfolders to the same folder structure located in another location. Ex: mainfolder1 file1,file2,file3 subfolder1(file1,etc) subfolder2(file1,etc) to another folder location of same folder structure. rsync is not... (7 Replies)
Discussion started by: Raji Perumal
7 Replies

4. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

5. Shell Programming and Scripting

copying random Jpg files to different folder

Hi, I have 200 pictures in a folder and I would like move 10 random pictures every week to given folder automatically. I have this server on 1and1.com. So I tried the following using Bash script for manual copy and paste for testing #!/bin/bash mapfile -t -n 3 files < <(find... (13 Replies)
Discussion started by: raamkum
13 Replies

6. Shell Programming and Scripting

Bash folder manipulation - selecting/copying specified files

Bash/scripting newbie here - I feel this might be a trivial problem, but I'm not sure how to tackle it. I've got a folder of a year's worth of files, with some random number of files generated every day of the year (but at least one per day). I'm writing a script to automatically grab the file with... (6 Replies)
Discussion started by: WildGooseChased
6 Replies

7. OS X (Apple)

Automated command ; extracting files from folders and copying them into a single folder

Hello everyone, I'm running Mac OS X Leopard (10.5.8) and I want to use the Terminal to help automate this tedious and laborious command for me: I need to extract all of the .m4p files in my "iTunes Music" folder which reside in folders of the artist, and then subfolders for the albums and... (2 Replies)
Discussion started by: qcom
2 Replies

8. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

9. UNIX for Advanced & Expert Users

Auto copy for files from folder to folder upon instant writing

Hello all, I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written. I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Discussion started by: Bashar
2 Replies
Login or Register to Ask a Question