Tuesday, February 21, 2012

How to copy file with the directory structure?

cp command has a --parents option which will automatically create the source directory structure at the destination.

$ pwd
$ ls
dir1 dir2 dir3 dest_dir
$ ls dir1

Following command will create the folder structure dir1/a inside dest_dir and copy the file.txt into it.

$ cp --parents dir1/a/file.txt dest_dir

No comments: