Reputation: 23
How i can recreate entire directory structure and copy only files with .txt extension if present. I would like to copy the directory or sub-directory even if its empty.
Upvotes: 1
Views: 926
Reputation: 241848
To create the directory structure:
cd source-dir
find . -type d -exec mkdir target-dir/{} \;
You can ignore the message that .
cannot be created.
Then, copy the txt
files into it:
find . -type f -name '*.txt' -exec cp {} target-dir/{} \;
Upvotes: 0
Reputation: 1
cd source-dir
find . -type d -mindepth 1 -exec mkdir target-dir/{} \;
to avoid creating directory "." and error "No such file or directory" respectively.
Upvotes: 0
Reputation: 23
here is one line command :)
rsync -vapEtogR --progress --stats --log-file="log_file_name.txt" --include '*/' --include '*.txt' --exclude '*' source_path/ destination_path/
Use rsync --help
to know about the options used.
Upvotes: 1