Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to cp a file to another directory but that directory doesn't exist yet.

So I would do:

mkdir /new_place
cp the_file /new_place

Can I do this in one?
I imagine something like cp the_file -m /new_place if "m" stood for "make dir's that don't exist"

Would this be a chance to use scp, rsync or another copying utility?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

With --parents you can recreate the directories from the source to the destination. For example:

cp --parents ~/Downloads/test.txt ~/Desktop/

Will create the subdirectories /home/desgua/Download/ inside my ~/Desktop folder and then copy test.txt.

share|improve this answer

You can do this with the following command

# rsync --recursive the_file /path/to/your/dir/that/doesn't/exists

cp doesn't have an option which can do this trick.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.