6

[Bash] Copy Large Number of Files on Linux

 2 years ago
source link: http://siongui.github.io/2016/12/20/bash-copy-large-number-of-files-on-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

[Bash] Copy Large Number of Files on Linux

December 20, 2016

If you want to copy large number of files, it's not a good idea to use cp -r command directly because it will take a lot of time. It's better to use tar command to archive the files into a single file and then extract the file to the destination directory you want. The following is the Bash script to demonstrate how to copy large number of files efficiently:

cpn.sh | repository | view raw

#!/bin/bash

# $1 is the directory in which files to be copied
# $2 is the destination directory

tar cvf /tmp/foo.tar $1
tar xvf /tmp/foo.tar -C $2
rm /tmp/foo.tar

Tested on: Ubuntu Linux 16.04, bash 4.3.46(1).


References:

[2][Bash] Move Large Number of Files via tar Command


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK