DIFFERENT METHODS TO COPY FILES IN LINUX
Ways to copy files
- cp
- rsync
- cat
Size of a file to be copied
[oracle@orcl19x ~]$ du -sh sale1.csv
96M sale1.csv
CP:
cp command is most commonly used to copy files in linux. cp doesnot overwrite an existing file if that already exist on the directory. Use cp with -v option to display the verbose output
[oracle@orcl19x ~]$ time cp sale1.csv /tmp
real 0m8.828s
user 0m0.002s
sys 0m0.108s
[oracle@orcl19x ~]$ cp -v sale1.csv /tmp
‘sale1.csv’ -> ‘/tmp/sale1.csv’
RSYNC:
Rsync is another underestimated command used in linux to copy files efficiently.
[oracle@orcl19x ~]$ time rsync sale1.csv /tmp
real 0m3.072s
user 0m0.703s
sys 0m0.368s
Major advantage of using rsync is to copy the incremental data on files on a directory if that file already exists. This command checks for synchronous match between source and destination. Use rsync with -va option to run the command with verbose and preserve symlink and other critical files
[oracle@orcl19x ~]$ time rsync -av sale1.csv /tmp
sending incremental file list
sale1.csv
sent 100486711 bytes received 31 bytes 40194696.80 bytes/sec
total size is 100474349 speedup is 1.00
real 0m5.962s
user 0m0.671s
sys 0m0.393s
CAT:
cat command can also be used to redirect the file output from one source file to destination file. This command mostly be used to display the output of files on the screen. But alternatively it can also be used to copy files indirectly which is not quite straightforward or confusing. A greater than ‘>’ symbol can be used to print the contents of files from source to destination.Do not use less than ‘<‘ symbol.
[oracle@orcl19x ~]$ time cat sale1.csv > /tmp/sale1.csv
real 0m0.094s
user 0m0.000s
sys 0m0.093s