-1

I have a list of files in following structure:

 A/abc.zip
 B/abc.zip
 C/abc.zip

I want to use copy command to copy them:

$ cp */abc.zip ~/dest/

This seems to replace the file every time, how can I copy these files properly with Linux bash?

Say if I want to rename it to be dest/A-abc.zip, dest/B-abc.zip, dest/C-abc.zip?

jww
  • 97,681
  • 90
  • 411
  • 885
Pythoner
  • 5,265
  • 5
  • 33
  • 49
  • if you use the --parents flag it should copy the folder paths to all of the abc.zip into dest – quasar Oct 10 '18 at 14:54
  • 1
    This question deals with the problem of copying and renaming in one command: https://unix.stackexchange.com/questions/115813/how-to-rename-files-while-copying – Blair Nangle Oct 10 '18 at 14:56
  • "I want to use the copy command" -- should we take this to mean you wouldn't accept any answer that *didn't* use `cp`? If not, how *should* we understand that line to reflect your intent? – Charles Duffy Oct 10 '18 at 14:57
  • @CharlesDuffy, ideally cp or basic bash cmd, as I use an old cygwin, it does not support some advanced command. – Pythoner Oct 10 '18 at 15:01
  • If you have `rsync`, then you can use the `-R` option. – Tom Fenech Oct 10 '18 at 15:03
  • You should show your code so folks know where you are having trouble. All the parts of this question have been asked and answered previously. Possible duplicate of [Renaming files in a folder to sequential numbers](https://stackoverflow.com/q/3211595/608639), [Renaming a set of files to 001, 002, … on Linux](https://stackoverflow.com/q/880467/608639), etc. – jww Oct 10 '18 at 18:45

1 Answers1

2

If you don't need to put everything in the same path, you could maintain the structure using --parent :

$ cp --parent */abc.zip ~/dest

$ tree ~/dest
~/dest
├── 1
│   └── abc.zip
├── 2
│   └── abc.zip
└── 3
    └── abc.zip
Andor
  • 1,998
  • 3
  • 16
  • 24