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:
[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
dirname "/nosuchdirectory/hi.txt" | while read path;do mkdir -p "$path"; done && cp -f urls-resume /nosuchdirectory/hi.txt