Linux copy directory without using cp -r or any variant

Hi guys,

I need a solution to copy files and folders without using cp-r , cp-R or any variants. So i need to code it manually. I allready have a loop

Avans Highschool Breda the Netherlands

#!bin/bash

IFS=$'\n'

if test "$1" = "" 
then
        wd=pwd
else
        wd=$1 
fi

for file in $(find $1)
do    
        if [ -f $file ]; then
                cp $file ~/Desktop 
        elif [ -d $file ]; then
                 #copy directory,subdirectory and files wihtout
                 #using cp-r, cp-R or any variant
        fi
done

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

In this case, please edit your post to include the completely filled out template that is required for all homework an coursework forum submissions.

Thank You.

The UNIX and Linux Forums.

i did use the homework criteria

Its not the criteria, it filling in the template...

That said, my only advice I would give now is that you test cases:
What will you do when you meet a directory ? what will cp do?

You cant use cp -Rr... but what about other commands? What is /is not allowed?

This is a special forum, where we will NOT provide solutions but guidelines or help you find your solution, you are the one having to do the work, we assist...

You have find that does the recursion already.
So you can do the plain cp and mkdir commands.
Man pages help you

man cp
...
man mkdir
...

The only reason I can think of not to use cp is because it has been deleted or moved. I speak from experience of a production system where a change tried to move / and it's contents into a subdirectory. :eek: It got quite a long way down too, moving /dev amongst other things which made new login impossible even on the console.

Can you explain why you need such an odd thing? It might illicit better responses.

Robin

He is allowed to use cp, he is not allowed to use cp -r. The assignment is an exercise in recursion.

I suspect he shouldn't be using find either then, since it also does recursion for him!

In any case, Wolverine89, you have not filled out the homework template after being instructed to do so several times. This thread is closed. If you open another topic, it will also be closed unless you fill out the template!

It is the only way that we're allowed to help homework.

No sir, you have not. Earlier I provided the link: Rules for Homework & Coursework Questions Forum

If you followed that link, you would have seen something similar to the following. Note that the template includes four items. You have provided the 3rd item in the template. You have provided part of the 1st item in the template. You have not provided anything for the 2nd and 4th items in the template. If you refuse to fill out the template completely, you will be banned from this site.

Homework Help:

On Posting Questions:

Any and all high school and undergraduate homework assignments or textbook style exercises for which you are seeking assistance are to be posted only in our Homework & Coursework Questions area--not in blogs, visitor messages, PMs, or the main technical forums.

This should be done whether the problem is part of one's assigned coursework or just independent study. The reason for this is that the main sections of The UNIX and Linux Forums are to be reserved for work-related discussions and not academic assistance.

Since graduate level assignments are meant to be more thought provoking (and hence more worthy of discussion), graduate level questions will be allowed in the relevant part of the main section of The UNIX and Linux Forums, provided that the graduate student attempts the problem and shows his work.

NOTES:

  1. You MUST show that you have attempted to answer your question in order to receive help.
  2. You MUST make use of the homework template, which automatically appears when a new topic is created in the homework help forums.

References. You Must Reference Any Help You Receive From Here:

Students must reference the The UNIX and Linux Forums as one of their sources of help if they make use of information obtained through the forum. In other words, if you get any help from our forums then you should acknowledge that fact when you write up your report and provide the URL to the thread.

We Do Not Support Cheating in Any Form:

Do not ask for solution manuals, answers to exams, or instructor's manuals. Every school and instructor has their own policies or honor codes on what constitutes cheating, and it is up to the individual student to adhere to those policies when seeking help here. If you are in doubt as to whether you are permitted to seek help, consider erring on the side of caution and not asking for help.

Any and all assistance given to homework assignments or textbook style exercises should be given only after the questioner has shown some effort in solving the problem. If no attempt is made then the questioner should be asked to provide one before any assistance is given. Under no circumstances should complete solutions be provided to a questioner, whether or not an attempt has been made.

Required Format and Template for Homework & Coursework Questions:

The template below will be provided automatically when you create a new thread in the Homework & Classwork Forum. You must complete this template. If you don't, your post may be closed or deleted.

Contract Cheating:

Never contact any member of The UNIX and Linux Forums with any paid offer to do any homework or coursework for you. Contract cheating is strictly forbidden here. Anyone who attempts to engage in any form of contract cheating here will be banned from this site. In addition, your login information and activity may by provided to your school, if requested. Do not even think about it.

Standard Forum Rules:

All standard forum rules apply to questions in the Homework & Coursework Questions forum. Make sure you are familiar with the standard forum rules and well as the special rules for students.

Please Note: If you post homework or coursework without complete school/city/country/professor/course information, you will be banned! Also, members who answer homework or coursework questions (assist students) that post without complete school/city/country/professor/course information will be given infractions. This complete information is mandatory.