Easy Linux Commands – Now On Shelves!

My book Easy Linux Commands: Working Examples of Linux Command Syntax is now on shelves, as seen in this picture from Borders Book and Music right down the street from my home in Concord, NH.

Easy Linux Commands at Borders Concord

Written by me and Terry Clark this book is part reference and part tutorial encompasing everything from basic file manipulation to administrative commands.

From an Amazon review by Kurt:

New users to Linux and old-school Unix engineers alike will find value in this book. The author did a tremendous service representing this rapidly growing technology in an easy to read, easy to follow humorous format. Page to page there are examples of basic Unix commands and obscure Linux features available to most builds. Having built my career in deploying “Enterprise Class” Unix based solutions for today’s high availability needs, it is refreshing to learn some new tricks and be reacquainted with old tools built discussed in this book. I recommend it to entry level and veterans alike.

The book is available in major bookstores (although any bookstore should be able to order it for you) and can also be ordered from the publisher for just $19.95. That’s 30% off the cover price!

Thanks to Zach for snapping the pic and sending it on to me.

linux, unix, linux commands, command line, redhat, ubuntu, book, technology, information technology, system administration, sysadmin

Statspack Analyzer – Intelligent analysis of Oracle Statspack and AWR reports

After spending a couple days picking through Oracle statspack reports for clues on what could be causing some database latency I finally got the chance to try out the new, free Statspack Analyzer from Texas Memory Systems, Inc. and Burleson Consulting.

StatspackAnalyzer.com is a FREE SITE provided to the Oracle community by sponsor companies including Texas Memory Systems, Inc. and Burleson Consulting.

Our shared goal is that the advice provided by this website evolves as community feedback indicates that the heuristics should be updated. If you like what you see, please let us know. If you don’t like what you see, please tell us what you would do to improve the site and which if any decision rules should be updated.

Just paste your whole statspack or AWR report into the analyzer and it will do the heavy lifting and give you custom recommendations on what areas you can possibly tune to increase performance. I had the chance to run several reports through the analyzer this week and it came up with many of the same conclusions I did in a fraction of the time.

Tools like this aren’t about to replace the DBA but rather help take the edge off intensive tasks like tuning. Check out the sample report to get a better idea of what the analyzer output looks like, or better yet try it out! After all, it’s free!

oracle, database, dba, database administrator, database tuning, sql

Archiving Directories and Files with tar

Still hanging in there the tar command remains the de facto standard for archiving files and directories in UNIX and UNIX-like operating systems. Here are some tar basics from Easy Linux Commands

There are several reasons you may want to create an archive of a file or directory. Here are some of the most common ones:

  • Archive and compress unused directories to conserve disk space
  • Create an archive of a directory and files before an upgrade allowing you to restore the original contents if there is a problem
  • Archive a directory before making any major changes
  • Create an archive to move several files and folders to another system as one
  • Create an archive as a means of software distribution

One of the most useful utilities for archiving a set of files and directories is tar. The name tar is short for Tape ARchiver because tar was originally written to write data to a tape backup device.

The following is a basic example of archiving a directory into a tar archive file and also extracting the archive into its original structure.

$ tar -cvf examples.tar examples
$ rm –r examples
$ ls
$ tar –xvf examples.tar
$ ls
examples examples.tar

In this example we have demonstrated the two most common uses of tar. The first tar command combines the –c (create) option to create a new archive, the –v (verbose) option to list the files and directories it’s archiving and the –f option to write to a file rather than to tape. Remember that tar was originally written for use with tape drives and it still defaults to tape if you do not use the –f option.

The two arguments for this tar command are the destination file (examples.tar in our example here) and the files which should be added to that file. This can be confusing since most other Linux commands take a source argument before the destination. tar takes them in the order of destination then source so you can list multiple source files to be archived into a single file. Also not that we have to specify the file extension (.tar) if we want our new archive to have an extension. You can name a tar archive (typically called a tarfile or tarball) anything you want, but the .tar extension is a widely accepted convention.

In the second tar command the –v and –f options have the same result and the –x (extract) option tells tar that we want to extract the contents of a tar file rather than create one. We then give tar the name of the archive to be extracted and it goes to work restoring our files.

A Warning about Relative and Absolute Paths in tar

As with other commands tar can be used with either relative or absolute paths. When specifying the tarfile to be created or extracted there is little difference between these two methods; however, if you use an absolute path when listing files to be archived you might get a surprise when you extract them!

If an absolute path is used to tell tar which files to archive, like with the command below the archive will record the absolute path and restore those files to that path, no matter where tar is run from or where the tarfile is.

$ tar -cf examples.tar /home/tclark/examples

If an absolute path is not specified on archiving the files will be extracted into the working directory or the appropriate subfolder of the working directory.

Easy Linux CommandsFor more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.

Buy it now!

linux, unix, system administration, sysadmin, tar, tape archive

SQL Date Math and the Leap Year

Ying pointed out on my article about finding the last Saturday of the year that adding a year to a DATE datatype works great with syntax like this:

SQL> select sysdate+numtoyminterval(1, 'YEAR') from dual;


It works great right up until you hit February, 29:

SQL> select to_date('02/29/2004', 'MM/DD/YYYY')+numtoyminterval(1, 'YEAR') from dual;
ERROR at line 1:
ORA-01839: date not valid for month specified

So what can we do about this? Well, as far as I can guess there are only two options. First, you could avoid ever using +numtoyminterval(1, 'YEAR') in your code and instead use +numtodsinterval(365, 'DAY') like this:

SQL> select to_date('02/29/2004', 'MM/DD/YYYY')+numtodsinterval(365, 'DAY') from dual


This may cause some confusion as 365 days after January 15, 2004 would be January 14, 2005 and 365 days after January 1, 2004 is actually December 31, 2004, but it should never throw an ORA- error.

UPDATE: Ying commented with this solution which is probably better in most scenarios. By using the add_months function we can step forward a number of months and Oracle will automatically truncate to the last day of the month if the resulting month has fewer days than the starting month.

SQL> SELECT Add_Months(to_date('02/29/2004', 'MM/DD/YYYY'), 12) from dual;


The other alternative is to handle the exception programmatically. Either avoid inserting a February 29 or avoid using the +numtoyminterval(1, 'YEAR') only when handling a February 29.

I’d say option 1 is the better choice, but both have their drawbacks.

This is the same error you get if you attempt to add a month to, say January 30th since there is never a February 30th.

SQL> select to_date('01/30/2006', 'MM/DD/YYYY')+numtoyminterval(1, 'MONTH') from dual;
select to_date('01/30/2006', 'MM/DD/YYYY')+numtoyminterval(1, 'MONTH') from dual
ERROR at line 1:
ORA-01839: date not valid for month specified

I guess this is why most things are good for “30 days” not “1 month”.

Thanks Ying for pointing out this anomaly.

database, oracle, date, to_date, timestamp, time, database administration, database development