LinuxQuestions.org
Visit Jeremy's Blog.
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 10-03-2020, 08:49 PM   #1
voncloft
Member
 
Registered: Mar 2019
Posts: 57

Rep: Reputation: Disabled
Question How do I copy folders with a file in them that has a grep pattern and preserve the folder structure


Basically I want to grep for the word "KDE" in /usr/ports/core and if a file in a subfolder matches I want to copy the folder with the files in it to another folder.

the command: grep -inrl "kde" /usr/ports/core | xargs cp -rv -p /Voncloft-OS/KDE

is almost working but not quite it moves the files to /Voncloft-OS/KDE

....but not the folder structure.

Thanks.
 
Old 10-03-2020, 11:00 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: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
See the --parents option to cp.
 
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] Copy files to a usb stick and automatically encrypt or encrypt files/folders and copy them to usb bmxakias Programming 8 03-14-2020 06:44 PM
find the pattern in a file where both pattern and file have differnt number of lines and space wedtorque Linux - Newbie 2 05-31-2017 09:02 AM
How to Upgrade Redhat 3 to Redhat 5 and preserve data and file system structure J_U_D_E Red Hat 10 03-15-2012 07:58 AM
[SOLVED] Using terminal command -Find files in a folder and copy them to a different folder j-jock Linux - General 4 11-28-2011 02:20 AM
Copy Files / Folders & Preserve Data carlosinfl Red Hat 9 12-31-2010 12:13 PM

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

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