Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Or learn to avoid the problem' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Or learn to avoid the problem
Authored by: tim-wood-MacOSXH on Nov 16, '05 10:37:29AM

I've lived in multiple unix worlds for a while and versions of this "problem" come. The basic problem is seen in the discussion here. Some people see the slash and say "ah, stuff inside the folder". Other people see the slash and say "ah, the folder". Surprise, surpise... those who programmed the different shells (tcsh, bash, sh, etc) are people, too.

Like a lot of things unix, you can come up with a simple approach that works across _all_ shells and not have to hack each computer you use.

An example is using cp -R instead of cp -r. Both mean recursive (e.g. go through all the nested folders) but a lot of unix commands only recognize the -R. Computers are so darn literal sometimes.

Back to the problem at hand... I avoid the problem by (begin really deep insight) explicitly telling the computer whether I want to deal with a folder _or_ all the stuff in it.

If I want the directory, I'll leave off the slash:

cp -R stuff ~/

If i want to the stuff in the directory, I'll add a slash and the wildcard:

cp -R stuff/* ~/

The final fly-in-the-ointment is that dot files (i.e. files whose names begins with a dash) are hidden from view by default and sometimes will not copy this way, so you may have to do a second copy by putting /.* on the end of the directory name:

cp -R stuff/.* ~/



[ Reply to This | # ]
Or learn to avoid the problem
Authored by: thadman08 on Nov 17, '05 05:50:57AM

You have to be careful with '~/folder/.*'. That covers the dot-files, yes, but it also covers 'dot' and 'dot dot', meaning the folder itselft and the parent folder.

Depending on the command you are using, this can affect a few more files than you might think.



[ Reply to This | # ]
Or learn to avoid the problem - better solution for dotfiles
Authored by: nickp on Nov 18, '05 08:58:00PM
As thadman08 pointed out, .* matches .. as well as the intended dotfiles.

My incantation to get around this was to use .[A-z]*

Un*x sux, btw. Fifty years of computer science and here we are arguing about how to copy some goddamn files ...

[ Reply to This | # ]