Skip to content

I predict a RAID, I predict a RAID !

How to create a simple Raid 1 Mirror Array

Make sure you have mdadm installed, if you have not then :-

prompt> yum install mdadm

Make sure you have 2 hard drive/2 partitions in total, each from a different hard drive that you can use for this Raid 1 setup

Do a quick : –

prompt> mdadm – – detail – scan

This will help to show if there are any RAID setups already on your system

Create the Raid 1

prompt> mdadm –C /dev/md0 –n2 /dev/hd a /dev/hdb –l1

This will create the raid array and start it.

Now to make sure the Raid array assembles each and every time you restart your computer make sure to: –

prompt> mdadm – – examine – – scan >> /etc/mdadm.conf

If you do not do the top bit mentioned then you will need to assemble the Raid array manually every time you restart your computer (mdadm –assemble –scan)

Now you need to put a file system on the /dev/md0 so that you can utilise the Raid Array.

To do this: –

prompt> Mke2fs -j /dev/md0

Now make sure to mount the Raid array so that you can use it.

prompt> mkdir /mnt/raid1

prompt> mount /dev/mdo /mnt/raid1

Now you can use the Raid Array that you have built on /dev/md0 by going to /mnt/raid1 and using it as a normal file system

Further Notes on managing a Raid Array

Sometimes a hard drive might fail. When it does fail you would like to know as soon as possible so that you can deal with the failure by replacing it with a new hard drive. Do a prompt> mdadm –D /dev/md0 to get a summary of how your raid array is working.

Now to remove the failed hard drive: –

prompt> mdadm /dev/md0 – – remove /dev/hdb

Then once you have removed the above hard drive and have replaced it with a new hard drive just add that hard drive into your Raid array by doing the following: –

prompt> mdadm /dev/md0 – – add /dev/hdc

If you type a prompt> mdadm –D /dev/md0 then you will be able to see first hand the raid array rebuilding itself from a clean, degraded state to a clean,degraded,recovering stage and finally to a clean state.

Beginning on the LAMP Journey

I’m hoping to learn more about LAMP – that’s Linux, Apache, Mysql and PHP. LAMP is generally used to setup a webserver. In an effort to understand what I am doing and to document my fails and successes, I will document what I do and how I go abouts doing it here. To be honest the easiest way to install Apache Webserver would be to do a “yum install httpd”, this would resolve all dependencies. But I have had a look at the httpd that would be installed from the repositories and it would install an older version of Apache, hence I’ve gone for installing the latest version as of April 2012 by source.

If you guys want to just go ahead and install apache without verifying the downloaded files then just go down to the heading “Installing Apache Requirements”

Links

Apache HTTP Server (http://httpd.apache.org/) # This is the main website of the Apache HTTPD Webserver

Download (http://httpd.apache.org/download.cgi)

Download new Apache HTTP server from website and dependencies using: –

wget –v http://mirrors.enquira.co.uk/apache//httpd/httpd-2.4.2.tar.gz

wget –v http://www.apache.org/dist/httpd/httpd-2.4.2.tar.gz.asc

wget -v http://apache.mirror.rbftpnetworks.com//apr/apr-1.4.6.tar.gz

wget -v http://apache.mirror.rbftpnetworks.com//apr/apr-util-1.4.1.tar.gz

Verify (http://httpd.apache.org/dev/verification.html)

Verify you have a complete and unmodified version of Apache by: –

#1 Check signature that came with the file in question: –

gpg *PGP.asc*

This will give you the Digital Signature Algorithm Identifier that you will need to query with a public key server to retrieve the public key. Note that GPG is a ‘generally pretty good’ encryption and decryption tool

#2 gpg –keyserver pgpkeys.mit.edu –recv-key *DSA KEY ID*

You should now have received a public key that has automatically been put in your trusted keys

#3 Verify the file again: –

gpg *PGP.asc*

At this stage the signature has been verified but we still cannot trust this public key. Generally a good signature represents a file that not been modified/altered with

What you really need to do is validate that the public key was really produced by an official developer/person from the project/company

#4 Validate the public key by looking at its fingerprint: –

gpg –fingerprint *DSA KEY ID*

This will give you the public key fingerprint that you will be able to confirm with the entity of the e-mail address if it is a valid public key or not.

Once you have obtained a verified trusted key from the entity of the e-mail address you should be able to verify the signature of the file again and find that as you have entered the “web of trust” that you can see that the public key is indeed a authorized trusted key

Installing Apache Requirements

Apache webserver has application dependencies that must be installed before you install Apache, and these are: –

pcre v.8.12-7 (Perl-Compatible Regular Expression Library) was already installed (you can check this by doing a rpm –q pcre)

pcre-devel 8.12 (development libraries for pcre) ; I installed this by doing a : –

prompt> yum -y install pcre-devel

gcc 4.6.3(GNU Compiler Collection) ; I installed this by doing a: –

prompt> yum install gcc

apr 1.4.6 (Apache Portable Runtime) ; I installed this from source by extracting the tarball, and then installing it: –

prompt> wget -v http://www.mirrorservice.org/sites/ftp.apache.org//apr/apr-1.4.6.tar.gz

prompt> gzip -dv apr-1.4.6.tar.gz

prompt> tar -xvf apr-1.4.6.tar

prompt> cd apr-1.4.6

prompt> ./configure

prompt> make

prompt> make install

apr-util 1.4.1 (Utilities for Apache Portable Runtime) ; I installed this from source too, by extracting the tarball just like above, and then doing: –

prompt> ./configure –with-apr=/usr/local/apr #the “-with-apr=/usr/local/apr” option tells the installer where the apr is already installed as it needs to know where this is so that it can proceed with the installation of the apr-util

prompt> make

prompt> make install

apr-util has now been installed. Keep an eye out for any error messages at the end of the output, unfortunately you do not get a big acknowledgement saying ‘this has now been completed’.

Install Apache

Now that we have installed all the dependencies for Apache Webserver (httpd) we can now go ahead and install the actual webserver itself: –

prompt> wget –v http://mirrors.enquira.co.uk/apache//httpd/httpd-2.4.2.tar.gz # this will download the apache source file

prompt> gzip –dv httpd-2.4.2.tar.gz # this will decrypt the contents of the file

prompt> tar –xvf httpd-2.4.2.tar # this will extract the contents of the archive into a directory)

prompt> cd httpd-2.4.2/ # this will change into the directory that you just extracted

prompt> ./configure –enable-so # note that you can tell the source file where to install the application, e.g. if I wanted to install it in /home/, I would do ./configure –prefix=/home/

This will install the webserver in the default location which is /usr/local/apache2/

prompt> make

prompt> make install

If you do not encounter any errors on the way then the webserver should be installed.

Customize (http://httpd.apache.org/docs/2.2/mod/core.html)

Next thing we will be able to do is customize your Apache’s server settings by editing the configuration file (httpd.conf) with any extra configurations you would want to add by: –

prompt> vi /usr/local/apache2/conf/httpd.conf

Note that as for me I did not need to alter any information to the configuration file so I just left it as it was

Test

As Apache has now been installed you can now start the service by: –

prompt> /usr/local/apache2/bin/apachectl -k start

You should be able to test that it works by typing the following in a web browser: –

http://localhost/

or

http://127.0.0.1

This should take you to Apache’s default page, this will prove as acknowledgement that your Apache server has started and is running correctly. I got a simple webpage with bold print text saying “it works!”

You can stop the Apache server by : –

prompt> /usr/local/apache2/bin/apachectl -k stop

To be able to run apachectl from anywhere I made a link from where apachectl is located to one of the directories that is already in the environment variable called PATH.

prompt> ln -s /usr/local/apache2/bin/apachectl /usr/local/bin/apachectl

To make the webserver start at boot we have to make another link from the apachectl file to the init.d directory. This will make sure the service of the webserver apachectl will be able to be found when using the command chkconfig to set the webserver to start at boot. We will also need to amend the configuration of the file as a valid sysV init file so that it can be read by chkconfig.

prompt> ln -s /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd # as you can see I have renamed the linked file as httpd in the init directory, the purpose of this is for simplicity as most people look for httpd when trying to start or stop a apache web server

Now we need to edit the httpd file we have linked to the init directory to include some sysV init script to help chkconfig identify it as a valid service to start at boot: –

prompt> sudo vi /etc/rc.d/init.d/httpd # If you are not used to using vi to edit files, just use sudo gedit /etc/rc.d/init.d/httpd instead

make sure to add the script below just under the #!/bin/sh and save it: –

#!/bin/sh

#

# Startup script for the Apache Web Server

#

# chkconfig: – 85 15

# description: Apache is a World Wide Web server. It is used to serve

# HTML files and CGI.

# processname: httpd

# pidfile: /usr/local/apache/logs/httpd.pid

# config: /usr/local/apache/conf/httpd.conf

Now all we need to do is tell the system to start the service at boot: –

prompt> chkconfig httpd on

You can make sure that httpd is added to the the startup boot sequence by: –

prompt> chkconfig | grep httpd

you should see something like: –

httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

The above line shows me that the service httpd will start at boot on run levels 2, 3, 4 and 5.

So that should be it now, make sure to reboot and test the webserver to make sure it is working by doing a http://localhost/

As the man pages was not installed automatically, you have to install this manually by creating a symbolic link from the man pages that have been installed in the apache directory to the directory that is purged for manual pages: –

prompt> sudo ln -s /usr/local/apache2/man/man8/httpd.8 /usr/share/man/man8/httpd.8

prompt> sudo ln -s /usr/local/apache2/man/man8/apachectl.8 /usr/share/man/man8/apachectl.8

So now you should be directed to the correct manual pages when you do: –

prompt> man httpd

&

prompt> man apachectl

#Thoughts, if I am going to be installing a lot of applications from source (tarball) it may be wise to learn how to properly make sysV init scripts as it seems we have to do this manually ourselves. If we were to install any applications through rpm or yum then gernerally the sysV init scripts will be added automatically and all you would really need to do is tell the system to turn the service on at boot (chkconfig service on).

How to get started building android applications

To get started on building applications for the Android platform you will need to do the following, which are all free: –

Download Eclipse Integrated Development Environment Download and install Eclipse Classic 3.7.1 From http://www.eclipse.org/downloads/

Download Software Development Kit Download and install Latest Version From http://developer.android.com/sdk/index.html

Download Android Development Tool Install Latest Version using instructions From http://developer.android.com/sdk/eclipse-adt.html

Make sure to install the items in this specific download sequence listed above, i.e. install Eclipse IDE ; SDK ; ADT.

For more information on developing applications on the Android platform ; http://developer.android.com/index.html

PS. As long as you have a good grasp of Java then you should be able to build applications fairly easily.

Japanese Gyozas

image

Attempted to make Japanese Gyozas, they turned out to be pretty tasty. Got the recipe from a Wagamama Recipe Book. Was not too difficult to make, although finding some of the ingredients were a bit tricky.

Sea shells, sea shells on the sea shore

Now that I have had enough of Fallout 3 on the PS3 its time to get back into Linux!

I’ve been learning about Shells…What happens in Linux is that the user inputs instructions/commands into the Shell which in turn interprets them and processes them to the Kernal.

The Kernal then processes the instructions/commands and talks to the appropriate hardware to complete the instruction/command.

The Kernal receives the output of the instruction/command and then processes the output back to the Shell, i.e. where the user is working.

Each Shell has variables, they are broken down into two forms: –

A Local Variable is a variable that can only process variables that have been started in its Shell, i.e. the Bash Shell.

A Environment Variable is a variable that can process commands that have been started in other Shells, i.e. a user may be working in the Bash Shell that has altered the value of a Environment Variable, as this is an Environmental Variable this Variable can be accessed from another Shell, for instance the C Shell.

The most common Shell that is used is the Bash Shell, there are other Shells that are used for other purposes. I believe there is a C Shell which is used for compiling code from the C# language, perhaps this Shell will also have syntax to easily pick up key commands that will help a developer produce their code or find bugs easier?

So, these Variables what do they do exactly?

Well there are many Local & Environmental Variables, they all contain stored values.

For instance the Variable ‘HISTFILE’ shows the location of the stored history file, ‘HISTSIZE’ shows the maximum lines of history commands & arguments the user has typed into the Shell and records this data in the ‘HISTFILE’ variable.

The first 2 commands below show the Environmental Variables that are set for the Shell: –

prompt> env

ORBIT_SOCKETDIR=/tmp/orbit-user

SSH_AGENT_PID=1257

TERM=xterm

SHELL=/bin/bash

XDG_SESSION_COOKIE=85250a19175ea63b09fa29dd4b72f884-1295208313.786947-1525384731

WINDOWID=62914563

GNOME_KEYRING_CONTROL=/tmp/keyring-kwfP0T

GTK_MODULES=canberra-gtk-module

USER=user

LS_COLORS=rs=0:di=01;34:ln=01;36:hl=44;37:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:

SSH_AUTH_SOCK=/tmp/keyring-kwfP0T/ssh

DEFAULTS_PATH=/usr/share/gconf/gnome.default.path

SESSION_MANAGER=local/user-desktop:@/tmp/.ICE-unix/1223,unix/user-desktop:/tmp/.ICE-unix/1223

USERNAME=user

XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg

DESKTOP_SESSION=gnome

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

PWD=/home/user

GDM_KEYBOARD_LAYOUT=gb

LANG=en_GB.utf8

GNOME_KEYRING_PID=1205

MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path

GDM_LANG=en_GB.utf8

GDMSESSION=gnome

SPEECHD_PORT=7560

SHLVL=1

HOME=/home/user

GNOME_DESKTOP_SESSION_ID=this-is-deprecated

LOGNAME=user

XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-pGwUxHIFic,guid=d14491e9ed074785b3d31a434d334f7a

LESSOPEN=| /usr/bin/lesspipe %s

DISPLAY=:0.0

LESSCLOSE=/usr/bin/lesspipe %s %s

XAUTHORITY=/var/run/gdm/auth-for-user-uKD5ZX/database

COLORTERM=gnome-terminal

_=/usr/bin/env

prompt> export

declare -x COLORTERM=”gnome-terminal”

declare -x DBUS_SESSION_BUS_ADDRESS=”unix:abstract=/tmp/dbus-pGwUxHIFic,guid=d14491e9ed074785b3d31a434d334f7a”

declare -x DEFAULTS_PATH=”/usr/share/gconf/gnome.default.path”

declare -x DESKTOP_SESSION=”gnome”

declare -x DISPLAY=”:0.0″

declare -x GDMSESSION=”gnome”

declare -x GDM_KEYBOARD_LAYOUT=”gb”

declare -x GDM_LANG=”en_GB.utf8″

declare -x GNOME_DESKTOP_SESSION_ID=”this-is-deprecated”

declare -x GNOME_KEYRING_CONTROL=”/tmp/keyring-kwfP0T”

declare -x GNOME_KEYRING_PID=”1205″

declare -x GTK_MODULES=”canberra-gtk-module”

declare -x HOME=”/home/user”

declare -x LANG=”en_GB.utf8″

declare -x LESSCLOSE=”/usr/bin/lesspipe %s %s”

declare -x LESSOPEN=”| /usr/bin/lesspipe %s”

declare -x LOGNAME=”user”

declare -x LS_COLORS=”rs=0:di=01;34:ln=01;36:hl=44;37:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:”

declare -x MANDATORY_PATH=”/usr/share/gconf/gnome.mandatory.path”

declare -x OLDPWD

declare -x ORBIT_SOCKETDIR=”/tmp/orbit-user”

declare -x PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games”

declare -x PWD=”/home/user”

declare -x SESSION_MANAGER=”local/user-desktop:@/tmp/.ICE-unix/1223,unix/user-desktop:/tmp/.ICE-unix/1223″

declare -x SHELL=”/bin/bash”

declare -x SHLVL=”1″

declare -x TERM=”xterm”

declare -x USER=”user”

declare -x USERNAME=”user”

declare -x WINDOWID=”62914563″

declare -x XAUTHORITY=”/var/run/gdm/auth-for-user-uKD5ZX/database”

declare -x XDG_CONFIG_DIRS=”/etc/xdg/xdg-gnome:/etc/xdg”

declare -x XDG_DATA_DIRS=”/usr/share/gnome:/usr/local/share/:/usr/share/”

declare -x XDG_SESSION_COOKIE=”85250a19175ea63b09fa29dd4b72f884-1295208313.786947-1525384731″

user@user-desktop:~$

Whilst the command below shows a combination of Local & Environmental Variables that have been set for all Shell types: –

prompt> set

BASH=/bin/bash

BASHOPTS=checkwinsize:cmdhist:expand_aliases:extglob:extquote:force_fignore:histappend:interactive_comments:progcomp:promptvars:sourcepath

BASH_ALIASES=()

BASH_ARGC=()

BASH_ARGV=()

BASH_CMDS=()

BASH_COMPLETION=/etc/bash_completion

BASH_COMPLETION_COMPAT_DIR=/etc/bash_completion.d

BASH_COMPLETION_DIR=/etc/bash_completion.d

BASH_LINENO=()

BASH_SOURCE=()

BASH_VERSINFO=([0]=”4″ [1]=”1″ [2]=”5″ [3]=”1″ [4]=”release” [5]=”i486-pc-linux-gnu”)

BASH_VERSION=’4.1.5(1)-release’

COLORTERM=gnome-terminal

COLUMNS=207

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-pGwUxHIFic,guid=d14491e9ed074785b3d31a434d334f7a

DEFAULTS_PATH=/usr/share/gconf/gnome.default.path

DESKTOP_SESSION=gnome

DIRSTACK=()

DISPLAY=:0.0

EUID=1000

GDMSESSION=gnome

GDM_KEYBOARD_LAYOUT=gb

GDM_LANG=en_GB.utf8

GNOME_DESKTOP_SESSION_ID=this-is-deprecated

GNOME_KEYRING_CONTROL=/tmp/keyring-kwfP0T

GNOME_KEYRING_PID=1205

GROUPS=()

GTK_MODULES=canberra-gtk-module

HISTCONTROL=ignoreboth

HISTFILE=/home/user/.bash_history

HISTFILESIZE=500

HISTSIZE=500

HOME=/home/user

HOSTNAME=user-desktop

HOSTTYPE=i486

IFS=$’ \t\n’

LANG=en_GB.utf8

LESSCLOSE=’/usr/bin/lesspipe %s %s’

LESSOPEN=’| /usr/bin/lesspipe %s’

LINES=54

LOGNAME=user

LS_COLORS=’rs=0:di=01;34:ln=01;36:hl=44;37:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.

taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31

:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*

.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.

rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=0

0;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:’

MACHTYPE=i486-pc-linux-gnu

MAILCHECK=60

MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path

OPTERR=1

OPTIND=1

Lets say we wanted to change the ‘HISTSIZE’ to only display the last 100 commands that we use in the Shell when we cycle through them using the up arrow on the keyboard. To limit the ‘HISTSIZE’ to only the last 100 entries we would do so like this: –

prompt> HISTSIZE=100 ### Limiting the HISTSIZE to 100

prompt> echo $HISTSIZE ### seeing what value the HISTSIZE now has

100 ### The HISTSIZE is now 100 as you can see!

The above example was setting a Local Variable to the Shell we are working on only. Lets say that we wanted this Variable to be used for all other Shells and to keep the same value too? Then we would set the Environmental Variable to 100 and it will be shared across all Shells that will be used on the system! See example below: –

prompt>exportHISTSIZE=100

prompt>echo $HISTSIZE ### Now if we were to use another Shell like C shell and then type this command to see what the value of HISTSIZE is then we would get the same value as below

100

There are many variables that you can edit the value of, some are more useful than others. For example lets say that you want to change the prompt to show where you are on every command line, then you would edit the ‘PS1’ variable like so: –

prompt>PS1=”<\$PWD>” ### To set this as an eniromental variable you can use the work export before the variable just like in the previous example

</home/user> ### The prompt now displays the present working directory on each command line

You can also alter the value of ‘PS1’ so that it shows the user logged in, hostname, ip address, etc on each command line once you are happy with your variable value altering skills

Summary

Will definitely be altering the values of certain variables for a more customized shell that will help me as a user have more beneficial information. There are many other variable values that can be set that include but not limited to: –

HOME, MAIL, PATH, PS2, SHELL, TERM, DISPLAY, etc. maybe a quick google will find more variables that can be altered?

Enough sed

sed is similar to awk but with one main difference. The sed command processes text from rows and prints them out. For example lets say that in the below example we want to see all the rows that contain the size 4.0K.

prompt> ls -lh

total 96K

drwxr-xr-x 2 root root 4.0K 2010-11-24 19:46 bin

drwxr-xr-x 3 root root 4.0K 2010-11-24 19:50 boot

lrwxrwxrwx 1 root root 11 2010-02-10 17:59 cdrom -> media/cdrom

drwxr-xr-x 18 root root 4.1K 2011-01-04 20:02 dev

drwxr-xr-x 144 root root 12K 2011-01-04 20:04 etc

drwxr-xr-x 3 root root 4.0K 2010-02-10 18:08 home

lrwxrwxrwx 1 root root 33 2010-10-08 19:57 initrd.img -> boot/initrd.img-2.6.32-25-generic

lrwxrwxrwx 1 root root 33 2010-07-31 15:34 initrd.img.old -> boot/initrd.img-2.6.32-24-generic

drwxr-xr-x 20 root root 16K 2010-11-24 19:46 lib

drwx—— 2 root root 16K 2010-02-10 17:59 lost+found

drwxr-xr-x 4 root root 4.0K 2011-01-03 14:25 media

drwxr-xr-x 2 root root 4.0K 2009-10-20 01:04 mnt

drwxr-xr-x 2 root root 4.0K 2009-10-28 20:55 opt

dr-xr-xr-x 149 root root 0 2011-01-04 20:02 proc

drwx—— 11 root root 4.0K 2010-12-03 17:31 root

drwxr-xr-x 2 root root 4.0K 2010-11-24 19:48 sbin

drwxr-xr-x 2 root root 4.0K 2009-10-20 00:05 selinux

drwxr-xr-x 2 root root 4.0K 2009-10-28 20:55 srv

drwxr-xr-x 12 root root 0 2011-01-04 20:02 sys

drwxrwxrwt 19 root root 4.0K 2011-01-04 20:14 tmp

drwxr-xr-x 10 root root 4.0K 2009-10-28 20:55 usr

drwxr-xr-x 15 root root 4.0K 2009-10-28 21:02 var

lrwxrwxrwx 1 root root 30 2010-10-08 19:57 vmlinuz -> boot/vmlinuz-2.6.32-25-generic

lrwxrwxrwx 1 root root 30 2010-07-31 15:34 vmlinuz.old -> boot/vmlinuz-2.6.32-24-generic

Then what we would do is call sed to print the specific rows that contain the characters 4.0K like in the example below: –

prompt> ls -lh | sed -n ‘/4.0K/p’ ### -n is used to only print the lines containing the pattern

drwxr-xr-x 2 root root 4.0K 2010-11-24 19:46 bin

drwxr-xr-x 3 root root 4.0K 2010-11-24 19:50 boot

drwxr-xr-x 3 root root 4.0K 2010-02-10 18:08 home

drwxr-xr-x 4 root root 4.0K 2011-01-03 14:25 media

drwxr-xr-x 2 root root 4.0K 2009-10-20 01:04 mnt

drwxr-xr-x 2 root root 4.0K 2009-10-28 20:55 opt

drwx—— 11 root root 4.0K 2010-12-03 17:31 root

drwxr-xr-x 2 root root 4.0K 2010-11-24 19:48 sbin

drwxr-xr-x 2 root root 4.0K 2009-10-20 00:05 selinux

drwxr-xr-x 2 root root 4.0K 2009-10-28 20:55 srv

drwxrwxrwt 19 root root 4.0K 2011-01-04 20:14 tmp

drwxr-xr-x 10 root root 4.0K 2009-10-28 20:55 usr

drwxr-xr-x 15 root root 4.0K 2009-10-28 21:02 var

Similarly if we want to see all rows that do not contain 4.0K then we would use the same command but different argument as below: –

prompt> ls -lh | sed ‘/4.0K/d’ #### d for do not display the rows that contain the characters between and

total 96K

lrwxrwxrwx 1 root root 11 2010-02-10 17:59 cdrom -> media/cdrom

drwxr-xr-x 18 root root 4.1K 2011-01-04 20:02 dev

drwxr-xr-x 144 root root 12K 2011-01-04 20:04 etc

lrwxrwxrwx 1 root root 33 2010-10-08 19:57 initrd.img -> boot/initrd.img-2.6.32-25-generic

lrwxrwxrwx 1 root root 33 2010-07-31 15:34 initrd.img.old -> boot/initrd.img-2.6.32-24-generic

drwxr-xr-x 20 root root 16K 2010-11-24 19:46 lib

drwx—— 2 root root 16K 2010-02-10 17:59 lost+found

dr-xr-xr-x 150 root root 0 2011-01-04 20:02 proc

drwxr-xr-x 12 root root 0 2011-01-04 20:02 sys

lrwxrwxrwx 1 root root 30 2010-10-08 19:57 vmlinuz -> boot/vmlinuz-2.6.32-25-generic

lrwxrwxrwx 1 root root 30 2010-07-31 15:34 vmlinuz.old -> boot/vmlinuz-2.6.32-24-generic

As you can see in the above example the rows that contained the data of 4.0K has been omitted from the printed data.

Furthermore sed can be used to replace the printed output of a command/files contents from one string of characters to another string of characters, e.g. lets say on the above example we want to substitute the word root with ADMIN, then this is how we would do it: –

prompt> ls -lh | sed -e ‘/4.0K/d’ -e ‘s/root/ADMIN/g’

total 96K

lrwxrwxrwx 1 ADMIN ADMIN 11 2010-02-10 17:59 cdrom -> media/cdrom

drwxr-xr-x 18 ADMIN ADMIN 4.1K 2011-01-04 20:02 dev

drwxr-xr-x 144 ADMIN ADMIN 12K 2011-01-04 20:04 etc

lrwxrwxrwx 1 ADMIN ADMIN 33 2010-10-08 19:57 initrd.img -> boot/initrd.img-2.6.32-25-generic

lrwxrwxrwx 1 ADMIN ADMIN 33 2010-07-31 15:34 initrd.img.old -> boot/initrd.img-2.6.32-24-generic

drwxr-xr-x 20 ADMIN ADMIN 16K 2010-11-24 19:46 lib

drwx—— 2 ADMIN ADMIN 16K 2010-02-10 17:59 lost+found

dr-xr-xr-x 150 ADMIN ADMIN 0 2011-01-04 20:02 proc

drwxr-xr-x 12 ADMIN ADMIN 0 2011-01-04 20:02 sys

lrwxrwxrwx 1 ADMIN ADMIN 30 2010-10-08 19:57 vmlinuz -> boot/vmlinuz-2.6.32-25-generic

lrwxrwxrwx 1 ADMIN ADMIN 30 2010-07-31 15:34 vmlinuz.old -> boot/vmlinuz-2.6

Note: – when using more than one string as arguments we need to add -e to tell the command to execute the argument. The s in the above example is telling sed to substitute the string root to ADMIN and the g is used to enforce the substitute

Summary

A good command to manipulate what rows you want to see based on the characters that you choose to display or not within the rows

awkward right?

There my be times in which I will need certain columns of information instead of viewing all the columns that gets printed in the terminal. In the below example I only want to see columns 1, 3 & 8 I do not want to see all the columns: –

prompt> ls -l

total 96

drwxr-xr-x 2 root root 4096 2010-11-24 19:46 bin

drwxr-xr-x 3 root root 4096 2010-11-24 19:50 boot

lrwxrwxrwx 1 root root 11 2010-02-10 17:59 cdrom -> media/cdrom

drwxr-xr-x 18 root root 4120 2011-01-03 20:36 dev

drwxr-xr-x 144 root root 12288 2011-01-03 20:39 etc

drwxr-xr-x 3 root root 4096 2010-02-10 18:08 home

lrwxrwxrwx 1 root root 33 2010-10-08 19:57 initrd.img -> boot/initrd.img-2.6.32-25-generic

lrwxrwxrwx 1 root root 33 2010-07-31 15:34 initrd.img.old -> boot/initrd.img-2.6.32-24-generic

drwxr-xr-x 20 root root 16384 2010-11-24 19:46 lib

drwx—— 2 root root 16384 2010-02-10 17:59 lost+found

drwxr-xr-x 4 root root 4096 2011-01-03 14:25 media

drwxr-xr-x 2 root root 4096 2009-10-20 01:04 mnt

drwxr-xr-x 2 root root 4096 2009-10-28 20:55 opt

dr-xr-xr-x 143 root root 0 2011-01-03 20:36 proc

drwx—— 11 root root 4096 2010-12-03 17:31 root

drwxr-xr-x 2 root root 4096 2010-11-24 19:48 sbin

drwxr-xr-x 2 root root 4096 2009-10-20 00:05 selinux

drwxr-xr-x 2 root root 4096 2009-10-28 20:55 srv

drwxr-xr-x 12 root root 0 2011-01-03 20:36 sys

drwxrwxrwt 18 root root 4096 2011-01-03 20:41 tmp

drwxr-xr-x 10 root root 4096 2009-10-28 20:55 usr

drwxr-xr-x 15 root root 4096 2009-10-28 21:02 var

lrwxrwxrwx 1 root root 30 2010-10-08 19:57 vmlinuz -> boot/vmlinuz-2.6.32-25-generic

lrwxrwxrwx 1 root root 30 2010-07-31 15:34 vmlinuz.old -> boot/vmlinuz-2.6.32-24-generic

So to see just the columns I want to see and not see any other columns I can use the awk command, as below:-

prompt> ls -l | awk ‘{print “permission”,$1,”owner”,$3,”name=”$8}’

permission total owner name=

permission drwxr-xr-x owner root name=bin

permission drwxr-xr-x owner root name=boot

permission lrwxrwxrwx owner root name=cdrom

permission drwxr-xr-x owner root name=dev

permission drwxr-xr-x owner root name=etc

permission drwxr-xr-x owner root name=home

permission lrwxrwxrwx owner root name=initrd.img

permission lrwxrwxrwx owner root name=initrd.img.old

permission drwxr-xr-x owner root name=lib

permission drwx—— owner root name=lost+found

permission drwxr-xr-x owner root name=media

permission drwxr-xr-x owner root name=mnt

permission drwxr-xr-x owner root name=opt

permission dr-xr-xr-x owner root name=proc

permission drwx—— owner root name=root

permission drwxr-xr-x owner root name=sbin

permission drwxr-xr-x owner root name=selinux

permission drwxr-xr-x owner root name=srv

permission drwxr-xr-x owner root name=sys

permission drwxrwxrwt owner root name=tmp

permission drwxr-xr-x owner root name=usr

permission drwxr-xr-x owner root name=var

permission lrwxrwxrwx owner root name=vmlinuz

permission lrwxrwxrwx owner root name=vmlinuz.old

Lets split that up a bit to understand it.

awk ### is the command

‘{print “permission”,$1,”owner”,$3,”name=”$8}’ ### and the remainder of the line is the arguments

In the arguments I am asking to print on the terminal the columns ($1, $3, $8) and I am asking for the words to be printed before the columns (these are the words between double quotes : “permission”, “owner”, “name). So command first awk followed by the arguments between ‘{ and }’

Note : The columns go in logical, i.e. if we want to call column 1, then that would be $1, if we wanted to call column 5, that would be $5, etc

Summary

Good command to manipulate the specific columns of data you want to see

The writings on the wall

The wall is a useful command used to broadcast a message to all users currently logged on to the system. The wall command can be used for instance if you need to notify all users currently logged in that the system will be going down for maintenance and that they should save their important documents and log off. e.g: –

prompt> wall ### hit return and then you can start typing your message

please note that thy system will go down for routine maintenance at 21:00 hours, please save any important documents and log off before 21:00 hours as those that do not will be logged off automatically!            ### Once you are happy with your message press Ctrl+d on your keyboard to broadcast the message to all users currently logged on to the system

 

Broadcast Message from user@hostname

(/dev/pts/0) at 21:15 …

 

please note that thy system will go down for routine maintenance at 21:00 hours

, please save any important documents and log off before 21:00 hours as those t

hat do not will be logged off automatically!

 

Summary

Quite simply really but a very useful command

Sticky Bit

The sticky bits purpose is to prevent the accidental deletion of directories by other users other than the original owner who created the directory.

As you can see in the example below, the sticky bit is set on the directory below, this means that other users can not delete the directory only the owner of the directory can delete the folder : –

prompt> ls -dl /tmp

drwxrwxrwt 18 root root 4096 2010-12-31 20:25 /tmp

As you can see in the above example, the directory has a t which symbolises the directory has a sticky bit enabled on this directory, hence no one but root can delete this directory.

Below is an example of how to remove the sticky point from the above example to allow other users to delete the directory, please note it is not advisable to do this on the directory in the example, the example only serves as an example of how to enable/disable the sticky bits on a specific directory: –

prompt> chmod o-t /tmp ### Change modify others (o) privileges to take away the stick bit

prompt> ls -dl /tmp

drwxrwxrwx 18 root root 4096 2010-12-31 20:25 /tmp ### As you can see the sticky bit has been removed, i.e. there is no t that denoted that the sticky bit was enabled on the directory

To enable the sticky bit on the directory you use the same symbolic notation method to do so: –

prompt>chmod o+t /tmp ### This time add the sticky bit to the directory to enable it

prompt> ls -dl/tmp

drwxrwxrwt 18 root root 4096 2010-12-31 20:25 /tmp           ### As you can see the t denotes that the sticky bit has indeed been enabled on the directory

Summary

The main reason to use the sticky bit would be to prevent users deleting other users directories by accident

setuid Bit & setgid Bit

Looking at setuid Bit & setgid Bit

The setuid Bit is what enables a file to be executed at the owners permission levels. For example a command that is used a lot by different users can have a setuid Bit set on it, this eliminates the need to switch to the user who owns the file or change the current permissions set to execute the file in question. E.g.: –

prompt> ls -l ls ### Use this ‘ls’ command to find out what permissions are set for ‘ls’

-rwxr-xr-x 1 root root 104528 2010-09-21 19:33 ls ### As you can see this is executable

Now to make the above file executable by any user that runs the file : –

prompt> chmod u+s /bin/ls ### Add the setuid Bit to user

prompt> ls -l ls

-rwsr-xr-x 1 root root 104528 2010-09-21 19:33 ls ### Now you can see that ‘s‘ has replaced the previous x which means that this file can now be executed by any user at the owners permission level

To remove the setuid bit, you just do the following: –

prompt> chmod u-s /bin/ls

prompt> ls -l ls

-rwxr-xr-x 1 root root 104528 2010-09-21 19:33 ls ### And as you can see the setuid Bit has now been removed

If a command/file needs to be executed frequently that was not created by the current user then setting the setuid bit will enable all users to execute the file/command as the file/command will be executed at the same level of the owner of the file/command

PS. The same applies to setting a file/command executable on a group basis, the only difference is the command to set/remove the setgid Bit on the group permissions of a file is chmod g+s filename & chmod g-s filenamerespectively.