1

For example, I use find command find /usr/share/icons -iname 'foxitreader*' find the files:

/usr/share/icons/hicolor/32x32/apps/FoxitReader.png
/usr/share/icons/hicolor/48x48/apps/FoxitReader.png
/usr/share/icons/hicolor/64x64/apps/FoxitReader.png
/usr/share/icons/hicolor/128x128/apps/FoxitReader.png
/usr/share/icons/hicolor/16x16/apps/FoxitReader.png

and I want to use xargs copy them to the .local/share/icons/, and in the icons directory has the same subdirectory structure, which is:

 └── hicolor
    ├── 16x16
    │   └── apps
    │       ├── 1B94_WScript.0.png
    │       ├── 1CD8_rundll32.0.png
    │       ├── 1E64_notepad.0.png
    │       ├── 2402_msiexec.0.png
    │       
    ├── 24x24
    │   └── apps
    │       ├── 6C56_Timwp.0.png
    │       └── FoxitReader.png
    ├── 256x256
    │   └── apps
    │       ├── 1E64_notepad.0.png
    │       ├── 2402_msiexec.0.png
    │       ├── 2EF4_wordpad.0.png
    ├── 32x32
    │   └── apps
    │       ├── 1B94_WScript.0.png
    │       ├── 1CD8_rundll32.0.png
    │       ├── 1E64_notepad.0.png
    └── 48x48
        └── apps
            ├── 1CD8_rundll32.0.png
            ├── 1E64_notepad.0.png
            ├── 2402_msiexec.0.png

and I just want to copy the files I find, not the whole directory structure, so how can I copy these files to the corresponding directory, like this:
/usr/share/icons/hicolor/32x32/apps/FoxitReader.png to the .local/share/icons/32x32/apps/FoxitReader.png, etc.
And the icons directory already have these subdirectories, and it's not empty, so you can't just use cp to merge them, and I use find to find the files, and want to use xargs to copy them once a time, not more times manually.

18
  • why do not you try to do it manually
    – bhordupur
    Apr 25, 2016 at 15:56
  • In one command to handle it, it is convenient.
    – zhenguoli
    Apr 26, 2016 at 1:33
  • @JacobVlijm, it is different, I know the basic cp commands, and I have used the command for a while, what I want to know is a specific problem to the cp command, maybe there is my terrible description confusing you. I want to use find and xargs command to copy the files once a time, not more times.
    – zhenguoli
    Apr 28, 2016 at 5:03
  • Not exactly, @JacobVlijm, I think I should describe my problem more speicifically.
    – zhenguoli
    Apr 28, 2016 at 5:07
  • Ah, the "I just want to copy the files I find, not the whole directory structur" is a new element. How do you find these items? what is the command. The (only) difference with my answer is then that it only should copy listed files, not all. right? Apr 28, 2016 at 5:20

1 Answer 1

1

You can do this in bash by enabling extended globbing.

shopt -s extglob

and then use the --parents options of cp.

So, go to /usr/share/icons/hicolor/ and do:

cp -R --parent {128x128,32x32}/apps ~/.local/share/icons/

Modify the directory names within {} to suit your needs.

Eg:

ron@ron:~$ tree dir1/          # Destination before copying
dir1/
├── 128x128
│   └── apps
├── 16x16
│   └── apps
├── 32x32
│   └── apps
└── 48x48
    └── apps
karthik@4736Z:~/dir2$ ls hicolor/            # Source structure
128x128  22x22    32     42x42  512x512  72x72  icons             scalable
16x16    24x24    32x32  48     64       8x8    icon-theme.cache  symbolic
192x192  256x256  36x36  48x48  64x64    96x96  index.theme
ron@ron:~/dir2$ tree hicolor/ | head -n 6
hicolor/
├── 128x128
│   ├── actions
│   ├── animations
│   ├── apps
│   │   ├── amazon-store.png
ron@ron:~/dir2/hicolor$ cd hicolor/    
ron@ron:~/dir2/hicolor$ cp -R --parent {128x128,32x32}/apps ../../dir1/
ron@ron:~/dir2/hicolor$ tree ../../dir1/          # Destination after copying
../../dir1/
├── 128x128
│   └── apps
│       ├── amazon-store.png
│       ├── chromium-browser.png
│       ├── credentials-preferences.png
│       ├── deluge.png
│       ├── display-im6.q16.png
│       ├── libreoffice-base.png
│       ├── libreoffice-calc.png
│       ├── libreoffice-draw.png
│       ├── libreoffice-impress.png
│       ├── libreoffice-main.png
│       ├── libreoffice-math.png
│       ├── libreoffice-startcenter.png
│       ├── libreoffice-writer.png
│       ├── ubuntuone-music.png
│       ├── ubuntusoftware.svg
│       ├── vivaldi.png
│       ├── vlc.png
│       └── vlc-xmas.png
├── 16x16
│   └── apps
├── 32x32
│   └── apps
│       ├── aim.png
│       ├── baobab.png
│       ├── bluetooth.png
3
  • What I means is that, the icons already have the directory structure, please see what I have edited, you may misunderstand my meanings. @Ron
    – zhenguoli
    Apr 26, 2016 at 1:28
  • I use the find command, and I want to copy all the files with the same basename I find to the corresponding directory, just like diff -r do to compare the same subdirectory structure, not just one directory.
    – zhenguoli
    Apr 26, 2016 at 4:38
  • I may have misunderstood your intentions. I've updated my answer. See if it works for you.
    – Ron
    Apr 26, 2016 at 12:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .