• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Copy bulk Files in Linux

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 22273
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all depends on where the files are and where you want to put them.

If I wanted to copy all the .java files from /home/timh/project5/src/main/java to /export/backup/timh/projects/project5 I could use the find command, the rsync command, the cp command and several others, and depending on options,  dump all the files into the destination directory or replicate the source directory structure as well.

In a simple case, if you specify multiple source files on the cp command and a single destination directory, all those files would be copied into that directory:
Or use a "glob" wildcard
I can copy a directory and its attributes to a new directory:
Only if you're trying to copy from/to wildly-located places would a script be essential, and even then, sometimes you can just feed a file containing a list of filename paths to a copy utility.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Gabriel Turqos

you can copy bulk of file with help of the cp command.
To copy multiple files using the cp command pass the
names of files followed by the destination directory to the cp command.

tree -F
.
├── bar.txt
├── baz.txt
├── foo/
└── foo.txt
cp foo.txt bar.txt baz.txt foo/
tree .
.
├── bar.txt
├── baz.txt
├── foo
│   ├── bar.txt
│   ├── baz.txt
│   └── foo.txt
└── foo.txt

The same operation can also be achieved through pattern matching

cp *.txt foo/

Follow this site for more understanding
https://www.thegeekstuff.com/2013/03/cp-command-examples/

i hope this will help to you
 
lowercase baba
Posts: 12871
62
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to maintain the relative paths, consider tar.  you basically tar up a directory, move the new file, then un-tar it in another and it re-creates the tree.
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic