• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

46
Views
How to search (using find command) for directories and copy all the files and directory itself to another directory in linux?

How to search (using find command) for directories and copy all the files and directory itself to another directory in linux? Here is what I have so far:

find -type d -name "*.ABC" -exec {} /Desktop/NewFile \;

I get this as output:

find: './GAE/.ABC: PERMISSION DENIED

Please Help, Thanks!

4 months ago ·

Santiago Trujillo

2 answers
Answer question

0

Your error here above has nothing to do with file read permission. You're trying to execute the directories you find! Avoid running commands as root or sudo unless: (1) you really need it and (2) you really know what you're doing. Quite often people asking for root or sudo privileges are exactly the ones should not have it.

That said... there are several ways to copy a directory tree under *nix. This is just one possible approach:

$ find <start> -type d -name \*.ABC -exec cp -av {} <target> \;

Where:

  • <start> is a directory name. It's used to tell find where to start its search (for example /usr/local or $HOME)
  • <target> is another directory name to define the final destination of your copied directories

UPDATE

In case you want to search for multiple paths...

$ find <start> -type d \( -name \*.ABC -o -name \*.DEF \) -exec cp -av {} <target> \;
4 months ago · Santiago Trujillo Report

0

This should work:

find ./source_dir -name \*.png -print0 | xargs -0 cp -t path/to/destination

For more info, you can look up here.

4 months ago · Santiago Trujillo Report
Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.