copy only non-hidden files

Duane Whitty duane at nofroth.com
Tue Oct 24 02:40:06 UTC 2017



On 17-10-23 11:26 PM, Ralf Mardorf wrote:
> On Tue, 24 Oct 2017 03:58:43 +0200, Ralf Mardorf wrote:
>> On Mon, 23 Oct 2017 22:32:48 +0000 (UTC), thufir wrote:
>> >From time to time I see different scripts or techniques on this 
>>> question.  The best approach I've seen yet is:
>>>
>>>
>>>
>>> rsync -av --exclude=".*" src dest
>>>
>>> https://stackoverflow.com/a/11557219/262852
>>>
>>>
>>>
>>> the rare time when I want to do this then I spend time trying to
>>> recall how to even find that solution.  Is there another tool or
>>> approach, perhaps?  
>>
>> The link you posted already is giving the pointer to globbing. IMO the
>> argument that "it would copy any hidden files in the next level
>> of sub-directories" is strange, since it's unusual to hide something
>> inside a hidden parent directory. The "asterisk" is your friend, issues
>> caused by "hidden files in the next level of sub-directories" are very
>> unlikely, respectively if there should be levels of hidden items, it
>> would be strange to exclude them unconditionally. A hierarchical file
>> system should make sense, if it's based on arbitrariness, it isn't a
>> hierarchical file system anymore.
> 
> PS:
> 
> You could use the "asterisk" on more than just one level, e.g.
> "/home/*/*".
> 
> 
> 
Please excuse me if I am totally misunderstanding either the OP or
responder... I thought the idea was to avoid copying any hidden files or
directories.  Does "*" not match any and all files.  So, for example,
what if I want to copy the contents of my home directory including
subdirectories excluding my ".gnupg" directory?

Wouldn't cp /home/duane/*/* /home/someone/ result in my .gnupg directory
being copied?

Best Regards,
Duane

-- 
Duane Whitty
duane at nofroth.com




More information about the ubuntu-users mailing list