Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
3  
Restore from backup? –  Daniel Beck Mar 22 '11 at 5: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 5:48
2  
@dsg: By default, ~/bin does not exist. You must have created it yourself. rm -f ~/bin && mkdir ~/bin –  grawity Mar 22 '11 at 5: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 6: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 6:10

1 Answer 1

up vote 5 down vote accepted

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.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.