Tiny from-scratch rewrites of
cat,echo, andgrepin C, built to get comfortable with the standard I/O and string libraries before moving on to bigger systems work.
Three single-file utilities that mirror the basic behavior of their GNU coreutils namesake. No external dependencies beyond the C standard library. The goal is to learn development in an embedded environment as well as learning how memory management works and to get the core file I/O and string-handling patterns down by simply reading a file byte-by-byte, walking argv, and scanning line buffers.
| Program | Mirrors | What it does |
|---|---|---|
cat.c |
cat |
Opens each file argument and streams its contents to stdout one character at a time via fgetc. |
echo.c |
echo |
Prints its arguments space-separated. Supports -n to suppress the trailing newline. |
grep.c |
grep |
Reads each file line-by-line into a fixed 2048-byte buffer and prints any line containing the search term via strstr. |
catandgrepboth fail gracefully per-file. The program prints an error if one file in the argument list can't be opened and continues with the rest rather than just exiting.grepuses a fixed-size line buffer rather than dynamic allocation, so it's a simplified single-substring matcher, not a real regex engine.- Flags for line numbers, recursion, and case-insensitivity were left out on purpose to keep the first pass focused on plain file I/O.
Just a standard C compiler (GCC / Clang). Each utility compiles independently.
Linux / macOS
gcc cat.c -o cat
gcc echo.c -o echo
gcc grep.c -o grepWindows (MinGW / GCC)
gcc cat.c -o cat.exe
gcc echo.c -o echo.exe
gcc grep.c -o grep.exeUsage
./cat file.txt
./echo -n hello world
./grep search_term file.txtpowered by logic, coffee, and many sleepless nights