This widget could not be displayed.
Operating System - Linux
1845515 Members
2442 Online
110244 Solutions
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
New Discussion
This widget could not be displayed.
This widget could not be displayed.

Re: rsync - excluding directories

 
Piotr Kirklewski
Super Advisor

rsync - excluding directories

Hi there
I need to copy all the .txt files from certain directory and it's subdirectories preserving timestamps permissions etc.
Rsync is great for that but I ccan't find out how to tell it not to copy the directories - just the files.



Jesus is the King
4 REPLIES 4
Wilfred Chau_1
Respected Contributor

Re: rsync - excluding directories

did you supply the -r or -a flag in the rsync command?

that is a normal behavior for rsync. Best bet would be to cd into the dir/sub dir first, then do a rsync *.txt dest:/dir
Jared Middleton
Frequent Advisor

Re: rsync - excluding directories

Assuming transfer is from a remote host to local, you could try a kludge like this:
dir=$(mktemp -d) && rsync -a --include '*/' --include='*.txt' --exclude='*' SOURCEHOST:/SOURCEDIR/ $dir && find $dir -type f -exec mv {} TARGETDIR \; && rm -rf $dir
Dennis Handly
Acclaimed Contributor

Re: rsync - excluding directories

What do you mean by excluding directories? Did you want to flatten the directory structure?
Steven Schweda
Honored Contributor

Re: rsync - excluding directories

> What do you mean by excluding directories?
> Did you want to flatten the directory
> structure?

That was my guess. As usual, showing an
actual example might be more helpful than a
vague description.

If you're not wedded to rsync, then the
Info-ZIP Zip and UnZip programs (both) offer
a "-j" option to avoid storing or restoring
directories. I'd also expect that GNU "tar"
options like --strip-components and/or
--transform should be able to do the job at
extraction. Either way, it should be
possible to preserve the date-time, UID+GID,
and permission info.

http://www.gnu.org/software/tar/manual/html_node/transform.html


> [...] it's subdirectories [...]

That's "its subdirectories".