Command Line – Copying Files

Copying files via the CLI is easily achieved by using the command ‘cp’:

cp file dest

The limitation with the ‘cp’ command is the lack of status or progress of the file copy. There are a couple of alternative approaches:

Use the ‘watch’ command via a new CLI window or use ‘rsync’.

The ‘watch’ command is a command to watch and refresh the display of the CLI with a specific command and time duration i.e:

watch -n 2 ls -l

Will simply refresh the CLI every 2 seconds with command ls -l. You will be able to see the file size updating every 2 seconds if listing the destination folder. This isn’t a clean solution, requires two windows and separate commands.

Rsync is a command that is vastly superior to the standard cp command. Remote and local hosts are supported and there is checking of files during the copy process. The example:

Rsync — progress file dest

Will show a progress bar of the file copying process.

As a recommendation, once large files have been copied it is always ensuring that the md5 checksum is consistent i.e. the file isnt corrupted. This can be done via the command:

md5sum file

Compare this checksum against the master/original copy. If there is a difference, this means the file is not the same and thus corrupted.

If you are copying large files >4GB onto FAT32 filesystems, then the file will need to be split. One method can achieve this by tar and splitting:

tar -cvj file | split -b 2000m -d – “targetname.tar.bz.”

This will create a tar file, split into 2GB files with a name targetname.tar.bz.xx. If a file is 4.5GB in size then there will be three files targetname.tar.bz.00, targetname.tar.bz.01, targetname.tar.bz.02