LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-08-2017, 05:31 PM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,433

Rep: Reputation: 110Reputation: 110
Copying files and their entire directory structure


Assuming something like this:

/usr/bin
/usr/bin/ffmpeg
/usr/share
/usr/share/doc
/usr/share/doc/ffmpeg
/usr/share/doc/ffmpeg/changelog.gz
/usr/share/doc/ffmpeg/copyright
/usr/share/ffmpeg
/usr/share/ffmpeg/examples
/usr/share/ffmpeg/examples/Makefile

I want to copy everything, files and entire structures, but not the entire content of directories. I just want the directories and the files that are listed, specifically.

How?
 
Old 07-08-2017, 06:02 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
One easy way with an arbitrary list of files (i.e. not a patterend selection) would be to copy the target files using cp with the --parents option.

Code:
cp --parents /usr/bin/ffmpeg \
more_files_here...  destination/
See man cp as always.
 
2 members found this post helpful.
Old 07-08-2017, 06:08 PM   #3
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,433

Original Poster
Rep: Reputation: 110Reputation: 110
Yes, that worked. Thank you.
 
Old 07-08-2017, 06:22 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Glad to help.

If this resolved your question please mark this threas as solved using the Thread Tools at top of first post.

** You beat me to the SOLVED button!

Last edited by astrogeek; 07-08-2017 at 06:24 PM.
 
Old 07-08-2017, 07:27 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by lucmove View Post
Yes, that worked. Thank you.
man cp has worked for years.
 
Old 07-08-2017, 07:44 PM   #6
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,433

Original Poster
Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by Habitual View Post
man cp has worked for years.
Well, that was quite unexpected to me. I expected to find it in 'man rsync' but I didn't, so...
 
Old 07-09-2017, 06:40 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
It might be a GNU-extension. With standard tools:
Code:
(cd from; tar -cf - filelistwithrelativepath)|\
(cd to; tar -xf -)
 
1 members found this post helpful.
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can't preserve directory structure when copying files andrew.comly Linux - Server 10 12-14-2015 08:01 PM
How to copy an entire directory structure except certain files? thanhvn Programming 9 01-27-2012 11:41 AM
Problem in copying directory structure agogoaye Linux - Newbie 9 07-02-2008 04:44 AM
Copying entire directory with subdirectory? centosfan Linux - Newbie 1 04-20-2007 09:14 PM
xgettext: How to parse entire directory structure (dirs/subdirs) Muffe Linux - Software 1 04-28-2006 09:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:04 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