Asked • 06/12/19

How to have the cp command create any necessary folders for copying a file to a destination?

When copying a file using `cp` to a folder that may or may not exist, how do I get `cp` to create the folder if necessary? Here is what I have tried: <!-- language:none --> [root@file nutch-0.9]# cp -f urls-resume /nosuchdirectory/hi.txt cp: cannot create regular file `/nosuchdirectory/hi.txt': No such file or directory

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.