Monday, April 29, 2024
19
rated 0 times [  19] [ 0]  / answers: 1 / hits: 51604  / 1 Year ago, sat, may 6, 2023, 10:20:14

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?


More From » command-line

 Answers
0

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 ~/Desktop/home/desgua/Downloads and then copy test.txt into it; and



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


will create ~/Desktop/Downloads.


[#39138] Sunday, May 7, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breadoules

Total Points: 212
Total Questions: 118
Total Answers: 120

Location: Dominica
Member since Mon, Jun 22, 2020
4 Years ago
;