Shell commands goodness

A few shell commands 

This article reference a few useful shell commands.

All of this stays in the man pages, but it’s not that easy to understand their arguments.  Here are some examples :

copying  files in the Finder will affect ownership ! It’s a pain.
using scp will have the same issue.
locally you can use the Apple ditto command.

Let’s use ditto over SSH to copy files from a Mac to another without the pain of loosing ownership.

Here’s what the man tells us :

The command:
 ditto -c --norsrc Scripts -|ssh rhost ditto -x --norsrc - ./Scripts
 copies Scripts, skipping any resources or meta-data, to rhost.

In this example, we will copy the /tmp/test folder of our Mac, to the /tmp folder of the distant server  ‘volnay.easymac.fr’

Scripts becomes /tmp/test
 rhost becomes volnay.easymac.fr
 ./Scripts becomes /tmp/test

The other args are :

-c to compress during the network transfer
-x to uncompress on the destination Mac
– this alone dash is not a mistake, it’s the way the ssh ditto result is sent to the local ditto command

ditto -c /tmp/test -| ssh volnay.easymac.fr ditto -x – /tmp/test

Reverse example : we will copy the /tmp/test folder of the distant server ‘volnay.easymac.fr’ in the /tmp folder of our local Mac

Scripts becomes /tmp/test
 rhost becomes volnay.easymac.fr
 ./Scripts becomes /tmp/test

Les autres arguments utilisés :

-c to compress during the network transfer
-x to uncompress on the destination Mac
– this alone dash is not a mistake, it’s the way the ssh ditto result is sent to the local ditto command

ssh volnay.easymac.fr ditto -c /tmp/test -| ditto -x – /tmp/test

You will notice that I don’t use the –norsrc argument, not because it’s not useful, because it should be responsible of resources not to be copied

Posted in macOS.

Leave a Reply

Your email address will not be published. Required fields are marked *