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

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-04-2020, 12:00 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,514
Blog Entries: 11

Rep: Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473Reputation: 3473
See the --parents option to cp.
 
1 members found this post helpful.
  


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 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 07: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 10: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 08: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 03:20 AM
Copy Files / Folders & Preserve Data carlosinfl Red Hat 9 12-31-2010 01:13 PM

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

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