Why?

Makes it easier to copy a default OpenCart extension. Find the files by name and copy them while also creating the required folder structure.

How

Use the cp command with --parents flag.

cp --parents admin/controller/extension/payment/bank_transfer.php easypaisa/

Won’t work on macOS by default, so brew install coreutils first and then use gcp instead of cp

gcp --parents admin/controller/extension/payment/bank_transfer.php easypaisa/
easypaisa
└── admin
    └── controller
        └── extension
            └── payment
                └── bank_transfer.php

Examples

Extract/Clone an OpenCart Extension with one command

find . -iname 'bank_transfer.*' -exec gcp --parents {} foo/ \;

{} will be replaced with the path name of the file. The last token, \; is there only to mark the end of the exec expression. foo is the directory you’re assumed to have created before running the command

Basically, with find and gcp you have extracted a particular extension.

../bank_transfer/
├── admin
│   ├── controller
│   │   └── extension
│   │       └── payment
│   │           └── bank_transfer.php
│   ├── language
│   │   └── en-gb
│   │       └── extension
│   │           └── payment
│   │               └── bank_transfer.php
│   └── view
│       └── template
│           └── extension
│               └── payment
│                   └── bank_transfer.tpl
└── catalog
    ├── controller
    │   └── extension
    │       └── payment
    │           └── bank_transfer.php
    ├── language
    │   └── en-gb
    │       └── extension
    │           └── payment
    │               └── bank_transfer.php
    ├── model
    │   └── extension
    │       └── payment
    │           └── bank_transfer.php
    └── view
        └── theme
            ├── default
            │   └── template
            │       └── extension
            │           └── payment
            │               └── bank_transfer.tpl
            └── mytheme
                └── template
                    └── extension
                        └── payment
                            └── bank_transfer.tpl

Recreate and Rename an OpenCart extension with two commands

First, find and copy all the files (Assuming you have already created the new folder, in this case easypaisa)

find . -iname 'bank_transfer.*' -exec gcp --parents {} easypaisa/ \;

The thing with using --parents is that the destination must be a directory. So you can’t copy and rename files in one go, like you are usually able to do with cp.

Renaming files once they are copied is easy though, just run a find command to find all the copied files based on their name and rename all of them.

# TOO BUSY TO DO THE GOOGLE
# to-be-continued, will update the code if i ever get a chance later
# manually rename the files for now