473,385 Members | 2,005 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,385 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 5633
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.