I finally finished exercise 4 for the MIT Missing Semester course Lecture 2 exercises. I wrote a command that found all HTML files and produced a zip file containing all of them. It took me a while but I got it done!
TLDR;
Okay, so here are the highlights of what I did:
- Finished my solution for exercise 4 from MIT Missing Semester Course.
- Started working on my solution for exercise 5.
- Continued working on my notes for the
find
command and thezip command
.
Exercise 4 Solution
The solution was not long but for my inexperienced self it was complicated enough to give me a run for my money. Previously I had never really used the find
or zip
commands. Learning how to use the programs with all their features took me a while.
One thing I can definitely say is that YouTube helped me out a lot. The manual is a good reference when you already know how things work but watching a live video made everything clear for me.
Anyways, here is my solution below.
# Solution will recursively find all .html files and then zip them altogether without their preceding directories into the zip_html.zip file.
find -name "*.html" | zip -j zip_html -@
I didn’t use the xargs
program which was mentioned in the question so I might have made a mistake. Ultimately it’s about learning so I am not too worried about it. I will get comfortable using all these programs soon enough.
Exercise 5
(Advanced) Write a command or script to recursively find the most recently modified file in a directory. More generally, can you list all files by recency?
I’m not entirely sure how this will work but I did start my search with everyone’s friend Stack Overflow
New find
command notes
I still haven’t fully refined the manual notes but I have started to group the related options together so it makes a bit more sense.
Tests
Some tests, for example -newerXY
and -samefile
, allow comparison between the file currently being examined and some reference file specified on the command line. When these tests are used, the interpretation of the reference file is determined by the options -H
, -L
and -P
and any previous -follow
, but the reference file is only examined once, at the time the command line is parsed. If the reference file cannot be examined (for example, the stat(2) system call fails for it), an error message is issued, and find exits with a nonzero status.
A numeric argument n
can be specified to tests (like -amin
, -mtime
, -gid
, -inum
, -links
, -size
, -uid
and -used
) as
+n
for greater than n,-n
for less than n,n
for exactly n.
Access Time / Change Time Tests:
Option | Description |
---|---|
-amin n | File was last accessed less than, more than or exactly n minutes ago. |
-atime n | File was last accessed less than, more than or exactly n * 24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1 , a file has to have been accessed at least two days ago ({ 2,3,4,5 } > 1 ). |
-anewer reference | Time of the last access of the current file is more recent than that of the last data modification of the reference file. If reference is a symbolic link and the -H option or the -L option is in effect, then the time of the last data modification of the file it points to is always used. |
-cmin n | File’s status was last changed less than, more than or exactly n minutes ago. |
-ctime n | File’s status was last changed less than, more than or exactly n * 24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times. |
-cnewer reference | Time of the last status change of the current file is more recent than that of the last data modification of the reference file. If reference is a symbolic link and the -H option or the -L option is in effect, then the time of the last data modification of the file it points to is always used. |
-mmin n | File’s data was last modified less than, more than or exactly n minutes ago. |
-mtime n | File’s data was last modified less than, more than or exactly n * 24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times. |
-newer reference | Time of the last data modification of the current file is more recent than that of the last data modification of the reference file. If reference is a symbolic link and the -H option or the -L option is in effect, then the time of the last data modification of the file it points to is always used. |
*-newerXY reference | Time of the last data modification of the current file is more recent than that of the last data modification of the reference file. If reference is a symbolic link and the -H option or the -L option is in effect, then the time of the last data modification of the file it points to is always used. |
*For -newerXY reference
the letters X and Y can be any of the following letters:
a
The access time of the file referenceB
The birth time of the file referencec
The inode status change time of referencem
The modification time of the file referencet
reference is interpreted directly as a time
Some combinations are invalid; for example, it is invalid for X to be t. Some combinations are not implemented on all systems; for example B is not supported on all systems. If an invalid or unsupported combination of XY is specified, a fatal error results. Time specifications are interpreted as for the argument to the -d option of GNU date. If you try to use the birth time of a reference file, and the birth time cannot be determined, a fatal error message results. If you specify a test which refers to the birth time of files being examined, this test will fail for any files where the birth time is unknown.
Conclusion
That’s all for today since I have had a busy weekend. Btw if you are interested in the MIT course you can check out the video lecture I’m currently doing the exercises for. The lecture is helpful but isn’t sufficient by itself. Anyways, until next time PEACE!