This week is all about files.
Unix/Linux file tree
(We say it’s “tree structured”, but symlinks actually make it into a graph)
It does not lead to redundency, but it is safer and more readable. If you have a runnable file named
ls which deletes all important files, then when you run actual ls in your terminal, catastrophe happens. Luckily you have to type
./ls to run your dangerous program but
ls to run the programs in PATH.
In Unix, a file descriptor is a none negative integer, which maps to files in the Unix process. The total amount of descriptors has limitation.
Closing files after use matters
Each opened file occupies a file descriptor, and if you do not close the file after use, you will end up with cannot open more files when you open many files. It is essential to close a file when dealing with large amount of files.