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 ?
How to obtain that ?
Using this bash script function :
cpd(){
mkdir -p "$(dirname ${@: -1})"
cp -r $@
}
- 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](https://res.cloudinary.com/practicaldev/image/fetch/s--1ShXbFHX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wi18vln6ol2yxuqa9mp9.gif)
Thanks for reading, feel free to like and/or subscribe for more 🐼.
Top comments (0)