List files which does not contain a string

root# grep -rL "string"

Explanation:
-r makes grep recursively
-L only output a filename when it does not contain “string”

Example:
[greg@localhost test123]$ ls -la
total 20
drwxrwxr-x. 2 greg greg 4096 Jun 2 11:31 .
drwx——. 18 greg greg 4096 Jun 2 11:30 ..
-rw-rw-r–. 1 greg greg 4 Jun 2 11:31 aaa.text
-rw-rw-r–. 1 greg greg 4 Jun 2 11:31 bbb.text
-rw-rw-r–. 1 greg greg 4 Jun 2 11:31 ccc.text
[greg@localhost test123]$ cat *
123
213
212
[greg@localhost test123]$

greg@localhost test123]$ grep -rL “123”
ccc.text
bbb.text
[greg@localhost test123]$

Vi delete commands – reference

A lot of times all people need is a quick reference, so I’ll start with a reference of vi/vim delete commands:

x – delete current character
dw – delete current word
dd – delete current line
5dd – delete five lines

d$ – delete to end of line
d0 – delete to beginning of line

:1,.d
delete to beginning of file

:.,$d
delete to end of file

Lists all files beginning with n or S followed by "-release".

ls [nS]*-release

Lists all files beginning with n or S followed by “-release” (e.g., novell-release)

oes11-34:/etc # ls -la [nS]*-release
-rw-r--r-- 1 root root 72 Jan 21 2014 novell-release
-rw-r--r-- 1 root root 69 Jun 3 2013 SuSE-release
oes11-34:/etc # cat [nS]*-release
Novell Open Enterprise Server 11 (x86_64)
VERSION = 11.2
PATCHLEVEL = 2
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 3
oes11-34:/etc #

Use logger to write a messages to log files.

The basic syntax for logger is logger message. It does not require any options if you are just going to write a message to the logfile and you want to write to the default /var/log/messages at the notice level.

root# logger Added a new disk to a machine

You can see a message in /var/log/message file. Also you can run this command with option -s Log the message to standard error, as well as the system log.

root# logger -s Added a new disk to a machine

Testing whether a string is null.

Testing whether a string is null.

#!/bin/bash
# str-test.sh: Testing null strings and unquoted strings,
#+ but not strings and sealing wax, not to mention cabbages and kings . . .

# Using if [ … ]

# If a string has not been initialized, it has no defined value.
# This state is called “null” (not the same as zero!).

if [ -n $string1 ] # string1 has not been declared or initialized.
then
echo “String “string1″ is not null.”
else
echo “String “string1″ is null.”
fi # Wrong result.
# Shows $string1 as not null, although it was not initialized.

echo
Continue reading “Testing whether a string is null.”

Tarballs benchmark – gz, bz2 and xz.

Directory used for this benchmark: test_tarball 189M in size. The directory contains /var/log files.

OS: Ubuntu 12.04LTS
CPU: Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz
RAM: 2 x 4096MB DDR3 1333MHz
HDD: Hitachi HTS72323

.gz
tar cvzf tarball.tar.gz test_tarball/
Size of tar.gz tarball: 22M
Compression time: 0m3.926s

.bz2
tar cvjf tarball.tar.bz2 test_tarball/
Size of tar.bz2 tarball: 19M
Compression time: 0m38.924s

.xz
tar cvJf tarball.tar.xz test_tarball/
Size of tar.xz tarball: 18M
Compression time: 0m57.988s

It seems that it does not make sense for use .xz tarball for small size files.

Grep is your friend :-)

Let’s say you have a running server and you notice that something in the server is not working well, so you want to search a log file for errors:

grep "error" somelogfile.log

This returned no results. This could be because grep being case-sensitive, let’s add the case-insensitivity flag:

grep –i "error" somelogfile.log

If the word “error” in any casing appears in the log file, you’ll see the relevant lines in the console. This is not the only way for the program to inform you there’s a problem, there are other words which might be relevant. You don’t want to search for them one by one:

grep –Ei "error|blocked|panic" somelogfile.log

The “E” flag indicates the use of regular expressions, which will allow you to use the pipe sign, dollar sign and other useful regex.

Now, you finally get the result you wanted, but you can only see one line of it and you want to know what it’s all about, so you can do this:

grep –A 10 –B 20 "Error" somelogfile.log