DEV Community

Cover image for How to copy/paste files/directories into non-existent destination path
darker
darker

Posted on

2 1

How to copy/paste files/directories into non-existent destination path

Have you ever tried to copy some file(s) or directory(ies) to a destination that doesn't exist yet ? It's possible with a smart bash function !

How doe's it work

HOW ?

How to obtain that ?
Using this bash script function :

cpd(){
    mkdir -p "$(dirname ${@: -1})"
    cp -r $@
}
Enter fullscreen mode Exit fullscreen mode
  • First, we create recursively the destination folder by getting the dir name of the last argument passed to the function.
  • And we copy recursively depending on the array of arguments passed to the function.

As the final step, You just have to add it in your .bashrc, source ~/.bashrc and you're good to go !

DEMO ?

Demo

Thanks for reading, feel free to like and/or subscribe for more 🐼.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more