I have accidently deleted /bin/hostname. Termporarily I have put in a shell script there that returns the known name. But how do I recover the lost binary?

It is an AWS AMI.

Linux ip-10-2-0-162 3.4.62-53.42.amzn1.x86_64 #1 SMP Fri Sep 20 07:23:24 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
  • 3
    Build another identical instance, copy the file from the working instance? – Zoredache Nov 15 '14 at 1:37
  • @Zoredache I actually do have an identical instance, Thanks!! BTW, this should have been in an "answer" – Dinesh Nov 15 '14 at 1:41

Other than copying the file from another instance you can also reinstall the package (via yum reinstall $package), e.g.:

[root@localhost ~]# rpm -qf /bin/hostname
[root@localhost ~]# ls -l /bin/hostname
ls: cannot access /bin/hostname: No such file or directory
[root@localhost ~]# yum reinstall net-tools
Running Transaction
  Installing : net-tools-1.60-110.el6_2.x86_64                                                                                                                           1/1 
  Verifying  : net-tools-1.60-110.el6_2.x86_64                                                                                                                       1/1 

  net-tools.x86_64 0:1.60-110.el6_2                                                                                                                                      

[root@localhost ~]# ls -l /bin/hostname 
-rwxr-xr-x 1 root root 13712 May 10  2012 /bin/hostname
  • I already fixed my issue but this appears definitely the right approach – Dinesh Nov 16 '14 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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