Linux copy directory without using cp -r or any variant

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Linux copy directory without using cp -r or any variant
# 1  
Old 03-14-2014
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

Code:
#!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

# 2  
Old 03-14-2014
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 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.
# 3  
Old 03-14-2014
i did use the homework criteria
# 4  
Old 03-14-2014
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...

Last edited by vbe; 03-14-2014 at 01:18 PM.. Reason: typo missinf t can->cant use...
# 5  
Old 03-14-2014
You have find that does the recursion already.
So you can do the plain cp and mkdir commands.
Man pages help you
Code:
man cp
...
man mkdir
...

# 6  
Old 03-14-2014
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. Smilie 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
# 7  
Old 03-14-2014
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.

Last edited by Corona688; 03-14-2014 at 02:12 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Debian

Which older version and variant ISO image should I use?

Which older version and variant of Debian Linux ISO image should I use? I attempted to install two versions of Debian Linux Operating System onto my older full tower computer. First version, V8.5.0, Amd64, xfce, 32Bit. Second version V7.11.0, i386, 32Bit. When trying to install... (1 Reply)
Discussion started by: Jefferyab6
1 Replies

2. Post Here to Contact Site Administrators and Moderators

How to count successfully copy files source to target location with check directory in Linux?

Hi guys...please any one help me .... how to copy files from source to target location if 5 files copied successfully out of 10 files then implement success=10 and if remaining 5 files not copied successfully then count error=5 how to implement this condition with in loop i need code linux... (0 Replies)
Discussion started by: sravanreddy
0 Replies

3. Shell Programming and Scripting

Copy the files in directory and sub folders as it is to another directory.

How to copy files from one directory to another directory with the subfolders copied. If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*. I do not want to create sub folders in folder2. Can copy command create them automatically? I tried cp -a and cp -R but did... (4 Replies)
Discussion started by: santosh2626
4 Replies

4. Shell Programming and Scripting

how to copy the directory but not copy certain file

Hi experts cp bin root src /mnt but not copy bin/bigfile any help? ( I post this thread in the "redhat" forum wrongly, I don't know how to withdraw that question in that wrong forum) Thanks (6 Replies)
Discussion started by: yanglei_fage
6 Replies

5. Linux

BSD Variant of ar (The Archiver)

A while back I posted about trying to find the BSD version of ar (The Archiver): https://www.unix.com/linux/136258-where-can-i-find-ar-archiver-bsd-variant.html I was given a link to the source, found here: ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/ar-20080302.tgz I recently was able... (0 Replies)
Discussion started by: Deluge
0 Replies

6. UNIX for Dummies Questions & Answers

Copy directory from Linux to Windows

Hola a todos, soy realmente nuevo programando en bash, y aśn estoy encontrando bastantes baches :o, mi pregunta es simple, supongo, alguien podria decirme si existe una manera facil de copiar un directorio de un server a otro?, sucede que en un server(server1) tengo los backup de las bases de... (7 Replies)
Discussion started by: yeestrada
7 Replies

7. Shell Programming and Scripting

Copy Last modified directory to another directory

Hi, I have to copy last modified Directory to another directory.How can i Do using pipe or redirect cp -R 'ls -lrt|tail -1' test is not working. please help. (3 Replies)
Discussion started by: shaveta
3 Replies

8. Linux

Where Can I Find the ar Archiver BSD Variant

I've been trying to get my hands on the source for the BSD variant of the ar archiver, but have not been able to find it anywhere. Does anyone know where I can get it? (3 Replies)
Discussion started by: Deluge
3 Replies

9. UNIX Desktop Questions & Answers

Please help - System V Release 4 Variant

Sorry for this newbie question, but what exactly is Unix system V release 4 variant, and where do I download or buy this edition? There is alot of Unix info on the web, but the specifics can be a bit diverse. sorry (1 Reply)
Discussion started by: tropophyte
1 Replies
Login or Register to Ask a Question