Chapter 14. Elless Island
Now you know that the girls are just making it up Now you know that the boys are just pushing their luck Now you know that my ride doesn’t really exist And my name’s not really on that list
They Might Be Giants, “Prevenge” (2004)
In this final chapter, you’ll create a Rust clone of the list command, ls
(pronounced ell-ess), which I think is perhaps the hardest-working program in Unix.
I use it many times every day to view the contents of a directory or inspect the size or permissions of some files.
The original program has more than three dozen options, but the challenge program will implement only a few features, such as printing the contents of directories or lists of files along with their permissions, sizes, and modification times.
Note that this challenge program relies on ideas of files and ownership that are specific to Unix and so will not work on Windows.
I suggest Windows users install Windows Subsystem for Linux to write and test the program in that environment.
In this chapter, you will learn how to do the following:
-
Query and visually represent a file’s permissions
-
Add a method to a custom type using an implementation
-
Create a module in a separate file to organize code
-
Use text tables to create aligned columns of output
-
Create documentation comments
How ls Works
To see what will be expected of the challenge program, start by looking at the manual page for the BSD ls
.
You’ll see that it has 39 options. I’ll include only ...
Get Command-Line Rust now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.