Copy bulk Files in Linux

Gabriel9999

Member
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?
 


captain-sensible

Well-Known Member
Credits
5,792
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.
 

JasKinasis

Well-Known Member
Credits
2,312
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.
 

f33dm3bits

Gold Member
Gold Supporter
Credits
3,480
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?
 

jglen490

Well-Known Member
Credits
2,035
Use rsync.
 

wizardfromoz

Super Moderator
Staff member
Gold Supporter
Credits
4,725
Just passing through and moving this to Command Line - all contributors will be redirected.

Friday here in Oz so

Avagudweegend, all

Chris Turner
wizardfromoz
 


Members online


Latest posts

Top