techtiptom

Tech Tip Tom, formerly of WIBC 93.1FM and wibc.com

Month: May, 2013

Unix Tips & Tricks

Here are a few pieces of Unix wisdom, picked up over the years…

You’ve done something that has completely screwed up your terminal. Everything you type is either invisible or incomprehensible. Try the following:

    $ ^C
    $ stty sane^J

If this doesn’t work, try:

    $ echo ^V^O

To determine what program dumped an anonymous core file, use gdb:

    $ gdb -core core
    [...]
    Core was generated by `a.out'.
    Program terminated with signal 6, Abort trap.
    [...]

If you are on a system without gdb, try the file command:

    $ file core
    core: ELF 32-bit LSB core file of 'a.out' (signal 6)
    $

To create a vi macro that will wrap the current paragraph to a reasonable number of characters, add the following to your .exrc or .vimrc file:

    map Q {!} fmt -c -u^M

Now, when you press ‘Q’ in visual mode, the current paragraph will be wrapped to approximately 70 characters.

Due to the Unix concept of sparse files, you can create seemingly enormous files that in reality take next to no disk space. The following program will create a 305,419,897 byte file called ‘core’ that may result in you receiving a ‘cleanup’ email message from a less-than-seasoned Unix sysadmin even though it occupies virtually no real disk space.

    $ cat bigcore.c
    #include <fcntl.h>
    #include <unistd.h>

    int main(void) {
        int fd = open("core", O_CREAT|O_WRONLY|O_TRUNC, 0600);
        lseek(fd, 0x12345678, SEEK_SET);
        write(fd, "1", 1);
        close(fd);
        return 0;
    }

    $ cc -o bigcore bigcore.c
    $ ./bigcore
    $ ls -l core
    -rw-------  1 dmr  staff  305419897 May  1 03:50 core
    $ du -k core
    48      core
    $

On older Unix systems, in particular those that don’t support MD5 password hashing, only the first 8 characters of a password are significant. If you use an 8 character password on these systems, you can type anything you want after the first 8 characters and it will be accepted by login. This allows you to type the first 8 characters of the password as usual, then have some fun. Enter a bunch of crap at superhuman speed, then enter the last few characters with your elbow. Then press backspace twice carefully and retype the characters with your other elbow. Etc….

When recursive copying, cp (cp -Rip, etc.) may not be the best tool for the job. For example, cp copies hard links as separate files, which is probably not what you want. To get a true copy of a directory, try:

    $ tar cf - <dir> | (cd <destdir>; tar xf -)

This will create an exact copy of ‘dir’ in ‘destdir’. The same principle can be used to create a recursive copy on a remote machine:

    $ tar cf - <dir> | ssh remotehost "(cd <destdir>; tar xf -)"

To list the files in another directory that match more than one pattern, it is easiest to do:

    $ ls -l /usr/local/foo/{*.conf,*.local,*.rc}

which is equivalent to:

    $ ls -l /usr/local/foo/*.conf /usr/local/foo/*.local /usr/local/foo/*.rc

This syntax is supported by (at least) bash, ksh, csh and sh.

You can extend this idea to make renaming files in another directory, for example, a little easier:

    $ mv -i /usr/local/foo/bar/baz/{stuff,stuff~}

A little insurance against running ‘rm -rf *’ in the wrong directory — create an empty file called -i in any critical directory:

    $ >-i

or…

    $ touch -- -i

If the ‘rm -rf *’ command is issued in that directory, the shell will expand the ‘-i’ early on and go into interactive mode, thus giving you a chance to say ‘Whoa, that was close!’, which always sounds better than ‘Oh fsck!’.

This tip works because the -i option to rm will override any previous -f.

Be forewarned that this tip only protects against ‘rm -fr *’, i.e., files and directories in the current directory.

To remove the -i file (or any other file beginning with ‘-‘):

    $ rm ./-i

or…

    $ rm -- -i

To return to the previous directory in ksh or bash, use:

    $ cd -

To use the last argument of the previous command line as an argument, use $_. For example:

    $ ls -l /usr/home/dmr/somefile
    $ vi $_

To make the up and down arrow keys work and thereby enable command line editing and recall in ksh, include the following lines in your ~/.profile:

    set -o emacs
    alias __A='^P'
    alias __D='^B'
    alias __B='^N'
    alias __C='^F'
    alias __H='^A'

You need to enter the actual control characters ^P, ^B, etc.

Charles Babbage

Charles Babbage

babbage Biography

Charles Babbage was born in London on December 26, 1792 (3), the son of Benjamin Babbage, a London banker. As a youth Babbage was his own instructor in algebra, of which he was passionately fond, and was well-read in the continental mathematics of his day. Upon entering Trinity College, Cambridge, in 1811, he found himself far in advance of his tutors in mathematics.With Herschel, Peacock, and others, Babbage founded the Analytical Society for promoting continental mathematics and, reforming the mathematics of Newton, then taught at the university.

In his twenties Babbage worked as a mathematician, principally in the calculus of functions. He was elected a Fellow of the Royal Society, in 1816, and played a prominent part in the foundation of the Astronomical Society (later Royal Astronomical Society) in 1820. It was about this time that Babbage first acquired the interest in calculating machinery that became his consuming passion for the remainder of his life.

Throughout his life Babbage worked in many intellectual fields typical of his day, and made contributions that would have assured his fame irrespective of the Difference and Analytical Engines.

Prominent among his published works are:

  • A Comparative View of the Various Institutions for the Assurance of Lives (1826); an actuarial paper,
  • Table of Logarithms of the Natural Numbers from 1 to 108, 000 (1827),
  • Reflections on the Decline of Science in England (1830),
  • On the Economy of Machinery and Manufactures (1832),
  • Ninth Bridgewater Treatise (1837),
  • and the autobiographical Passages from the Life of a Philosopher (1864).

Babbage occupied the Lucasian chair of mathematics at Cambridge from 1828 to 1839. He played an important role in the establishment of the Association for the Advancement of Science and the Statistical Society (later Royal Statistical Society).

Despite his many achievements, the failure to construct his calculating machines, and in particular the failure of the government to support his work, left Babbage in his declining years a disappointed and embittered man. He died at his home in Dorset Street, London, on October 18, 1871.

Computer Pioneers: Howard Hathaway Aiken

aiken_howard3Achievement

Invented/developed the Mark I

Biography

Howard Hathaway Aiken was born March 8, 1900 in Hoboken, New Jersey. However he grew up in Indianapolis, Indiana where he attended the Arsenal Technical High School. {My High School!}   After high school he studied at the University of Wisconsin where he received a bachelor’s degree in electrical engineering. During college Aiken worked for the Madison Gas Company; after graduation he was promoted to chief engineer there.

In 1935 Aiken decided to return to school. In 1939 he received a Ph.D. from Harvard University. It was while working on his doctoral thesis in physics that Aiken began to think about constructing a machine to help with the more tedious tasks of calculations. Aiken began to talk about his idea and did research into what could be done. With help from colleagues at the university, Aiken succeeded in convincing IBM fund his project.

The idea was to build an electromachanic machine that could perform mathematical operations quickly and efficiently and allow a person to spend more time thinking instead of laboring over tedious calculations. IBM was to build the machine with Aiken acting as head of the construction team and donate it to Harvard with the requirement that IBM would get the credit for building it. The constructing team was to use machine components that IBM already had in existence.

It took seven years and a lot of money to finally get the machine operational. Part of the delay was due to the intervention of World War II. Officially the computer was called the IBM Automatic Sequence Controlled Calculator but most everyone called it the Mark I. After completing the Mark I, Aiken went on to produce three more computers, two of which were electric rather than electromechanical.

More important than the actual computer (whose major purpose was to create tables), was the fact that it proved to the world that such a machine was more than just fancy, it was a practical purpose machine. Perhaps more important than the invention of Mark I was Aiken’s contribution to academia. He started the first computer science academic program in the world.
Aiken retired from teaching at Harvard in 1961 and moved to Ft. Lauderdale, Florida. He died March 14, 1973 in St. Louis, Missouri.

History of Mother’s Day

mothers_dayEARLY CELEBRATIONS 

Some historians believe that the earliest celebrations of Mother’s Day was the ancient spring festival dedicated to mother goddesses. The ancient Greek empire had a spring festival honoring Rhea, wife of Cronus and mother of the gods and goddesses. In Rome there was a Mother’s Day-like festival dedicated to the worship of Cybele, also a mother goddess. Ceremonies in her honor began some 250 years before Christ was born. This Roman religious celebration, known as Hilaria, lasted for three days -from March 15 to 18.

ENGLAND’S MOTHERING SUNDAY 

England’s “Mothering Sunday”, similar to Mother’s Day,  also called Mid-Lent Sunday, is observed on the fourth Sunday in Lent. Some say the ceremonies in honor of Cybele were adopted by the early church to venerate the Mother of Christ, Mary. Others believe the Mother Church was substituted for mother goddess and custom began to dictate that a person visit the church of his/her baptism on this day. People attended the mother church of their parish, laden with offerings.

Also in England in the 1600’s, young men and women who were apprentices or servants returned home on Mothering Sunday, bringing to their mothers small gifts like trinkets or a “mothering cake”. Sometimes frumenty was served – wheat grains boiled in sweet milk, sugared and spiced.

In northern England and in Scotland, the preferred refreshments were carlings – pancakes made of steeped pease fried in butter, with pepper and salt. In fact, in some locations this day was called Carling Sunday.

Another kind of mothering cake was the simnel cake, a very rich fruit cake. The Lenten fast dictated that the simnel cake had to keep until Easter. It was boiled in water, then baked, and was often finished with an almond icing. Sometimes the crust was of flour and water, colored with saffron.

JULIA WARD HOWE

In the United States, Julia Ward Howe suggested the idea of Mother’s Day in 1872.
She wrote her Mother’s Day Proclamation in 1870.

Julia Ward Howe, a Boston poet, pacifist, suffragist, and author of the lyrics to the “Battle Hymn of the Republic,” organized a day encouraging mothers to rally for peace, since she believed they bore the loss of human life more harshly than anyone else.

THE FIRST MOTHER’S DAY

The first Mother’s Day observance was a church service honoring Mrs. Anna Reese Jarvis, held at Anna Jarvis’s request in Grafton, West Virginia, and in Philadelphia, Pennsylvania, on May 10, 1908.

Carnations, her mother’s favorite flowers, were supplied at that first service by Miss Jarvis. White carnations were chosen because they represented the sweetness, purity and endurance of mother love. Red carnations, in time, became the symbol of a living mother. White ones now signify that one’s mother has died.

OFFICIAL PROCLAMATION

The House of Representatives in May, 1913, unanimously adopted a resolution requesting the President, his Cabinet, members of Congress, and all officials of the federal government to wear a white carnation on Mother’s Day. Congress passed another Joint Resolution May 8, 1914, designating the second Sunday in May as Mother’s Day. The U.S. flag is to be displayed on government buildings and at people’s homes “as a public expression of our love and reverence for the mothers of our country.” President Woodrow Wilson issued the first proclamation making Mother’s Day an official national holiday.

Juliet Calhoun Blakeley

On May 13, 1877, the second Sunday of the month, Juliet Calhoun Blakeley stepped into the pulpit of the Methodist-Episcopal Church and completed the sermon for the Reverand Myron Daughterty.

According to local legend, Daughterty was distraught because an anti-temperance group had forced his son to spend the night in a saloon.

Proud of their mother’s achievement, Charles and Moses Blakeley encouraged other to pay tribute to their mothers.

In the 1880’s the Albion Methodist church began celebrating Mother’s Day in Blakeley’s honor.

OTHER MOTHER’S DAY OBSERVANCES 

The first Mother’s Day proclamation was issued by the governor of West Virginia in 1910. Oklahoma celebrated Mother’s Day that year as well. By 1911 every state had its own observances. By then other areas celebrating Mother’s Day included Mexico, Canada, China, Japan, South America and Africa. The Mother’s Day International Association was incorporated on December 12, 1912, with the purpose of furthering meaningful observations of Mother’s Day.

Mother’s Day is celebrated in many countries, including the United Kingdom, the United States, Denmark, Finland, Italy, Turkey, Australia, Mexico, Canada, China, Japan and Belgium. The day is used by children and husbands to honor mothers and grandmothers for all that they do in raising children.