3

Somehow I accidentally overwrote my ~/bin.

I typed the command: $ cp /home/dsg/Downloads/sbt-launch-0.7.4.jar ~/bin

I was trying to copy the file into my bin folder but instead overwrote the folder.

Now:

$ cd ~/bin
bash: cd: /home/dsg/bin: Not a directory

And:

$ diff /home/dsg/Downloads/sbt-launch-0.7.4.jar ~/bin

Shows no differences.

What do I do?

Hennes
  • 65,142
dsg
  • 1,189
  • 3
    Restore from backup? – Daniel Beck Mar 22 '11 at 05:37
  • No backup. Is there a way to restore to default? It is almost a fresh install, so there shouldn't have been much there. I am trying to avoid a reinstall of the whole system. – dsg Mar 22 '11 at 05:48
  • 2
    @dsg: By default, ~/bin does not exist. You must have created it yourself. rm -f ~/bin && mkdir ~/bin – u1686_grawity Mar 22 '11 at 05:51
  • 3
    To add to grawity's comment, if ~/bin had existed as a directory prior to the cp command, the cp command would have copied the .jar file into ~/bin, not replaced ~/bin. So I don't think there was a ~/bin directory before the cp command. – garyjohn Mar 22 '11 at 06:00
  • Oh, excellent! Thanks! @garyjohn , confirmed. I have just rm ~/bin and mkdir ~/bin, and now when I do a copy the file is moved into the directory as you say. – dsg Mar 22 '11 at 06:10
  • @dsg: if that resolved your question, you should add it as an answer and then accept it (or even better, @grawity should do it) – Olli Mar 22 '11 at 07:24

1 Answers1

6

When you copy a file using the command you used:

$ cp /home/dsg/Downloads/sbt-launch-0.7.4.jar ~/bin

different things happen depending on what the target is.

1) ~/bin is a directory

The file will be copied into the ~/bin directory keeping the original name of the file.

2) ~/bin is a regular file

The file ~/bin will be overwritten by the source file.

3) ~/bin does not exist

The source file will be copied to the destination name creating a new file.

By default the ~/bin directory doesn't exist, so unless you created a directory at some time in the past called ~/bin then option 3 will be what happened. If there was a ~/bin in existance, then for the cp command to overwrite it it must have been a regular file and not a directory.

You should delete the ~/bin file and create a directory with:

$ rm ~/bin
$ mkdir ~/bin

Then you can copy the jar file into it with the same command you used before.

(Thanks to @grawity and @garyjohn on whose comments to the question this answer was based upon.)

Majenko
  • 32,428