Click the box titles below to expand:

How to's

XSLT

GOOGLE MAPS API

PHP

Perl

Document Object Model (DOM)

UNIX

Generic Mapping Tools (GMT)

Miscellaneous

Projects

Courses Taught

Latest Favorites

Mac OS X

Web Development

Beta

How To :: Snippets of useful UNIX code that make my life easier

Modify permissions on an RCS file

Go into the RCS directory (if there is one) and chmod on the ,v file. For example, you have a file called documents.html that has read-only permissions. You want it to have executable permissions. You need to go into the RCS directory and chmod the documents.html,v file to +x.

Repeat the last part of a UNIX command

Repeat the last argument of the command with a new command.

[user@host]$ mkdir this
[user@host]$ cd !$
cd this

Using find and grep together

Search for string using find and grep together:

find ./ -exec grep "searchStr" \{\} \; -print

This prints out all matching results with the file name on the next line.

Getting MySQL query results into a text file in your home directory

This is actually really simple... there are two methods...

Method 1

  1. In the typical MySQL environment, query results are pushed to STDOUT (ie. the MySQL command line prompt). You need to change this to cat and then point cat to your text file in your home directory.
  2. Run your query.
  3. Exit mysql and you will see your result query in the text file you defined with the pager option. To return the output to STDOUT just type nopager at the MySQL prompt.
mysql> pager cat > /path/to/test.sql
PAGER set to cat >  /path/to/test.sql

mysql> SELECT email FROM members WHERE password='' AND email != 'null';
632 rows in set (0.01 sec)

mysql> nopager
PAGER set to stdout

Method 2

Make the database do the work, and just add the INTO OUTFILE within your SELECT statement:

mysql> SELECT email FROM members WHERE password='' AND email != 'null' INTO OUTFILE '/tmp/test.sql';
Query OK, 632 rows affected (0.04 sec)

Using cat in fancy ways

To create a file with 'cat', type cat and the redirection character ">"
(greater-than) and a file name.  Everything from Standard In (STDIN)
eg. everything you type (or paste in a copy/paste operation) then gets
written to the file until a CTRL-D is typed. The file will be created
if it does not already exist or overwritten if it already exists. If
you use double greater-than as in "cat >>" and a file-name the file
will be appended to rather than overwritten.

Some examples:

cat > newwork.text (then type whatever you want in the
file and finish with a CTRL-D) write everything that is typed following
the 'cat > newwork.text' command, up to but not including the CTRL-D,
in to the file 'newwork.text' Either create a new file 'newwork.text'
or overwrite it if one exists.

cat >> addwork.text (then type whatever
you want in the file and finish with a CTRL-D) Append everything that
is typed following the 'cat > addwork.text' command, up to but not
including the CTRL-D, to the end of file 'addwork.text' Append to an
existing file 'addwork.text' if it exists. Create it if it does not
already exist.

cat > screen.text (then highlight a piece of screen
text with the left button and write it back with the middle button)
CTRL-D copy everything in the highlighted section of screen text to the
file screen.text. Either create a new file 'screen.text' or overwrite
it if one exists.

cat >> screen.text (then highlight a piece of screen
text with the left button and write it back with the middle button)
CTRL-D copy everything in the highlighted section of screen text and
append to the end of the existing file screen.text. If it does not
already exist, create it.

cat filea fileb filec > combo-file Copy everything from files 'filea',
'fileb', 'filec' in to 'combo-file' Either create a new file
'combo-file' or overwrite it if it already exists.

cat filea fileb filec >> combo-file Copy everything from files 'filea',
'fileb', 'filec' and append to the end of the existing file
'combo-file'. If 'combo-file' does not exist, create it.

cat /dev/null > empty-file Create an empty file called 'empty-file. If
a file by that name already exists, empty it out.  (Note: '/dev/null'
is a special null device on UNIX systems.)

Source: http://serv1.scnc.k12.mi.us/howto/edit/cat.html

Disclaimer

This information is freely provided as–is. Messing around with the command line and creating files is a serious business, and I accept no liability for errors created, systems corrupted, or hard–disk damage by you following these instructions. They worked for me but may not work for you. Remember to back–up EVERYTHING before you try any of this stuff — it is not simple OR easy!!!

If you have any questions about this please email me at rlnewman@ucsd.edu and I will try my best to help you out.

made with CSS     Valid XHTML 1.0!      Valid CSS!