Grep from files matching a name in a directory

To look only at files matching a certain name (or part of a name) -name or -iname can be used.

-name pattern Base of file name (the path with the leading directories removed) matches shell pattern pattern. Because the leading directories are removed, the file names considered for a match with -name will never include a slash, so `-name a/b’ will never match anything (you probably need to use -path instead). The metacharacters (`*’, `?’, and `[]’) match a `.’ at the start of the base name (this is a change in findutils-4.2.2; see section STANDARDS CONFORMANCE below). To ignore a directory and the files under it, use -prune; see an example in the description of -path. Braces are not recognised as being special, despite the fact that some shells including Bash imbue braces with a special meaning in shell patterns. The filename matching is performed with the use of the fnmatch(3) library function. Don’t forget to enclose the pattern in quotes in order to protect it from expansion by the shell.

-iname pattern Like -name, but the match is case insensitive. For example, the patterns `fo*’ and `F??’ match the file names `Foo’, `FOO’, `foo’, `fOo’, etc. The pattern `*foo*` will also match a file called ‘.foobar’.

$ find /path/to/search/in/ -iname '201512*' -type f -print0 | xargs -0 grep "LookForString"
/path/to/search/in/20151209-000855.LOG:2015-12-09 08:01:15 LookForString is in this file
/path/to/search/in/20151219-001855.LOG:2015-12-19 23:15:47 LookForString is also in this file

Kill all processes with a given name

suppose we wish to kill all instances of rsync that is running
Simplest given that we know the process name

pkill rsync
ps aux|awk '/sleep/ {print "kill -9 " $1}'

Or a sligtly longer version that might(?) be more verbose as to what it does

kill -9 $(ps aux | grep '[r]sync' | awk '{print $2}')

un tar and ownership of the extracted files

If the user extracting is a “ordinary” user, the files will be owned by that user (by default).
If the user extracting is a super user, then the files ownership will be preserved (by default).

Note: This is by default and can be overridden when needed:

From the manual page of tar:

--same-owner
       try extracting files with the same ownership as exists in the archive (default for superuser)
 
--no-same-owner
       extract files as yourself (default for ordinary users)

PostgreSQL 8.3 adding uuid-ossp on Debian

UUID is a nice way to generate (almost) unique id’s.

However on PostgreSQL 8.3 the data type exists, but if you wish to be able to generate UUID’s you need to get a module (in this case uuid-ossp).

On Debian this module is in the contrib package, so if you have not installed this before do it now

user@server:~$ sudo apt-get install postgresql-contrib

Then you need to “load” the module into PostgreSQL; or more accurately you tell PostgreSQL about the new functions this module has, how to reach them etc.
Depending on you security settings (in pg_hba.conf) you may need to log in as the postgres user on your system.

postgres@sever:~$ psql -d MYDB -U postgres -f /usr/share/postgresql/8.3/contrib/uuid-ossp.sql

Ubuntu Hibernate/Suspend problem

First off, quick explanation.
Suspend saves a image to ram. It is faster to save and reload; but the computer uses a minimal amount of energy to keep this in ram. If the power is lost (battery is drained etc) then the image is lost.
Hibernate save a image to disk. It is slightly slower to save and reload; but there is no problem if the power is lost.

However I am not the only one that have noticed that hibernate/suspend on Ubuntu does not work on a default installation.
One solution that more than me have found to be working is to switch to uswsusp.

user@laptop$ sudo apt-get install uswsusp
user@laptop$ sudo s2disk

s2disk does a hibernation (s2ram does a suspend); and it is good to test it out before swapping the hibernate/suspend function.
When you know hibernate/suspend works, you can swap to using uswsusp by using:

user@laptop$ sudo dpkg-divert --rename --divert /usr/sbin/pmi-disabled /usr/sbin/pmi

If you later on would like to swap back you can use

user@laptop$ sudo dpkg-divert --rename --remove /usr/sbin/pmi

.forward to several recipients

On *nix environments it is possible to forward the mail to one account to another user (or another email address if external mail is supported).
This is done by adding the recipient in a file called .forward in the home directory.

Example To simply forward to another address:

user@server$ echo recipient@mail.com > ~/.forward
user@server$ chmod go-w ~/.forward

In order to forward to several addresses coma (,) is used as a delimiter between the different recipients.

Example To forward to two addresses at the same time:

user@server$ echo recipient1@mail.com,recipient2@mail.com > ~/.forward
user@server$ chmod go-w ~/.forward