Copy bulk Files in Linux

Gabriel9999

Member
Joined
Mar 12, 2019
Messages
38
Reaction score
4
Credits
130
I have multiple files in a Linux systems where I want to copy them with a single cp command into a different path and directory. Should I write a bash script to copy one by one?
 


depends, even writing a bash script might be too much work but depends on diversity , number locations and if you can group into "like" files.

For instance if i want to copy loads of tgz files from /tmp and want to copy them to a directory on my Desktop say called dir2 then i won't bother with a bash script just open a terminal cd to /tmp and



cp *.tgz /home/andrew/Desktop/dir1


then that just leaves a couple of .txz so

cp *.txz /home/andrew/Desktop/dir1


in both cases the file name prior to the * is preserved.
 
It depends on what you’re trying to copy/move.

You might need a single cp, or mv command.
Or you might need several.
Or you may need to use a different command altogether, like find (to find files to move/copy) and use finds -exec option to specify an action to perform on the found files/directories.

Or it might require a full blown script.

The cp and mv commands can take a list of several items to copy/move. So if you have several items going to one destination, that should be a one-liner.

If you have different items going to different directories, that could require several commands.

Also, you may be able to take advantage of globbing, or pattern matching using regular expressions to identify the files you want to copy/move.

But without some more specific information, it’s difficult to advise you on what to do next.
 
You can also use rsync to copy files locally from one directory to another directory. Just to files withon the source directory: rsync -av /src/foo/* /dest/backup or you could copy over the whole directory to another location. Can you give an example of what you would like to do?
 
Use rsync.
 
Just passing through and moving this to Command Line - all contributors will be redirected.

Friday here in Oz so

Avagudweegend, all

Chris Turner
wizardfromoz
 
according to this article ,
bulk copy can done using rsync command

rsync -arv /home/centos/sampe-dir /opt/temp-directory/
 

Members online


Top