sarkon
sarkon

Reputation: 187

Use rsync to copy current directory without specifying current directory's name

Is there a way to copy the current directory (and not just the contents) to a remote directory -- without specifying the current directory by name.

For example, I'm in the directory /bar and I want to copy /bar and its contents to the remote directory /foo with the resulting directory being /foo/bar.

Of course I could specify the current directory by name, but I'd just to be able to copy, in the manner specified, whatever directory I'm in.

Upvotes: 1

Views: 2898

Answers (1)

Michael Rice
Michael Rice

Reputation: 8194

This seems to do what you want in my tests unless I am miss understanding you:

rsync -r `pwd` user@hosts:./bar

Assuming you have:

Michaels-MacBook-Pro-2 in ~/foo
○ → ls -l 
total 0
-rw-r--r--  1 errr  staff  0 May  9 13:07 bah
-rw-r--r--  1 errr  staff  0 May  9 13:07 bar
-rw-r--r--  1 errr  staff  0 May  9 13:07 baz

Michaels-MacBook-Pro-2 in ~/foo
○ → rsync -r `pwd` [email protected]:./bar
[email protected]'s password: 

You end up with:

errr@ansible-master:~/bar$ ls -lR
.:
total 4
drwxr-xr-x 2 errr errr 4096 May  9 18:10 foo

./foo:
total 0
-rw-r--r-- 1 errr errr 0 May  9 18:10 bah
-rw-r--r-- 1 errr errr 0 May  9 18:10 bar
-rw-r--r-- 1 errr errr 0 May  9 18:10 baz

Upvotes: 1

Related Questions