UNIX File Copy

Use sftp or rsync for copying files between hosts. The scp protocol is no longer considered secure.

Copying Files

cp

To time how long it takes to make a copy of a file...

time cp myfile1.tst myfile2.tst

rsync

To recursively copy a directory and its contents including progress reporting  and timing...

time rsync -a --progress /mymount1/mydir /mymount2

time rsync -rlptgoD --progress /mymount1/mydir /mymount2

The two commands above are functionally identical. i.e. -a is the same as -rlptgoD

rsync mydir1 mydir2

Copies mydir1 into mydir2 and misses out mydir1/mysubdir

rsync mydir1/* mydir2

skipping directory mysubdir
Duplicates the files in mydir1 to mydir2 but misses out mydir1/mysubdir

rsync -r mydir1/* mydir2

Successfully duplicates mydir1 to mydir2

rsync -ri mydir1/* mydir2

>f+++++++++ myfile1>f+++++++++ myfile2cd+++++++++ mysubdir/>f+++++++++ mysubdir/myfile3
Successfully duplicates mydir1 to mydir2

rsync -ri mydir1/* mydir2

>f..T...... myfile1>f..T...... myfile2>f..T...... mysubdir/myfile3
Running the same command again without removing mydir2 results in output as shown.

rsync -rv mydir1/* mydir2

sending incremental file listcreated directory mydir2myfile1myfile2mysubdir/mysubdir/myfile3
sent 547 bytes  received 110 bytes  1,314.00 bytes/sectotal size is 289  speedup is 0.44
Successfully duplicates mydir1 to mydir2

rsync -r --stats mydir1/* mydir2

Number of files: 4 (reg: 3, dir: 1)Number of created files: 4 (reg: 3, dir: 1)Number of deleted files: 0Number of regular files transferred: 3Total file size: 289 bytesTotal transferred file size: 289 bytesLiteral data: 289 bytesMatched data: 0 bytesFile list size: 0File list generation time: 0.001 secondsFile list transfer time: 0.000 secondsTotal bytes sent: 547Total bytes received: 81
sent 547 bytes  received 81 bytes  1,256.00 bytes/sectotal size is 289  speedup is 0.46
Successfully duplicates mydir1 to mydir2.Provides stats about the rsync.

rsync -r --progress mydir1/* mydir2

sending incremental file listcreated directory mydir2myfile1             63 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=3/4)myfile2             62 100%   60.55kB/s    0:00:00 (xfr#2, to-chk=2/4)mysubdir/mysubdir/myfile3            164 100%  160.16kB/s    0:00:00 (xfr#3, to-chk=0/4)

time rsync -ahiv --stats mydir1/* mydir2

rsync -ahv --progress --dry-run --update --backup --suffix=.bak /mymount1/mydir /mymount2

rsync -ahv --progress --update --backup --suffix=.bak /mymount1/mydir /mymount2

Standard out redirection

TODO:

pv source >destination

cat source >destination

gcp

Bibliography