#
Project 1
#
Remaking ls
The idea of these "learning projects" is to give a rather open-ended challenge with just enough information to get googling. Some hints are given, and some links are provided, but not everything is directly referenced or explained. You can feel free to ask your leads for assistance, but be warned that they'll ask what you've googled first!
If you're at all familiar with navigating the file system via command line, there's one utility you make frequent use of: ls
.
What's just as important as knowing where you are? Well, knowing what's in where you are! Being that it's one of the simplest
utilities and most commonly used, it's a prime target for learning a variety of skills.
As the title of this project suggests, we seek to recreate the functionality of ls
by hand. Before continuing, it might be a
good idea to make sure you understand the functionality of ls
as best as possible. What utilites exist to tell you the complete
functionality of a command?
#
Prerequisite Experience
While you are expected to run into things you haven't seen before, this project is intended for those that have at least some experience navigating a file system via the command line. Similarly, you should know how to create and edit files, and you should be somewhat familiar with ls
as a tool.
#
Objectives
Upon completing this project, we expect that you have:
- Gained a slightly more in-depth understanding of
ls
's functionality - Gained an understanding of how to interface with files and directories in your language of choice.
#
Description & Targets
As stated above, our goal in this project is to replicate the functionality of ls
. This can be done in the language of your choice. While Python's probably easiest, if you prefer another language, feel free to use it! In the event you would like to test your
results against the examples shown here, a zipped example directory is given below. Simply unzip that and then test your
implementation within it.
Note
Examples will all assume Python as the language of choice. It is assumed that if you are using something else, you know what should be replaced.
As the bare minimum, you should make sure your implementation simply lists the files in the working directory. If the bare minimum is executed in the example directory, we should expect to see the following:
$ python3 my_ls.py
bar.txt
example_script.sh
foobar.sh
foo.txt
ls_bare_min.txt
this_file_doesnt_have_an_extension
this_is_a_dir/
Then, you should aim to make the program a standalone executable, i.e. be able to run the program without directly
invoking the interpreter/compiler. This would look like python3 my_ls.py
above being replaced by simply ./my_ls.py
. Hint: It's all in the shebang.
For an added challenge, figure out what must be done in order to omit the ./
.
Finally, as part of the standard targets of this project, you should add the ability to input the path to a directory to list, rather than the program only listing the current directory.
Stretch targets (ordered by possible difficulty):
- Add a "-h/--help" flag
- Display some info about each file (permissions, last access time, etc.)
- Additionally, toggle sorting via a command line flag
- Choose which parameter to sort by via a command line arg
#
Feedback
The learning projects are in their infancy, and we'd greatly appreciate any feedback you'd be willing to share with us! Share your anonymous feedback here. Thanks!