I have a directory which has a lot of header files(.h) and other .o and .c files and other files. This directory has many nested directories inside. I want to copy only header files to a separate directory preserving the same structure in the new directory.
cp -rf oldDirectory newDirectory
will copy all files.
I want to copy only header files.
If you want to also copy folders & subfolders from one location to another then you need to use -R option for recursive copying. Here is an example to copy all files & folders present in /home/ubuntu to /home/data Copying files & folders is a common task in system administration and it is always convenient to have a shell script for it.
The “ cp” command is one of the commonly used commands to perform the copy operation. You can copy files or folders from source to destination, i-e, one directory through this command. The syntax of the “ cp ” command is: $ cp [ options] [source …] [ destination…]
Press Ctrl + C keys together to copy the page. 5. Create a new Word document, and press Ctrl + V keys together to paste the page. And now you will see the specified page and its header and footer are copied to the target document at the same time.
The “ cp” command is one of the commonly used commands to perform the copy operation. You can copy files or folders from source to destination, i-e, one directory through this command.
(cd src && find . -name '*.h' -print | tar --create --files-from -) | (cd dst && tar xvfp -)
You can do something similar with cpio if you just want to hard link the files instead of copying them, but it's likely to require a little mv'ing afterward. If you have lots of data and don't mind (or need!) sharing, this can be much faster. It gets confused if dst needs to have a src in it - this is, if it isn't just a side effect:
this one worked for me:
rsync -avm --include='*.h' -f 'hide,! */' . /destination_dir
from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With