for i in {1..20..3}; do
echo “Welcome $i”
done
example:
snoopy@srv02:~# for i in {1..20..3}; do echo "Welcome $i"; done
Welcome 1
Welcome 4
Welcome 7
Welcome 10
Welcome 13
Welcome 16
Welcome 19
snoopy@srv02:~#
Just another WordPress site
for i in {1..20..3}; do
echo “Welcome $i”
done
example:
snoopy@srv02:~# for i in {1..20..3}; do echo "Welcome $i"; done
Welcome 1
Welcome 4
Welcome 7
Welcome 10
Welcome 13
Welcome 16
Welcome 19
snoopy@srv02:~#
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]$
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
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 #
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
To extract a single file from an archive:
# tar zxvf tarfile.tgz -–include=”somefile”
Use patterns:
# tar zxvf tarfile.tgz -–include=”somefile*”
the somefile must use full path. To check file’s fullpath:
# tar tf tarfile.tgz
root# line=123abc
root# line2=${line%%???}
root# echo $line2
root# 123
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.
ping some_IP | while read ping; do echo "$(date): $ping"; done > ping_output.txt
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.