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.
less
?