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 12-12-2013, 02:28 AM   #1
dirtyrobinson
LQ Newbie
 
Registered: Dec 2013
Posts: 6

Rep: Reputation: Disabled
Copy directory - exclude files/folders


Hi,

I saw a couple of threads regarding copying directories and excluding files/folders but they weren't 100% what I was looking for.

I have a directory that I want to copy on an ARM device but I can't add programs to the filesystem so I'm reduced to find/cp. I want to exclude the /mnt directory completely but I also wanted to exclude any file/folder that has mmc in it since I'm copying these files to an sd card. I tried cp on the whole directory but it just endlessly copies the mmc/sd insert & tmp files so it never completes the cp process.

find (directory to search) (exclude files/folders) cp (everything else to sd card)

Thanks,
Jason
 
Old 12-12-2013, 03:02 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Just to make sure: You can only use cp and find? Using mkdir is out of the question?

If mkdir can be used, have a look at this:
Code:
find / -type d ! \( -name "mnt" -prune -o -name "mmc" -prune \) -exec mkdir -p "/new_location/"{} \;
The search starts at the root directory (/),
The -type d only targets directories,
The ! \( -name "mnt" -prune -o -name "mmc" -prune \) excludes directories named mnt and mmc (including sub-directories),
The -exec mkdir -p "/new_location/"{} \; creates the found directories in the /new_location/ directory.

To test what is found: Remove the brown part.
 
1 members found this post helpful.
Old 12-12-2013, 03:17 AM   #3
dirtyrobinson
LQ Newbie
 
Registered: Dec 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thank you Druuna,

I did a test using new folders renamed to mnt/mmc and it copied everything but those folders. Also, yes I can use mkdir. I just saw the most common ways of doing this were using compression programs like gzip, rsync, and find/cp so thats why I said I only had those, I should have elaborated that better.

I also struggled to find a noob description of what each part of the command does so I really thank you for the description! I read quite a few helps about this way of copying but they didn't really make sense to me.
 
Old 12-12-2013, 05:23 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome.

BTW: Can you put up the [SOLVED] tag if this is answered to your satisfaction.
- above the first post -> Please Mark this thread as solved if you feel a solution has been provided.
- -or- -
- first post -> Thread Tools -> Mark this thread as solved
 
  


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
using rsync to copy only certain folders within a directory structure Ryanjon7 Programming 5 06-20-2011 02:34 PM
[SOLVED] Rsync exclude a directory with all subdirectories and files Slackovado Slackware 1 12-26-2010 11:40 PM
Can we use exclude option in"rm" command to exclude some files/folders? yadav_rk727 Linux - Newbie 1 02-03-2010 10:14 AM
Subversion: exclude certain files or folders Ephracis Linux - Software 1 03-01-2008 03:58 PM
How can I copy hidden home directory configuration files and folders? rm_-rf_windows Linux - General 3 06-29-2007 05:26 AM

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

All times are GMT -5. The time now is 11:15 PM.

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