I have a directory ~/plugins/
and inside there are many sub-directories. If I wanted to create a backup somewhere else of just the sub-directories starting with abc
could I do that with a one line copy command? I would assume something like this would work (but it doesn't):
cp -R ~/plugins/abc* ~/destination/
I would rather use a one-line command, if possible, because I would also like to use the same syntax for rsync, and if I have to do something like
find ~/plugins/ -type d -name "abc*" -exec cp -R {} ~/destination;
then that works fine for the cp
command but it would mean that I would have to run rsync once for each directory and that just doesn't seem efficient :(
To copy files or directories in Unix-based operating systems (Linux and MacOS), you use the cp command. The cp command is a relatively simple command, but its behavior changes slightly depending on the inputs (files vs directories) and the options you pass to it.
In order to copy the content of a directory recursively, you have to use the “cp” command with the “-R” option and specify the source directory followed by a wildcard character.
Copying Directories with cp Command To copy a directory, including all its files and subdirectories, use the -R or -r option. The command above creates the destination directory and recursively copy all files and subdirectories from the source to the destination directory.
Not sure why what you're trying didn't work (but what is the "copy" command?), but this works on Linux at least:
cp -r ~/plugins/abc* ~/destination
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