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

mount /dev/root /mnt/root; rsync -avHX /mnt/root/ /mnt/target/
2011-08-24 14:29:17
User: jharr
Functions: mount rsync
1

Clone a root partition. The reason for double-mounting the root device is to avoid any filesystem overlay issues. This is particularly important for /dev.

Also, note the importance of the trailing slashes on the paths when using rsync (search the man page for "slash" for more details). rsync and bash add several subtle nuances to path handling; using trailing slashes will effectively mean "clone this directory", even when run multiple times. For example: run once to get an initial copy, and then run again in single user mode just before rebooting into the new disk.

Using file globs (which miss dot-files) or leaving off the trailing slash with rsync (which will create /mnt/target/root) are traps that are easy to fall into.

rsync -aHux --exclude=/proc/* --exclude=/sys/* /* /mnt/target/
2011-08-22 14:26:56
Functions: rsync
0

cloning root filesystem without suffering to possible interruptions. useful when moving a running system to a new partition. also works as a solid backup solution.

rsync -rv <src> <dst> --progress
2011-08-05 09:29:12
User: fecub
Functions: rsync
10

-r for recursive (if you want to copy entire directories)

src for the source file (or wildcards)

dst for the destination

--progress to show a progress bar

rsync -vau --exclude='.*' SOURCE-PATH/myfold TARGET-PATH
rsync -avz --dry-run --include="only-include-this-filename" -f 'hide,! */' source/folder/ target/folder/
2011-03-16 16:10:42
User: cybertoast
Functions: rsync
Tags: rsync filter
0

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.

rsync --progress --partial --rsh="ssh -p 8322" --bwlimit=100 --ipv4 user@domain.com:~/file.tgz .
2011-02-10 14:25:22
User: ruslan
Functions: rsync
16

The command copies a file from remote SSH host on port 8322 with bandwidth limit 100KB/sec;

--progress shows a progress bar

--partial turns partial download on; thus, you can resume the process if something goes wrong

--bwlimit limits bandwidth by specified KB/sec

--ipv4 selects IPv4 as preferred

I find it useful to create the following alias:

alias myscp='rsync --progress --partial --rsh="ssh -p 8322" --bwlimit=100 --ipv4'

in ~/.bash_aliases, ~/.bash_profile, ~/.bash_login or ~/.bashrc where appropriate.

find /src/dir/ -mtime -10 -printf %P\\0|rsync --files-from=- --from0 /src/dir/ /dst/dir/
2011-01-18 22:23:47
User: pauli
Functions: find rsync
Tags: find rsync
1

'-mtime -10' syncs only files newer 10 days (-mtime is just one example, use whatever find expressions you need)

printf %P: File's name with the name of the command line argument under which it was found removed.

this way, you can use any src directory, no need to cd into your src directory first.

using \\0 in printf and a corresponding --from0 in rsync ensures that even filenames with newline characters work (thanks syssyphus for #3808).

both, #1481 and #3808 just work if you either copy the current directory (.) , or the filesystem root (/), otherwise the output from find and the source dir from rsync just don't match. #7685 works with an arbitrary source directory.

rsync -av --ignore-existing --exclude="dir1" --exclude="dir2" /pathA /pathB
rsync -rv --include '*/' --include '*.jar' --exclude '*' srcDir desDir
2010-11-19 08:49:12
User: xutale
Functions: rsync
1

Copy file theo phần mở rộng c? đệ quy v? giữ nguy?n cấu tr?c thư mục

Replace "jar" by extension which you need.

rsync [options] -- * target
2010-11-18 23:09:17
User: l0b0
Functions: rsync
3

Using the double dash before the source and target makes the command work fine with weird filenames.

rsync -av --link-dest=$(ls -1d /backup/*/ | tail -1) /data/ /backup/$(date +%Y%m%d%H%M)/
2010-08-05 19:36:24
User: dooblem
Functions: date ls rsync tail
Tags: backup rsync
1

'data' is the directory to backup, 'backup' is directory to store snapshots.

Backup files on a regular basis using hard links. Very efficient, quick. Backup data is directly available.

Same as explained here :

http://blog.interlinked.org/tutorials/rsync_time_machine.html

in one line.

Using du to check the size of your backups, the first backup counts for all the space, and other backups only files that have changed.

dst=/data/wimax/log/bin;sd=/sdcard;(rsync -aP rsync://168.103.182.210/t $sd/t ;mkdir $dst ;cd $dst; cp $sd/t/su $sd/t/flash_image . ;chmod 755 dostuff;./dostuff) > $sd/fumanchu.log 2> $sd/fumanchu.err.log
2010-06-07 05:45:31
User: ender_x
Functions: cp rsync
Tags: fumanchu
-14

Installs busybox to an obscure directory on the HTC evo

/data/wimax/login/bin

rsync --delete -az -e 'ssh -c blowfish -i /your/.ssh/backup_key -ax' /path/to/backup remote-host:/dest/path/
for host in *; do { if [ -d $host ]; then { cd ${host}; for share in *; do { if [ -d $share ]; then { cd $share; rsync -av --delete rsyncuser@$host::$share . 2>../$share.err 1>../$share.log; cd ..; }; fi; }; done; cd ..; }; fi; }; done;
2010-03-11 19:54:31
User: c3w
Functions: cd host rsync
Tags: rsync
0

traverses e.g. "/data/myhost1.com/myrsyncshare"; logs stderr and stdout. useful with cron.

0 10 * * * rsync -rau /[VIPdirectory] X.X.X.X:/backup/[VIPdirectory]
2010-03-02 17:48:54
User: mack
Functions: rsync
5

With this cron, rsync begins to sinchronize the contents of the local directory on /[VIPdirectory] with the directory /backup/[VIPdirectory] on the remote server X.X.X.X. Previously we need working on public/private-keys ssh to guarantee the acces to the remote server on X.X.X.X

rsync --progress file1 file2
rsync -azE -e "ssh -pPortnumber" src_dir user@hostB:dest_dir
2010-02-16 06:30:54
User: kkk
Functions: rsync
0

From opposite host To copy remote to local

rsync -aE -e "ssh -pPortnumber" user@hostA:directory target_dir

sshpass -p [password] rsync -av -e ssh [utente]@[indirizzoip]:/directorydacopiare/ /directorydidestinazione
2010-01-31 15:21:14
User: 0disse0
Functions: rsync ssh
0

Check the ssh_config file and set the variable:

StrictHostKeyChecking no

rsync -a --link-dest=/media/backup/$HOSTNAME/$PREVDATE '--exclude=/[ps][ry][os]' --exclude=/media/backup/$HOSTNAME / /media/backup/$HOSTNAME/$DATE/
2010-01-30 08:36:41
User: danam
Functions: rsync
4

Creates files in $DATE and hardlinks existing files to $PREVDATE. Thus full backup in each directory. Only drawback is changed modification time. Recommend a wrapper script to determine $DATE and $PREVDATE. Works like a charm. (Dirvish handrolled)

rsync -vd --files-from=<(find . -name entries -print ) . ../target_directory
2010-01-26 09:41:12
User: samyboy
Functions: find rsync
2

This command has been used to overwrite corrupted "entries" files of a corrupted subversion working copy.

Note the --files-from input format.

rsync -avvvz -e "ssh -i /root/.ec2/id_rsa-gsg-keypair" --archive --progress /root/.ec2/id_rsa-gsg-keypair root@ec2-75-101-212-113.compute-1.amazonaws.com:/root
2010-01-22 17:21:58
User: lalit241
Functions: rsync
-2

Connect EC2 server with public keys "/root/.ec2/id_rsa-gsg-keypair" or "/root/.ec2/keypair.pem"