Jump to content

cp question [solved]


Deo Favente
 Share

Recommended Posts

Hi,

i have a question on how to use the cp command. I already comepleted the job, but i would like to know how i could use cp to shorten what i did so i could learn how to use it next time.

So for work i needed to copy a bunch of files. This is what my directory tree looks like:

img001jh2.th.gif

there are 48 directories in level 1. The directories below don't always exsist in all 48 direcetories, but i want the directories abc, def, and ghi and their contents copied over to /usr/somedirectories/lib/

so that there will be lib/abc, lib/def, and lib/ghi. All files have different names (or should- there might be one or two human errors i can take care of manually, never know) so i want everything to merge, and there are plenty of duplicate folders and some folders might be empty.

My current idea is

cp */*/{abc,def,ghi,jkl,mno} /usr/somedirectories/lib/

does this work? what's wrong with it? I've already copmpleted the job so i cant try it on anything.

Link to comment
Share on other sites

Well what do you know. I tottally forgot i do have another chance to try it! But this time i have 4 levels between the top and the abc, def, ghi folders. So i tried my idea and it didnt work. It printed out "cp: omitting directory " then it listed all the directories that matched, and at the end it printed out "cp: cannot stat */*/*/*/jkl" cause it didnt match any folders. I also learned that all the second level folders were named the same thing cool. So then i tried

cp -R */xyz/*/*/{abc,def,ghi,jkl,mno} usr/somedirectories/lib/

and that worked yay! I hope i remember to prepend [solved] to the topic title.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...