I was trying to use the following command to pipe the results to less so that I could read a listing fully:

ls -lh | less

This, according to various sources pipe the contents to less and allow viewing the listing in a new file. Instead, though, it overwrote my less command. I used vi to view less and it indeed was now a listing of the folder I was in.

I believe the reason was because I was within the /usr/bin/ folder when I used the command, where less lives. Yes, I've reviewed my steps in the command log, only cd and ls were before and after it being overwritten and the modification time matches when I ran the above command. And yes, I'm the only user with root access.

So, now that less has been destroyed, how do I reinstall just that file?

The server is CENTOS 4.9 (Final) and uname -a returns:

Linux server.name.com 2.6.9-89.0.16.EL #1 Tue Nov 3 17:15:02 EST 2009 i686 i686 i386 GNU/Linux

I do need to do a OS reload/upgrade at some point as cPanel no longer supports CENTOS 4, but in the meantime, I want less back. I can use vi or more in place of it as well.

--- Edited to add ---

I know everyone is going to say this repeatedly that it can't happen as described, but here is the actual list of what was done step by step:

> /usr/sbin/exim -bp > /home/<username>/<filename>.log (created Feb 4 21:03)
> less -N /home/<username>/<filename>.log (less was working fine)
> top
> df -P
> cd /usr
> ls -l
> cd games
> ls -l
> cd ..
> cd lib
> ls -l
> cd ..
> ls -l
> cd etc
> ls -l
> cd ..
> cd bin
> ls -lh
> ls -lh | less (less reports created Feb 4 21:22)
(this started trying to run every line in the listing like a shell script. I was confused about this error, so I did some looking online for an answer - none found. So I decide to send the output to a file instead.)
> ls -lh
> ls -lh > /home/<username>/ls (created Feb 4 21:42)
> less /home/<username>/ls (output is the same with it trying to run every line in the listing as a shell script)
> ls -lh > /home/sbaldwin/ls.log (wondering if calling a file ls messed up things, I retry to > output to a file)
> ls -lh /home/sbaldwin/ls.log (check to see the file size)
> less /home/sbaldwin/ls.log (same result as before)
> less (same result)
> top
> more (functioning normally)
> vi (functioning normally)
> less (same result)
> exit (tried exiting and returning, and seeing if a process is running for less)
> less (same result)
> vi /usr/bin/less (Now I see that it is the directory listing of '/usr/bin'
> ls -lh /usr/bin/less
-rwxr-xr-x  1 root root 74K Feb  4 21:22 /usr/bin/less*

To the naysayers that attest that this can't happen, there it is. No one else has root access, I was the only one logged in to SSH, and no other commands were run other than above. For what it is worth, maybe it is a bug, if you run ls -lh | less in the /usr/bin/ folder where a link to less is located, it might just write over your less file. If you are 100% certain this can't happen, by all means try it. Again, it might be limited to CENTOS 4.9.

  • The command you mentioned won't overwrite or delete anything. You can't use vi to examine the less binary and get useful results either. You may not have less installed? What happens when you just run less? – Max Sherman Feb 5 '13 at 4:28
  • Running less results in it trying to run every line in the less file, which is now the output of a listing. Trust me, the less file has been overwritten. Maybe it is a bug specific to CENTOS 4.9, but the only commands I ran since my last using less were cd, df, and ls. – Exit Feb 5 '13 at 5:37
  • I've amended my question above to clear up what happened. – Exit Feb 5 '13 at 6:08

The command you posted should not have overwritten less, but let's not dwell on details.

I'm not sure what it means to say, "cPanel no longer supports CENTOS 4", but if the CentOS 4 repos no longer work on your system, then download the less RPM from the CentOS distribution and forcefully reinstall it.

wget http://vault.centos.org/4.9/os/i386/CentOS/RPMS/less-382-4.rhel4.i386.rpm
rpm -Uvh --force less-382-4.rhel4.i386.rpm

That will forcefully overwrite any packages installed by the less RPM, including the modified less binary.

| improve this answer | |
  • Thanks for the response. That probably will be the best solution, though I was hoping to just upload the one file and be done with it. I have added some custom shell scripts and don't want anything to disappear. Also, this is a cPanel server and there might be special considerations there as well. This is why I would want to only replace the one file. As for cPanel, cPanel servers are licensed and auto-update cPanel unless disabled. To run the new version of cPanel, it requires CENTOS 5. – Exit Feb 5 '13 at 6:15
  • This procedure will just replace the files listed in the RPM. It's your choice whether this is acceptable in your situation or not. – fuero Feb 5 '13 at 8:00
  • @Exit The only thing that will disappear is the mistake. – Michael Hampton Feb 5 '13 at 8:12

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.