Janea Taylor – Ancient Tech Blog


Project archiving made simple
May 11, 2007, 3:12 am
Filed under: Linux, Productivity, Scripting

When I’m working on an application I periodically save the entire directory structure the project resides in, usually upon the completion of any major milestones or prior to any dirty work. The number of archive files can add up over time so to keep track of them I use a handy little naming convention -> Project_yyyyMMddhhmm. The reason for this, other than consistency is pretty simple… By using the current date/time in this format, all the archive files are automatically sorted alphabetically by the exact year, month, day and time they were created and well, it makes more sense than say “Project1, Project2” etc…If I’m working in Windows I usually go about the process of archiving a project by selecting all the files/folder in the working directory, adding them to a zip file then naming the zip file according to the naming convention. In the process I have to look at the current date/time and populate the information accordingly. This takes less than a minute…but when under tight deadlines, every minute counts!

In Linux/Unix, I can archive a project in less than a second…through the use of a few aliases and a single variable. For example, I have the following in my .bashrc file:

alias appname=’echo $appname’
alias archtime=’date +%Y%m%d%M’
alias archapp=’tar -cf `appname`_`archtime`.tar *’

So, I have a shell variable called appname which, in BASH I can change by typing appname=’currentapp’. Then I have a command called appname which simply returns the value of that variable. Finally, I have two commands: archtime and archapp which retreive the date and archive the entire directory respectively. The archtime command simply returns the formatted results of a date command and the archapp command uses the tar application to archive the directory using the results of the appname and archtime commands.

Now I can run archapp from the command line and it will automatically create a new archive file using my naming convention 🙂 Simple but sweet!