Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy folder structure (without files) from one location to another

People also ask

Can I copy a folder structure without files?

It's the /T option that copies just the folder structure not the files. You can also use the /E option to include empty folders in the copy (by default empty folders will not be copied).

How do you copy an entire directory structure?

Copying Directories with cp Command To copy a directory, including all its files and subdirectories, use the -R or -r option. The command above creates the destination directory and recursively copy all files and subdirectories from the source to the destination directory.

How do I copy a folder structure without files in Outlook?

To copy the existing folder structure from the current Outlook PST file to a new (empty) Outlook data file, you have to create the new Outlook PST file using the "Archive" feature in Outlook.


You could do something like:

find . -type d > dirs.txt

to create the list of directories, then

xargs mkdir -p < dirs.txt

to create the directories on the destination.


cd /path/to/directories &&
find . -type d -exec mkdir -p -- /path/to/backup/{} \;

Here is a simple solution using rsync:

rsync -av -f"+ */" -f"- *" "$source" "$target"
  • one line
  • no problems with spaces
  • preserve permissions

I found this solution there


I dunno if you are looking for a solution on Linux. If so, you can try this:

$ mkdir destdir
$ cd sourcedir
$ find . -type d | cpio -pdvm destdir

This copy the directories and files attributes, but not the files data:

cp -R --attributes-only SOURCE DEST

Then you can delete the files attributes if you are not interested in them:

find DEST -type f -exec rm {} \;