Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@brianloveswords
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianloveswords/46b337bcf8dfd2a2909b to your computer and use it in GitHub Desktop.
Save brianloveswords/46b337bcf8dfd2a2909b to your computer and use it in GitHub Desktop.

I have two directories that look like this:

$ ls
dirA/ dirB/

$ ls dirA
bg_BG/  cs_CZ/  de_DE/  el_GR/  en_AU/  en_GB/  en_PH/  en_PL/	en_SG/  en_US/  es_AR/
es_ES/  es_MX/  fr_FR/  hu_HU/  id_ID/  it_IT/  ja_JP/  ko_KR/	ms_MY/  nl_NL/  pl_PL/
pt_BR/  pt_PT/  ro_RO/  ru_RU/  th_TH/  tr_TR/  vn_VN/  zh_CN/	zh_MY/  zh_TW/

$ ls dirB
bg_BG/  cs_CZ/  de_DE/  el_GR/  en_AU/  en_GB/  en_PH/  en_PL/	en_SG/  en_US/  es_AR/
es_ES/  es_MX/  fr_FR/  hu_HU/  id_ID/  it_IT/  ja_JP/  ko_KR/	ms_MY/  nl_NL/  pl_PL/
pt_BR/  pt_PT/  ro_RO/  ru_RU/  th_TH/  tr_TR/  vn_VN/  zh_CN/	zh_MY/  zh_TW/

dirA and dirB have different stuff in their subdirectories and I want to copy just one file from the subdirectories of dirA to the subdirectories of dirB: dirA/<locale>/file -> dirB/<locale>/file

What are some ways to solve this problem?

If you want to experiment, I've included a base64 encoded tar file below that expands into the following structure:

file-copy-test
├── dirA
│   ├── 1
│   │   ├── file
│   │   └── garbage
│   ├── 2
│   │   ├── file
│   │   └── garbage
│   └── 3
│       ├── file
│       └── garbage
└── dirB
    ├── 1
    │   └── safe
    ├── 2
    │   └── safe
    └── 3
        └── safe

8 directories, 9 files

The goal is to copy all the files from dirA/* to dirB/* without deleting the safe files and without copying the garbage files, i.e:

file-copy-test
├── dirA
│   ├── 1
│   │   ├── file
│   │   └── garbage
│   ├── 2
│   │   ├── file
│   │   └── garbage
│   └── 3
│       ├── file
│       └── garbage
└── dirB
    ├── 1
    │   ├── file
    │   └── safe
    ├── 2
    │   ├── file
    │   └── safe
    └── 3
        ├── file
        └── safe

8 directories, 12 files

Problem Data

Copy the blob below and do:

$ pbpaste | base64 --decode | tar -x

(use tar -t to list contents if you don't trust me)

H4sIAMTXy1QAA+2cy07bQBSGs6uUJ+jSLwDM1XZUZQEtKqhURdCLKnVjiEFRwVRJqOiuj9W36EP0
RWo7NWniIcRmcmZa/m8TNAqyifN/c3J8wmFys5cmg3S0dTa8SDdOr75825ik40nHIoyxSOugE5XM
HtkfhI4CLlQoIi2l4gETQmjVCW5snsRdXI8nySg/lfRmsnlyMkqzLMlMzzvaf/P25fbr3eNPL64u
k2EWvBuno/HcH5kT3D7+I/AoOB8O+r2e1lEYM9nNF67zBS4501L3RFew4HQyvEz7XAkRKtULebGW
/LWmecS6Mg4O9ne2j57v7b/f3TwdpfkzrrK539SqK2RwnD/j4OPmIP3a52H+RhA87gpRLQ+zq77Q
cRjJ/FziajW7GGaf+6rr+uX675hP/dZajlHl/3v+85OfP54Wj88+vPrFZizkn/NIdgK9lrNZ4JHn
f+H6H95uB4PhaNvSMRr5X6v8+ksuI/ifghb+j0Rr/8cN/K9Uzf8a/rfNQv6L1FvfBBr5v8y/YDqE
/ylY5v8dS8do4n8lxdT/Gv6noLH/NSt03c7/xSeHlf2vGfy/fur+33Hq/2n+c/8r+J8C0/WfbQLc
yjEa+T8MC/9Lhv4PCS38r8J2/p/uHKv6P843i0X/S/jfNqb8c8s7QCP/l/nPQf+HhOX+F1aO0cr/
qP9J8Nj/Av5fP6b8Cx/8j/qfhOX+l1aO0cr/IfxPgcf+r9//hf+tY8q/9MH/Gv6nwHz9ZzvAODlL
H3qM/PUIlVrif84Xrr8SDPd/SbDj/3JtZbP36mbnMLsbzPm3kfoZVf6/d1b1vyz7/8zeKdzNI8+/
+fOfB/5H/U+CE//XOzvwvyPM+ffA/xL+p8B8/8cD/6P/T4IT/9fv7ML/jjDn3wP/C/ifAtP8r9P5
H1HOf4ri+x/w//ppM//JWs9/9hrMf0b4/hcBpvw7nf8p8y8EF+j/U7Dc/w7mfyr/Y/6TBFL/R03m
/6MQ/l8/pvw7nf+p/I/5TxKW+9/B/E/lf/R/SKD1v2jg/7jeJYL/rWPKv9P5n8r/mP8kwXz9D+f+
K9BDj8Ga9P+5LPr/PML8Dwkt/J8/qdb/L9ZW7v9zzP94gzn/NlI/gzXp/5f5l0xh/oeE+/x/noxO
kvOHvRka+b/c/1WoGfxPgZ36v1xb2f8ihv99wZx/G6mf0cj/08//mmv4nwJz/8+D+h/znyQ4qf8x
/+kN5vx7UP9j/pOE+/zvqv5X6P+Q4KT+j+B/XzDn34P6H/0fEszzXx7U/7j/S4KT+h/z/95gzr8H
9T/m/0m4z//O6n/0f0hwUv/XJzvhf0eY8+9B/Y/+DwAAAAAAAABY5TdRxdowAHgAAA==

My Solution

Copy the blob below and do:

$ pbpaste | base64 --decode | less
VGhpcyBpcyBob3cgSSBzb2x2ZWQgaXQ6CgpgYGBiYXNoCiQgbHMKZGlyQS8gZGlyQi8KCiQgKGNk
IGRpckEgPiAvZGV2L251bGwgJiYgdGFyIC1jICovZmlsZSkgfCAoY2QgZGlyQiAmJiB0YXIgLXgp
CmBgYAoKVGhpcyB3b3JrcyBiZWNhdXNlIGB0YXJgIGZpbGVzIGtlZXAgdGhlIHJlbGF0aXZlIGRp
cmVjdG9yeSBzdHJ1Y3R1cmUKaW50YWN0IHdoZW4gY3JlYXRpbmcgdGhlIGFyY2hpdmUgYW5kIHdo
ZW4gdW5wYWNraW5nIHRoZSBhcmNoaXZlLCBpdAptZXJnZXMgZGlyZWN0b3JpZXMgY29udGVudHMg
cmF0aGVyIHRoYW4gcmVwbGFjaW5nIGRpcmVjdG9yaWVzCmNvbXBsZXRlbHkuCg==
@brianloveswords
Copy link
Author

Updated to use --decode for base64 flag to make more portable between coreutils version and Apple provided version (decode flag for coreutils: -d, apple: -D)

@gnarf
Copy link

gnarf commented Jan 30, 2015

In keeping with your base64 hashing -- my solution:

Y2QgZGlyQSA7IGZvciBmIGluICovZmlsZTsgZG8gY3AgJGYgLi4vZGlyQi8kZjsgZG9uZQ==

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment