Tuesday, August 28, 2018

file recovery - overwrote ~/bin folder


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?


Answer



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


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...