473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

copy directories and files recursively using C shell or bash shell

Hi all,
I am trying to copy couple of directories and their files to another place. Each directory have 25-30 files and numbered accordingly, the problem I am facing is, I have to copy files numbered from 4-22 only and leave rest all.
I have written a code but its only copying one directory and its files and not others.
Overall /test1/step_1/prodinit_1....30 and I want to copy to /test2/step_1/prodinit_4...22
Expand|Select|Wrap|Line Numbers
  1. #!/bin/csh -f
  2.  
  3. set dir1 = /home/rr/copy/test1
  4. set dir2 = /home/rr/copy/test2
  5.  
  6. set step = 1
  7. set stepmax = 30
  8. set num  = 4
  9. set nummax = 22
  10.  
  11.     mkdir $dir2/step_${step}
  12.     echo $dir2/step_${step}
  13.  
  14. while ($step < 30)
  15.    cd $dir2/step_${step}
  16.    cp -r $dir1/step_${step}/prodinit_${num}*.* $dir2/step_${step}
  17.    echo "Copying file .."
  18.    @ num = ${num} + 1
  19.    if ($num == $nummax ) exit
  20.    cd ..
  21. end
  22.  
I am new to shell programming and any help will be appreciated.

Thanks
Kumar
Jun 5 '08 #1
1 5634
gpraghuram
1,275 Expert 1GB
You can make use of for and while loop for this

Expand|Select|Wrap|Line Numbers
  1. DIR="dir1 dir2 dir3 ..."
  2. dest_dir="directory u need"
  3. for dir in $DIR
  4. do
  5.    $i=4
  6.    while [ $i -lt 30 ]
  7.    do
  8.        cp $d/$i".txt" $dest
  9.        $i=`expr $i + 1`
  10.    done
  11. done
  12.  
Start with this pseudo code

Raghu
Jun 6 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Kay Lee | last post by:
Hi, I looked up os module to find out some method to move and copy files in python, but os doesn't support such methods. Is there any way to move & copy files in python? Thanks in adv.
2
by: Phil Healey | last post by:
Here goes: I looked all over the place, and I think I'm still too far down on the "steep part of the learning curve" to figure this out. When writing perl scripts, I touch the filename and then...
1
by: Trinity | last post by:
Hi, I want to delete a particular file in all the sub-directories. I am using the SHFileOperation() API. But it is not deleting the files recursively. Any sample code is appreciated. TIA
1
by: Antonio Lopez Arredondo | last post by:
hi all !!! I need to copy a folder and its subfolders to another location; which class should I use ? could only find the System.IO.Directory.MOVE but don't know how to COPY. thanks in...
5
by: rbt | last post by:
What is the most efficient way to recursively remove files and directories? Currently, I'm using os.walk() to unlink any files present, then I call os.walk() again with the topdown=False option...
3
by: Kamen TOMOV | last post by:
Hi, Is uploading recursively directories to a web server possible with JavaScript? I mean is it possible read a directory recursively and dynamically construct <input type="file"> with value...
16
by: John Salerno | last post by:
Hi all. I just installed Ubuntu and I'm learning how to use the bash shell. Aside from the normal commands you can use, I was wondering if it's possible to use Python from the terminal instead of...
9
by: bhumikas | last post by:
Hi all, I need a help in perl script.The basic idea is,it must have command line arguments for the user flexibility.the files are in the format as shown below. MainFolder Directory ...
3
by: usman | last post by:
Hi I have a windows service that backups a folder onto another location on the same computer. The service is written in C#. The size of the original folder is large i.e. over 8 GB. Also the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.