woodwardiocom: (Coding)
[personal profile] woodwardiocom
-Question: If in Unix you accidentally type "cp *.html", and there's (say) half-a-dozen html files in the directory, what does Unix do?

Date: 2007-02-15 04:23 pm (UTC)
From: [identity profile] ariesd.livejournal.com
well with 2 files the first one overwrites the 2nd, with many it seems to ask for more param's.

Date: 2007-02-15 04:32 pm (UTC)
ckd: (cpu)
From: [personal profile] ckd
Yup. Unless the lexicographically last item is really a directory, in which case it will copy all the other items into it.

The important thing to remember about Unix command lines is that the shell, not the program, does the expansion of wildcards.

In a directory with a.html b.html:
cp *.html becomes cp a.html b.html

In a directory with a.html b.html c.html:
cp *.html becomes cp a.html b.html c.html

Date: 2007-02-15 04:29 pm (UTC)
From: [identity profile] caulay.livejournal.com
That, I suspect, is one of those answers that will be "implementation specific".

What I have seen happen is that you can get 1) the first .html file gets over written by each .html file in sequence, leaving you with, at the end, two copies of the contents of the last one; 2) the first .html file gets overwritten with the contents of all the other .html files, including itself, concatenated together; 3) all the .html files get copied to a new file with a blank file name, overwriting that file one at a time; 4) the .html files get concatenated together into a new file with a blank file name and 5) each .html file gets copied to a new file with a blank file name, giving you as many "blank name" files as you had .html files.

Date: 2007-02-15 05:01 pm (UTC)
beowabbit: (Geek: Mac 64)
From: [personal profile] beowabbit
Not quite. What [livejournal.com profile] ckd said above.

The reason you’ve seen various kinds of behaviour on commands like this is that it depends on whether the (lexicographically) last name on the command line after expansion is a directory or not, and if not, it depends on whether there are exactly two files in the directory.

Theoretically, you could have a directory named zzzz.html/ in the current directory, so that the last pathname on the command line after expanding *.html would be a directory, but it’s pretty unlikely.

Date: 2007-02-15 04:55 pm (UTC)
From: [identity profile] szasz.livejournal.com
Standard cp has two acceptable syntaxes:

cp sourcefile destfile
cp sourcefile1 ... sourcefilen destdirectory

So if there are two files, it will copy the alphabetically first one on top of the second one. If there are three or more, because the last one will not be a directory, the command should fail with something similar to "cp: copying multiple files, but last argument `c.foo' is not a directory".

There may be some implementation-specific cautions here, but as far as I know the command line syntax for 'cp' has been pretty well standardized for some time now, since it is one of the very oldest Unix commands.

Date: 2007-02-16 07:54 am (UTC)
From: [identity profile] mbarr.livejournal.com
To sum it all up: It depends :)

Ain't I helpful?

Profile

woodwardiocom: (Default)
woodwardiocom

February 2020

S M T W T F S
      1
23 4 5678
9101112131415
16171819202122
23242526272829

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Apr. 15th, 2026 10:24 pm
Powered by Dreamwidth Studios