Let's Rewrite Linux 'ls' command: Getting the list of files and their info
In this article we will start collecting info about files
If you want to know more about command, please read Part 1.
If you want to know how we configured tests, check Part 2.
Note: Source codes can be found at: https://github.com/Miradils-Blog/linux-ls
Getting the list of files First things first, our file structure looks like this (tree command was used for output):
We have separate folder with different types of files for us to cover all cases. For now, we will hard-code the folder where listing will happen, just focusing on functionality. So, how do we get the list of all files and their respective data about ownership, size, links etc.? Lucky for us, C provides function for this (and honestly, for everything else as well):