D
D
Damian Lewis2021-09-06 00:25:36
linux
Damian Lewis, 2021-09-06 00:25:36

Creating folders when copying recursively with cp command in terminal?

When copying a folder with the cp command, how do I make it automatically create folders at the destination I specified? Let me explain with an example:
There is such a command cp -r ~/Local/Test/* ~/Документы/Разные/2021/04/
of Folders Miscellaneous/2021/04/ not at all and I would like them to be created right during copying. So that I do not enter, writes:

cp: cannot create directory '~/Документы/Разные/2021/04': No such file or directory

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Karabanov, 2021-09-06
@DamianLewis

Add to ~/.bashrc

mkcp() {
    test -d "${@: -1}" || mkdir -p "${@: -1}"
    cp "[email protected]"
}

Restart bash
Runmkcp -r ~/Local/Test/* ~/Документы/Разные/2021/04/

A
Alexey Yarkov, 2021-09-06
@yarkov

cp -vaR ./from ./to
Checked on a smartphone - it works.
61353a941ec60891628815.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question