Some time ago I a found an interesting question about FreeBSD on https://www.reddit.com/r/freebsd/: “How can I restore the ls command?”
The comments gave several solutions: copy/use the statically linked ‘ls’ in the /rescue directory, download base.txz from ftp.freebsd.org for extracting ‘ls’, install the port of ‘GNU ls’, and so on. I didn’t know these solutions, they are good to know; anyway in that time I was customizing some utility on my FreeBSD Laptop, so I suggested another solution.
My solution is very simple, it exploits an awesome feature: FreeBSD is a complete Operating System, the source code of ‘ls’ is in /usr/src with the kernel, installer, libraries, and so on.
If /usr/src is empty:
# git clone --depth 1 https://git.freebsd.org/src.git /usr/src
Build and install ‘ls’:
# cd /usr/src/bin/ls # make# make install
It’s all, Happy BSD Hacking!