Saturday, March 22, 2014

Sharing information can help you remember it

I had a problem at work. I was working through a list of directions for clearing space on a server so that the server could be made ready for an upgrade. As I worked through the list, I came upon a directory that could contain many files each of which could take up a lot of space. The instructions said that all I needed to do was compress files that were older than 30 days and that should free up enough space.

Unfortunately for me, and everyone else faced with this task, the instructions did not provide for an automated method of finding the files. Instead, I was thinking about how much time it would take for me to inspect the files by eye, identify the files that were older than 30 days and compress them. I'm lazy and knowing that I would encounter this again, I recalled how I had managed to automate this before.

In Linux, there is the find command. Find is a great command for finding files that meet certain selection criteria. You can use it to find a file by name if you're just looking for one file. But you can also use the find command to locate files based on size, type and the last modified date or even the last access date.

Gzip is a standard compression utility in Linux. Rather than compressing each file one at a time, like this, "gzip ", I found a way to combine two different commands to get the results I wanted. While I sat there at work, looking at so many files that I could compress to free up space, I remembered the find command and did a little research. The research yielded the following command:

find . * -mtime +30 -exec gzip {} \;

What this command does is can be explained in a few simple steps:

1. find files in the current directory - that's what the dot after the find command is for.
2. Select any file - that's what the asterisk * is for.
3. Select files that are older than 30 days - the option -mtime +30 sets the selection criteria based on modified date.
4. -exec allows me to run a command on the results of the find command. In this case, any files returned by the find command will be compressed with gzip.
5. The last part, {} \;, that is a sort of place holder for the results. This command will check every file in the directory and if the file matches the selection criteria, the {} \; will be replaced with the file name and the gzip command will operate on the file.

I shared this command with the person who wrote the instructions that I was following. The feedback I got was that this command would be added to the article and made available to anyone who needed it.

Although I consider this little command sequence quite fascinating, and hope you do, too, that's not the point of this article. There are actually two points. First, we are both better off when we share ideas. There is a really good reason for this. I think it is best explained by Thomas Jefferson in a letter to Ian McPherson, more than 200 years ago, with the following excerpt:
If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. Its peculiar character, too, is that no one possesses the less, because every other possesses the whole of it. He who receives an idea from me, receives instruction himself without lessening mine; as he who lights his taper at mine, receives light without darkening me. That ideas should freely spread from one to another over the globe, for the moral and mutual instruction of man, and improvement of his condition, seems to have been peculiarly and benevolently designed by nature, when she made them, like fire, expansible over all space, without lessening their density in any point, and like the air in which we breathe, move, and have our physical being, incapable of confinement or exclusive appropriation. 
My heart sings when I read this prose, not only for its truth, but also for its beauty, its rhythm and its ultimate conclusion. I can only add one more thing to the wisdom of Jefferson, and it seems such a little thing but it is well worth noting.

I noticed that after I shared my idea with the author of the instructions I used to free up space on the server, and got the feedback, I kept reviewing the command in my mind. When I got home that day, I started to think about how to check the results of the command before running it. I did some experiments on my computer to explore the command some more. The idea got reinforced in my mind after sharing it. It became easier to remember it, you know, in case I ever needed to share it again. That is the second point of this article.
Post a Comment