linuxbashshellunixcp

Linux: copy and create destination dir if it does not exist


I want a command (or probably an option to cp) that creates the destination directory if it does not exist.

Example:

cp -? file /path/to/copy/file/to/is/very/deep/there

Solution

  • mkdir -p "$d" && cp file "$d"
    

    (there's no such option for cp).