Sunday, October 17, 2010

Colorful BASH prompt: How to display BASH prompt with multiple colors

Add this line to the .bashrc

PS1='\[$(tput bold)$(tput setb 4)$(tput setaf 7)\]\u@\h:\w $ \[$(tput sgr0)\] '


More references:

http://wiki.archlinux.org/index.php/Color_Bash_Prompt
http://www.systhread.net/texts/200703bashish.php
http://www.thegeekstuff.com/2008/09/bash-shell-ps1-10-examples-to-make-your-linux-prompt-like-angelina-jolie/
http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/

How to get the system information from bash command prompt

Process info
: top

  • Then A ([{shift} + A) to have multi-window process view. Do again to go back to normal view
  • Type k and input process ID (PID) to kill a process
  • Type u and input user name to get process from the user alone


Process information
: ps -Af
: ps -u username -Af


Check the free RAM available
: free -m

Hard disk and mounted file systems
: fdisk -l (as root)
: df -hT
: cat  /etc/fstab
: du -h --max-depth=1


Other Hardware info
: uname -a
: cat /proc/cpuinfo
: cat /proc/version

/proc directory contain several info
use cat to read the files in /proc such as

cpuinfo,
devices,
filesystems,
meminfo,
partitions,
swaps,
uptime,
version

: cat /proc/cpuinfo
: cat /proc/version

: dmesg | head -2

: lspci   
(as root) (controllers, etc.) (VERY good report; -v is verbose, -vv is very verbose

: lspci -tv  
(as root) shows tree

: lsusb
: lsusb -tv 
list usb devices,


Network:
: ifconfig -a


From GUI:
: ksysguard
KDE keyboard shortcut Ctrl-ESC (KDE)
New tabs can be added to monitor a variety of stuffs

Log files are stored in /var/log (in RHEL5 and other distros)
As 'root', you can view the system events in 'messages' file.
: sudo tail -20 /var/log/messages
: sudo vi /var/log/messages



A bash script for detecting the linux version and kernel is here, but may not work for all system.


#!/bin/sh
# Detects which OS and if it is Linux then it will detect which Linux Distribution.

OS=`uname -s`
REV=`uname -r`
MACH=`uname -m`

GetVersionFromFile()
{
       VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
}

if [ "${OS}" = "SunOS" ] ; then
       OS=Solaris
       ARCH=`uname -p`
       OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
elif [ "${OS}" = "AIX" ] ; then
       OSSTR="${OS} `oslevel` (`oslevel -r`)"
elif [ "${OS}" = "Linux" ] ; then
       KERNEL=`uname -r`
       if [ -f /etc/redhat-release ] ; then
               DIST='RedHat'
               PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
               REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
       elif [ -f /etc/SuSE-release ] ; then
               DIST=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
               REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`
       elif [ -f /etc/mandrake-release ] ; then
               DIST='Mandrake'
               PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
               REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
       elif [ -f /etc/debian_version ] ; then
               DIST="Debian `cat /etc/debian_version`"
               REV=""

       fi
       if [ -f /etc/UnitedLinux-release ] ; then
               DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
       fi

       OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"

fi

echo ${OSSTR} 


from: http://www.novell.com/coolsolutions/feature/11251.html 
http://www.unix.com/unix-advanced-expert-users/21468-machine.html?t=21468#post83185


Useful Vi editor commands

VI Navigation  [escape key = ]
0  [zero] = Move to beginning of line
G         = Go to end of file
5G        = Move to beginning of 5th line
u         = Undo
.         = Repeat last command
x         = Delete character
dd        = Delete line
dw        = Delete word
d$        = Delete from cursor to end of line
$ then J  = Join/append following line with current
$ then a  = Append input at end of line
A         = Append input at end of line [same as above, but one less key stroke]
i         = Insert text at cursor
/         = Bottom of screen type search string and  will move 
                 cursor to first occurrence

Replace text
 
.  :1,$s /and/AND/g
   ^^^^^   ^   ^  ^
   |||||   |   |  |
   |||||   |   |  \----------- Globally
   |||||   |   \-------------- Replace with
   |||||   \------------------ Find
   |||||
   ||||\---------------------- substitute for text
   |||\----------------------- To last line
   ||\------------------------ separator
   |\------------------------- From line "1"
   \-------------------------- ":" operator to start command processing
Useful tid bit to remove EOL characters from DOS file 
[use key sequence "" together for EOL char]
 :%s/^M$//


Write lines to new file
:1,10w abc     [puts lines 1~10 into file abc]
Change working file from current to file abc [be sure to save first]
:e abc
Read abc file into working file after cursor
:r abc


Execute command from prompt
:!cmd    [where cmd is could be a bash command]
Example ->    :r !date   [inserts time and date at prompt]
From online wiki resource: http://en.wikibooks.org/wiki/Linux_Guide/Using_the_shell

Free HD Video Editing software

KDEnlive for Linux
http://www.kdenlive.org
http://en.wikipedia.org/wiki/Kdenlive

Avidemux for Windows and Linux
http://fixounet.free.fr/avidemux/
http://download.cnet.com/Avidemux/3000-13631_4-10829933.html

Useful Linux command compilation

Set system date/time

: date -s "17 OCT 2010 13:00:00"

: hwclock -systohc



Change the time stamps of files

: touch foo


File Permissions

chmod -R ugoa =+- rwx filename
       ^ ^^^^ ^^^ ^^^     ^
       | |||| ||| |||     |
       | |||| ||| |||     \---------- file or directory
       | |||| ||| |||                 --------------------
       | |||| ||| ||\---------------- Execute
       | |||| ||| |\----------------- Write
       | |||| ||| \------------------ Read
       | |||| |||                     --------------------
       | |||| ||\-------------------- Remove
       | |||| |\--------------------- Add
       | |||| \---------------------- assign
       | ||||                         --------------------
       | |||\------------------------ All
       | ||\------------------------- Others
       | |\-------------------------- Group
       | \--------------------------- User
       |                              --------------------
       \----------------------------- Recursively 
                                      --------------------
       Usage: chmod g+w filename
 
 
From : http://en.wikibooks.org/wiki/Linux_Guide/Using_the_shell 
An excellent resource of information with clear explanations  
 
 
 

Saturday, October 16, 2010

Linux bash command online resources for beginners and experts

These are some of the useful online resources I came across while searching for some Linux bash commands to do certain specific tasks.

1) http://www.linux.org/lessons/tips/cmndline.html