
Every once in a while, I get on this thing about how cool (and powerful) the shell is. With a little knowledge, you can do all sorts of great things. For instance, starting up the editor of your choice to open up a work file with the day's date automatically generated. This is actually the sort of thing I do all the time. For instance, today's journal would be in a directory called /home/marcel/Daily_Journal/Saturday_Jan_17_2004. Let's step back. Open up a shell prompt and type the command "date". The result will look something like this. $ date "Nothing special there", you say. Well, what if you wanted to know the date 12 days ago. Use the "-d" modifier. $ date -d "12 days ago" It gets more interesting, doesn't it? You can also modify the output of the date command with the plus sign modifier. For instance. $ date +%A -d "12 days ago" The "%A" tells the date command to print out the long for of the day (ie: Monday instead of Mon). Check the man pages and you will see a whole lot of these modifiers. If I wanted to have the day in long form, the month in 3 letter short form, followed by the day and the year in 4 digit form, I would use the following command. $ date +"%A %b %d %G" I put quotes around the modifiers because I wanted spaces in between each one. Had I wanted underscores, it would not have been necessary. So far so good. Let's say that I wanted a command to call my favorite editor (whatever it might be) to open a daily journal in the form of Saturday_Jan_17_2004, I could put the whole thing in a script file like this. #!/bin/bash Notice the back quotes around the date command -- very important. I used the kwrite command here, but you could use vi, pico, nedit, or whatever editor you feel comfortable with. When I wrote this script, I called it "think" and saved it in /usr/local/bin. Then, I made the file executable with "chmod +x /usr/local/bin/think". All I have to do now is call the command "think" and it magically opens a pre-named daily journal text file. |
|||










