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 🐼.

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay