LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-21-2004, 12:54 AM   #1
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Rep: Reputation: 56
Command question


Hi folks,

If I have 2 folders/directories namely folder-A/directory-A and folder-B/directory-B

What will be the most convenient command (plus correct syntax) shall I use;

1) to copy all sub-folders/sub-directories including all files inside from folder-A/directory-A to folder-B/directory-B.

2) to copy all sub-folders/sub-directories only EXCLUDING all files inside from folder-A/directory-A to folder-B/directory-B

3) only to copy the FIRST and SECOND levels of the sub-folders/sub-directories, i.e. the sub-folders/sub-directory immediate under folder-A/directory-A and their immediate sub-folders/sub-directories, EXCLUDING all files inside.

Kinldy advise. TIA

B.R.
satimis
 
Old 06-21-2004, 05:01 AM   #2
LinuxLala
Senior Member
 
Registered: Aug 2003
Location: New Delhi, India
Distribution: Fedora 7
Posts: 1,305

Rep: Reputation: 45
1) to copy all sub-folders/sub-directories including all files inside from folder-A/directory-A to folder-B/directory-B.

cp folder-A/directory-A/ folder-B/directory-B/ -r

I am not too sure about the other two parts. I don't know if excluding all files under a location is possible.
 
Old 06-21-2004, 06:55 AM   #3
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Hi LinuxLala,

Tks for your advice.

What I am trying to find is a combination of commands to do the jobs.

(Remark:
Previously I meant Folder-A=User-A and Folder-B=User-B
Acturally I need to create the exact set of folders and sub-folders to User-B, User-C, etc. same as User-A)

Currently I apply 'cp' and 'mc' to do the jobs as listed in my first posting as follows;

Using 'mc' to copy all folders, sub-folders and files from User-A to User-B, then removing all files. Afterwards using 'mc' again to copy all folders and sub-folders from User-B to User-C, User-D etc.

I have been searching on Internet with google but up to now still I have not found a solution.

B.R.
satimis
 
Old 06-21-2004, 12:25 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
If I understand you correctly, you want to copy the directory structure with no files. right ?????

If so, you could use this command:
Code:
cd /home/user1
find . -type d -name '*' \
-exec mkdir -p /home/user2/{} \;

Last edited by homey; 06-21-2004 at 12:28 PM.
 
Old 06-21-2004, 12:56 PM   #5
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Hi homey,

Tks for your advice.

Quote:
... you want to copy the directory structure with no files. right ?????
Yes. You are correct. I want to copy the complete directory structure including all sub-directories but without file.

Code:
cd /home/user1
find . -type d -name '*' \
-exec mkdir -p /home/user2/{} \;
Are line-2 and line-3 above a single line (i.e. ONE LINE)

Furthermore if I want to copy selected level of sub-directories. Can I make it and how?

TIA

B.R.
satimis
 
Old 06-21-2004, 01:34 PM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Hi,

Lines 2 and 3 are all one line of command. It just looks neater to break it in half with a " \ '

The -type d says that I'm only interested in directories.

This command does create the subdirectories by using mkdir -p . The -p switch tells mkdir to make any parent directories if they don't already exist.

If you only want to go to a certian level of sub-directories, use the -maxdepth command. For example to go down 4 levels should look like this...

cd /home/user1
find . -maxdepth 4 -type d -name '*' -exec mkdir -p /home/user2/{} \;

Last edited by homey; 06-21-2004 at 01:42 PM.
 
Old 06-21-2004, 10:03 PM   #7
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Hi homey,

Lot of thanks for your advice which is very interesting to me.

I thnk I should spare some time learning C++ and Bash/Shell script languages

If I save
Code:
cd /home/user1
find . -type d -name '*' \
-exec mkdir -p /home/user2/{} \;
to a file namely "cpdir" and want to make it executable

1) what will be the file extention '.sh' or '.exe'
2) where shall I save it? '/bin/'?
3) how to activate it so that it can be executed by typing "cpdir + ENTER" on Konsole window? With 'chown'?
4) how to make 'user2' variable for 'user2','user3', 'user4', 'userX', etc. so that I am allowed to copy the directory structure to either 'user2', 'user3' or 'user4' individually. Similarly I am also allowed to copy the directory structure to 'user2', 'user3', 'user4', etc.collectively.

TIA

B.R.
satimis
 
Old 06-21-2004, 10:52 PM   #8
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
There is a niffty tool called dialog but I haven't actually created any scripts using this.
You may have better luck with good advice down at the program section.
 
Old 06-23-2004, 02:43 AM   #9
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Quote:
Originally posted by homey
There is a niffty tool called dialog but I haven't actually created any scripts using this.
You may have better luck with good advice down at the program section.
Hi homey,

Noted with thanks

B.R.
satimis
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question About a Command? carlosinfl Linux - General 4 10-28-2005 12:51 PM
mt command question Ayman.mashal Linux - General 3 06-17-2005 05:19 AM
Command question satimis Linux - Newbie 2 11-24-2004 08:59 AM
cp command question satimis Linux - Newbie 1 09-13-2003 08:31 PM
Command Question gauge73 Linux - Newbie 2 02-13-2003 08:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration