Useful for transferring large file over a network during operational hours
That is, after running `vagrant ssh-config` to determine ports and ip's:
vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2200
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/romanvg/tmp/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
This will email user@example.com a message with the body: "rsync done" when there are no processes of rsync running. This can be changed for other uses by changing $(pgrep rsync) to something else, and echo "rsync done" | mailx user@example.com to another command.
Check the ssh_config file and set the variable: StrictHostKeyChecking no
traverses e.g. "/data/myhost1.com/myrsyncshare"; logs stderr and stdout. useful with cron.
Applying filter rules is what makes this a really useful command. It's usually a pain to figure out how to sync ONLY files matching a particular pattern, and often one reverts to goofy stuff like find .. -exec rsync .. The filter hides all folders from the transfer, so that only the matching folders that store the filename are left for the sync.
a : to keep files permissions --no-whole file : use rsync?s delta-transfer algorithm --inplace : writes the updated data directly to the destination file optionnal -> add --remove-source-files to mv instead of cp
Useful when upgrading my Linux distro and trying to copy only "settings" from the old home folder to the new one.
rsync will copy the source directory into destination and any subsequent run will synchronize only the changes from the source. Show Sample Output
This line unbuffers the interactive output of rsync's --progress flag creating a new line for every update. This output can now be used within a script to make actions (or possibly piped into a GUI generator for a progress bar)
While edtiing a project under git, it is sometimes nice to sync changes immediately to a test machine. This command will take care of this if you have inotifywait installed on the developement machine. Note the -R (relative) in rsync. with rsync foo/bar/baz user@host:dest/dir/ it will put 'baz' in dest/dir/foo/bar/ which is what we want. this can be turned into a function for additionnal flexibility : function gitwatch() { if [ -z $1 ]; then echo "You must provide a rsync destination" return fi while true; do rsync -vR $(git ls-files | inotifywait -q -e modify -e attrib -e close_write --fromfile - --format '%w') $1 done }
This command allows you to mirror folders or files with rsync using a secure SSH channel with a forced HMAC integrity algorithm. Use this if you are absolutely adamant about preserving data integrity while mirroring a set of files. --partial is for resumability.
Useful, when you need to backup/copy/sync a folder over ssh with a non standard port number
update the output of rsync after completing a file but don't create newlines, just overwrite the last line, this looks a lot better in scripts where you do want to see a progress-indicator, but not the lengthy logs this option is available since rsync 3.1.0 Show Sample Output
Functionally the same as the Microsoft Robocopy (https://en.wikipedia.org/wiki/Robocopy) command below but with the benefits of compression and optionally specifying a user.
robocopy /e [//host]/source/path [//host]/destination/path
Options:
-a: archive mode - rescursive, copy symlinks as symlinks, preserve permissions, preserve modification times, preserve group, preserve owner, preserve device files and special files
-hh: Numbers in human-readable K=1024 format. Single "h" will produce human-readable K=1000 format
-m: don't copy empty directories
-z: use compression (if both source and destination are local it's faster to omit this)
--progress: Shows progress during the transfer and implies --verbose (verbose output)
--stats: Summary after the transfer stops
Show Sample Output
run rsync over ssh where root login is not allowed. You need to have "ForwardAgent yes" in your ssh config and run ssh-add before you login to the machine where you want to sync the files to.
cd $target_dir then run the command for fast removal of millions of files
Especially useful while syncing to Amazon EC2 instance. avz stands for archive verbose compress
Transfer files with rsync over ssh on a non-standard port, showing a progress bar and resuming partial transfers.
rsync by itself doesn't support copying between two remote hosts, but if you use sshfs you can pretend one of them is local. If you have a passphrase-less ssh-key, you can even put this script into a cron job. A faster alternative is to run ssh-keygen on remote1 and put the pubkey into remote2:~/.ssh/authorized_keys, running rsync on remote1 (or vice versa), but the problem with that is that now a hacker on remote1 can access remote2 at any time. The above method ensures your local computer stays the weak link. Show Sample Output
--dry-run will only show you which files would be otherwise synced with rsync. -z is for compressio -v vervose -a "as is" - permissions, ownership etc.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: