home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 21.13 Read an Inode with stat Chapter 21
More About Managing Files
Next: 22. File Security, Ownership, and Sharing
 

21.14 Automatically Appending the Date to a Filename

I suppose this falls into the category of "stupid tricks" but I still find it useful sometimes. I created a simple alias called vid , which I use to create and edit a file with a date as part of the filename.

I find it handy for repetitive reports and memos.

The alias looks like this:


alias vid "vi \!:1.`date +%m.%d`"

and given an argument like memo or status , appends the date as an extension. Using wildcards, I can then list all my memos of a particular date or a particular subject:

% ls status*


status.02.18
status.03.10
% ls *3.10


budget.03.10
status.03.10

If I wanted to add the year, I'd put a dot or other separator, followed by %y in the specification to the date command.

If you understand backquote interpolation (9.16 ) and the formats for the date (51.10 ) command, you can easily develop variations of this alias that work with other commands besides vi .

- TOR


Previous: 21.13 Read an Inode with stat UNIX Power Tools Next: 22. File Security, Ownership, and Sharing
21.13 Read an Inode with stat Book Index 22. File Security, Ownership, and Sharing

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru