LinuxQuestions.org
Visit the LQ Articles and Editorials section
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-03-2005, 09:04 AM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 668
Blog Entries: 7

Rep: Reputation: 31
copy files from directory to directory without subfile


Hi there,
Is there any method in bash to do the following:
I want to copy all the file and subdirectories of a directory "exept" a directory called sub_abc.
Is this possible ??
 
Old 06-03-2005, 10:54 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

This should do the trick:

find /home/user -type d \! -path './*/sub_abc*' -exec cp -R {} /path/to/destination/ \;

Don't know how much experience you have with find, so here's a breakdown of the command.

/home/user : search starts here

-type d \! -path './*/sub_abc*' : return directories only (-type d) except (\!) if the path has sub_abc in it (-path './*/sub_abc*')

You will end up with all the dirs except the directory that is called sub_abc.

-exec cp -R {} /path/to/destination/ \;

This will exectue a cp -R. The found paths are put between {} the destination is /path/to/destination.

Don't forget the \;

A Few Notes:

Try the first part of the command before using the -exec part, especially if you're new to this stuff. Something like:

find /home/user -type d \! -path './*/sub_abc*' -exec echo "cp -R {} /path/to/destination/" \; will do nothing but show what it would do.

Or, simpler:

find . -type d \! -path './*/sub_abc*' prints what it finds.

Last edited by druuna; 06-03-2005 at 10:56 AM.
 
Old 06-03-2005, 11:51 AM   #3
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 668
Blog Entries: 7

Original Poster
Rep: Reputation: 31
I want to copy the file like in cp , isnt there a simpler method
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Copy files from multiple directories into one directory MadRabbit Linux - Newbie 8 02-07-2014 07:56 PM
need script to copy all files containing a certain string to a directory dc6463 Programming 21 04-18-2013 01:56 PM
How to copy an entire directory structure except certain files? thanhvn Programming 9 01-27-2012 11:41 AM
How do you copy hidden files from one directory to another? Akhran Linux - Newbie 19 12-29-2011 03:31 AM
copy 3 files to a directory and all subdirectories? snip128 Linux - Newbie 9 08-12-2005 09:18 PM


All times are GMT -5. The time now is 10:18 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration