Tuesday, May 7, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 3896  / 1 Year ago, sat, march 18, 2023, 3:16:51

I just found out about /bin/true yesterday. I'm not a bash power user by any means, but I decided to check it out. I was surprised to find that it is a 22K file (Ubuntu 12.04), and not one of the smallest utilities in /bin (e.g. kill is smaller). This is really just curiosity, but is there are reason for it not to be a very small bit of code? How would I go about finding the source code for /bin/true?


More From » bash

 Answers
5

Well, looking into the sources of the coreutils tools, true is one of the smallest. It is smaller than kill, though larger than false which is the very smallest:



$ for i in src/*c; do wc -l $i; done | sort -nr | tail -11
78 src/true.c
74 src/operand2sig.c
73 src/sync.c
37 src/prog-fprintf.c
2 src/uname-uname.c
2 src/uname-arch.c
2 src/ls-vdir.c
2 src/ls-ls.c
2 src/ls-dir.c
2 src/lbracket.c
2 src/false.c


So, true has 78 lines, but only 58 of them are actually code (the rest are blank lines and comments):



$ grep . src/true.c | awk '{ if(//*/){a=0} if(a){print} if(/*//){a=1}}' | wc
50


And yes, a lot of that (10 lines) are dedicated to the usage function. The program is still tiny though.



Also, the reason that false is tinier is that it simply calls true:



$ cat src/false.c
#define EXIT_STATUS EXIT_FAILURE
#include "true.c"

[#25729] Saturday, March 18, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ousear

Total Points: 395
Total Questions: 114
Total Answers: 89

Location: Jordan
Member since Thu, Aug 5, 2021
3 Years ago
ousear questions
Tue, Sep 27, 22, 03:29, 2 Years ago
Thu, Nov 25, 21, 00:51, 3 Years ago
Tue, Feb 22, 22, 17:47, 2 Years ago
;