Category Archives: UNIX & Linux How Tos and Tutorials

GNU and UNIX Commands: grep with AND instead of OR

We all know how easy it is to grep for something OR something_else:

However, there’s no elegant way to grep for something AND something_else:

Easiest way around this (and most elegant) is with awk:

Files and Filesystems: Remove Files With Strange Filenames

If it is a file that is called ‘ ‘, i.e. a single space, you can delete it a couple of ways:

Also, it might actually be some kind of control character … observe:

Easy to remove with the same find . -inum technique above.

If the file starts with a - character, e.g.:

try removing it:

Obviously it’ll whinge about -foo not being an option … so:

That’ll do it. -- tells the command to stop interpreting arguments as options. You can use this technique with other commands too, e.g. mv, file, etc.

How To Configure Solaris 10 BIND Chroot

Disclaimer: This post was originally posted in 2008 as an article on the now-defunct website zazzybob.com. While the software version and actual commands used may vary, the concepts are still similar and give a general idea of how to approach a given problem.

The default BIND installation in Solaris 10 does not run in a chroot environment, which is an obvious security risk. Starting BIND to run in a chroot environment is a no-brainer, but getting it to managed by SMF in Solaris 10 requires a bit more work …

Continue reading

Files and Filesystems: Core Files

Note: This tip assumes that you’ve checked the filesystem for legitimate files called core before running the scripts/commands contained herein! See the bottom of this article for how to do that.

Coredumps are created when a program crashes and dumps the contents of memory at the time of the crash to disk. Left unchecked, coredumps can quickly become a problem, consuming vast amounts of disk space.

You can find and remove core dumps with a command such as:

This is fine for a quick fix, but for a longer-lasting solution you can do one of two things. If your OS/Shell support it, you can add the following line to /etc/profile for POSIX compliant shells to disable core dump generation:

(For the C shell, add the line “limit coredumpsize 0” to /etc/csh.login).

If your OS/Shell doesn’t support this, you can still tackle the problem as it happens. Most core files appear in users home directories. Running a quick script such as:

will ensure that any core file on the system is truncated to zero bytes and marked read-only, so that the core file cannot be re-created and thus will never be larger than 0 bytes. Obviously, this is a very kludgy solution, and to work efficiently, you’d need a zero byte core file in everyone’s home directory (and anywhere else on the system coredumps are found), but suffices on very old systems where ulimit isn’t available. Run from cron on a nightly basis, this can be a very useful technique on old systems.

A much more robust way of searching for and deleting core dumps is with a command like:

If you want to be cautious, then change the rm -f to rm -i.

If you’re using a system other than Solaris, you may need to modify the regex in the awk command to match whatever the output of the file command gives you when executed against a core dump.

We can see this in action here…

As you can see, it’s only removed the true core dump.

How to Change the UID of a Running Process

Recent versions of Solaris come with a suite of tools known as the “/proc�? tools, which list and/or modify process information in the kernel-maintained /proc filesystem. One of these tools, pcred, can be used to change (among other things) the UID of a running process, e.g.:


If you run a man proc, you’ll receive the manual page for the /proc tools - highly useful.

Shells: Using vi-mode Line Editing in tcsh

Just a quick one. If you think emacs is a bunch of crap (like me), you’ll hate the way that tcsh defaults to using this Meta-key-ridden abomination for line editing. Let’s enable vi-mode line editing:

Ahhh, that’s better.

To make this persistent, just add it to ~/.cshrc_local:

Job done. Better yet, don’t use tcsh!

Files and Filesystems: How to Mount ISO Images

Most modern Linux kernels support the loop mount option. One of the nifty things about the loop filesystem option is that it allows you to mount an ISO image directly into the filesystem without having to burn the image onto a CD first. You could simply run the command

to mount foo.iso on the /mnt mountpoint. The type should be auto-detected (iso9660). If things don’t auto-detect, explicitly state them by running a command something along the lines of:

How to Update Volume Configuration within Netbackup

This is for an old version (4.5) of Veritas NetBackup.


Obviously, your robot type (-rt) may be different. Here, we see that the volume configuration is already up to date, thus no changes are made.

Terminals: How to Sanitise Your Haywire Terminal

We’ve all done it - issuing a nonsense command such as cat /bin/ln can really screw up your terminal! In order to sanitise your terminal, you can try three things. First of all, try the reset command. If that doesn’t work (or isn’t supported), try stty sane. That should be supported, but doesn’t always work. I find the command that gets me out of trouble is

The ^O is produced by typing CTRL-V CTRL-O. This should return your terminal to a sensible state.

How to Set up a BIND DLZ Nameserver with MySQL Replication

Disclaimer: This post was originally posted in 2008 as an article on the now-defunct website zazzybob.com. While the software version and actual commands used may vary, the concepts are still similar and give a general idea of how to approach a given problem.

This article sets out to describe the process used to set up a BIND nameserver with Dynamically Loadable Zones (DLZ) running with a MySQL backend (with replication).

DLZ allows us to maintain a dynamic database of zone information, located either locally or across the network (and with replication, highly-available). Thus we eliminate the need for zone transfers. Further information on BIND DLZ can be found at the BIND DLZ SourceForge site.

Continue reading