You are not logged in.

#1 2010-08-31 05:10:12

r6
Member
From: Melbourne
Registered: 2008-07-02
Posts: 156

[SOLVED] Stupid bash question (cp command)

I accidentally copied a file using * as the destination, like this:

cp /path/to/file *

There was no error so it must have done something but I can't figure out what.

Can anyone tell me what that command does, thanks.

Last edited by r6 (2010-08-31 07:15:29)

Offline

#2 2010-08-31 05:18:02

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [SOLVED] Stupid bash question (cp command)

* is expanded to all the files in your current directory except for ones beginning with a dot.

cp with multiple (n) files listed will copy the first n-1 files to the nth file which should be a directory.

In the future use the -i option to avoid mistakes like this.

Last edited by fsckd (2010-08-31 05:19:43)


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#3 2010-08-31 05:34:06

r6
Member
From: Melbourne
Registered: 2008-07-02
Posts: 156

Re: [SOLVED] Stupid bash question (cp command)

OK, I see that now. It copied everything into the last file (directory) in the list. Interesting, thanks.

Offline

#4 2010-08-31 07:01:31

quigybo
Member
Registered: 2009-01-15
Posts: 223

Re: [SOLVED] Stupid bash question (cp command)

Hehe getting used to the terminal in the beginning can be fun, you are bound to make some mistakes - I still do at times tongue

In the mean time adding these to your .bashrc could be helpful safer:

alias mv="mv -i"
alias cp="cp -i"
alias rm="rm -i"

Offline

Board footer

Powered by FluxBB