8
2
I want to copy current directory to my backup directory:
I tried this command rsync -a . ~/backup/
but it just copies the current directory contents instead of creating new directory at the destination.
I know creating new directory at the destination end can be achieved by avoiding the trailing slash in source path. But it does not work in my case since I am using a period(".") instead of directory name.
I want rsync to create a new directory at the destination path with name same as the current directory. How can I achieve this?
This is better solution..! Actually I just wanted to create an alias like ("backupme") So I can easily take backup of current directory by executing that command. This command is very useful and now I am going to remove that script and use this instead. Thank You..! – B.A.B – 2015-04-24T03:44:49.847
This command works! But when I am creating an alias and executing that alias it just takes the backup of my home directory instead of current directory. – B.A.B – 2015-04-24T04:10:09.073
1Try to use single quote
'
in the alias definition:alias BACKUPNOW='rsync -a $(pwd) ~/backup/'
– Hastur – 2015-04-24T06:56:22.697Examples often are better than words. It is not in aliasing, it is in bash. ;) Till you are curious do a wide use of
– Hastur – 2015-04-24T07:10:18.140man bash
(or another command) orhelp alias
if the command is a built-in... Okman bash
is a wide output to start with... but in general you can do it.Oh! when I use double quotes it expanded inside the alias definition okay understood. Thanks for your help – B.A.B – 2015-04-24T07:11:52.640
Thanks, this works great. But when path of current directory contains space it breaks. So it's better to always use
pwd
with double quotes"$(pwd)"
. – Navid Ht – 2016-05-02T17:25:43.1531@NavidHt Thanks for the spot. Updated. Note that you can avoid at all the subshell with the use of the variable PWD,
"$PWD"
. – Hastur – 2016-05-03T15:13:47.747I had to add / to "$PWD" for it to work for delete as well – tsukimi – 2018-01-26T02:18:26.237