Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using rsync from sorted by
Terminal - Commands using rsync - 67 results
rsync -avz --dry-run /somewhere/source_directory /somewhereelse/target_directory
2014-04-01 20:55:59
User: tsener
Functions: rsync
Tags: diff rsync
-1

--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.

rsync -a -v --delete sending_directory target_directory
rsync -av -e "ssh -o MACs=hmac-ripemd160" --progress --partial user@remotehost://path/to/remote/stuff .
2014-02-01 00:46:38
User: RAKK
Functions: rsync
Tags: ssh rsync hmac
0

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.

while true; do rsync -vR $(git ls-files | inotifywait -q -e modify -e attrib -e close_write --fromfile - --format '%w') user@host:dest/dir/; done
2014-01-21 10:31:41
User: leucos
Functions: rsync
0

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

}

rsync -arvx --numeric-ids --stats --progress --bwlimit=1000 file server:destination_directory
2013-10-01 13:00:59
Functions: file rsync
Tags: Linux rsync
0

Useful for transferring large file over a network during operational hours

rsync -v -r --size-only --compare-dest=../A/ B/ C/
2013-09-10 21:41:16
User: knoppix5
Functions: rsync
8

Assumed dir A, B, C are subdirs of the current dir

Exact syntax of the command is:

rsync -v -r --size-only --compare-dest=/path_to_A/A/ /path_to_B/B/ /path_to_C/C/

(do not omit end-slashes, since that would copy only the names and not the contents of subdirs of dir B to dir C)

You can replace --size-only with --checksum for more thorough file differences validation

Useful switch:

-n, --dry-run perform a trial run with no changes made

rsync -a --append source-file destination
BEGIN=`date`; rsync -avxW /home/ /backups/home ; echo "Begin time: $BEGIN" ; echo "End time..: `date`"
2013-07-06 08:24:45
User: ryanchapman
Functions: echo rsync
Tags: rsync
0

Copies a directory structure from /home/ to /backups/home (notice that the destination does not have a trailing slash)

rsync -avzhP <[[user@]host1:]directory1> <[[user@]host2:]directory2>
rsync --progress user@host:/path/to/source /path/to/target/ | stdbuf -oL tr '\r' '\n' >> rsyncprogress.txt
2013-03-26 11:06:45
User: MessedUpHare
Functions: rsync tr
0

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)

rsync
2013-03-01 14:47:19
User: techie
Functions: rsync
-8

rsync is the best command ever and I am interested what the rest of you think is the best command

rsync -arl --rsh=ssh --progress --exclude-from=/etc/localbin/exclude_files.txt /var/www/html/source/* <user>@<server>:/var/www/html/source/
rsync -a -v --stats -e ssh /home root@<newserver>:/root/
mkdir r1 && sshfs remote1:/home/user r1 && rsync r1/stuff remote2:~/backups/
2013-01-11 14:12:22
User: unhammer
Functions: mkdir rsync
Tags: rsync sshfs
-1

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.

rsync -aHAXxv --numeric-ids --delete --progress -e "ssh -T -c arcfour -o Compression=no -x" user@<source>:<source_dir> <dest_dir>
2012-12-26 13:46:23
User: somaddict
Functions: rsync
Tags: ssh rsync
7

This creates an archive that does the following:

rsync::

(Everyone seems to like -z, but it is much slower for me)

-a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.

-H: preserves hard-links

-A: preserves ACLs

-X: preserves extended attributes

-x: don't cross file-system boundaries

-v: increase verbosity

--numeric-ds: don't map uid/gid values by user/group name

--delete: delete extraneous files from dest dirs (differential clean-up during sync)

--progress: show progress during transfer

ssh::

-T: turn off pseudo-tty to decrease cpu load on destination.

-c arcfour: use the weakest but fastest SSH encryption. Must specify "Ciphers arcfour" in sshd_config on destination.

-o Compression=no: Turn off SSH compression.

-x: turn off X forwarding if it is on by default.

Flip: rsync -aHAXxv --numeric-ids --delete --progress -e "ssh -T -c arcfour -o Compression=no -x" [source_dir] [dest_host:/dest_dir]

rsync -ayz -e ssh --exclude=/proc --exclude=/sys --exclude=/dev / root@NEWHOST:/MNTDIR
2012-11-06 09:43:42
User: bones
Functions: rsync ssh
7

Copies the complete root-dir of a linux server to another one, where the new harddisks formated and mountet. Very useful to migrate a root-server to another one.

rsync -avz -e ssh user@host:/srcpath destpath
rsync -avz ~/src ~/des/
2012-06-01 15:08:12
User: axelabs
Functions: rsync
0

rsync will copy the source directory into destination and any subsequent run will synchronize only the changes from the source.

rsync -a /path/from/.[^.]* /path/to
2012-03-19 22:08:54
User: magbeat
Functions: rsync
Tags: rsync
0

Useful when upgrading my Linux distro and trying to copy only "settings" from the old home folder to the new one.

rsync -aP --no-whole-file --inplace
2012-01-29 18:39:31
User: jlaunay
Functions: rsync
0

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

rsync -rv --exclude .svn src/dir/ dest/dir/
rsync -rv --include '*/' --include '*.txt' --exclude '*' srcDir/ desDir/
rsync -a /etc /destination
2011-10-18 13:07:55
User: atoponce
Functions: rsync
Tags: rsync
7

Yes, rsync(1) supports local directories. And, should anything change, it's trivial to run the command again, and grab only the changes, instead of the full directory.

rsync -P -e 'ssh -p PORT' SRC DEST
2011-10-13 08:59:07
User: vickio
Functions: rsync
Tags: ssh rsync
-1

Transfer files with rsync over ssh on a non-standard port, showing a progress bar and resuming partial transfers.

rsync --daemon --port 9999 --no-detach -v --config .rsyncd.conf
2011-09-22 20:48:31
User: pykler
Functions: rsync
-3

An example config file is placed in the sample output along with the command line call to use it.

The rsync daemon here is setup on the destination, thus requiring the read only = false flag. Also it uses uid and gid of root, change as required.