Thursday, June 28, 2007

Know ur System n os

uname
options:
-a, --all print all information, in the following order,
-s, --kernel-name print the kernel name
-n, --nodename   =  sysctl-a | grep kernel.hostname print the network node hostname
-r, --kernel-release   = sysctl-a | grep kernel.osrelease  print the kernel release
-v, --kernel-version  = sysctl-a | grep kernel.version  print the kernel version
-m, --machine print the machine hardware name
-p, --processor print the processor type or "unknown"
-i, --hardware-platform print the hardware platform or "unknown"
-o, --operating-system print the operating system

sysctl -a also gives lot of information

TO know current shell

echo $SHELL
wrong as it gives the default shell path as set in the $SHELL variable
example:
mycomp@mydomain:/proc$ echo $SHELL
/bin/bash
mycomp@mydomain:/proc$ sh
$ echo $SHELL note :shell is sh here not bash
/bin/bash

SOlution use $$ which qives pid of current shell
ps -eaf | grep $$ | head -1 | tr -s ' ' ' ' | cut -f8 -d" "
it includes 5 steps
1 & 2 will get the lines of process of (current)shell and processes spawend by the current shell
i.e
$ ps -eaf | grep $$
tbxk67 20253 19978 0 13:35 pts/3 00:00:00 bash
tbxk67 21049 20253 0 14:01 pts/3 00:00:00 ps -eaf
tbxk67 21050 20253 0 14:01 pts/3 00:00:00 grep 20253
3) head -1 : to Extract the first line
NOw we need the last column for that we have to cut it But we need a delimiter for that
lets use single space for that
but the output which we have has multiple spaces what to do ??
4) we can translate multiple Spaces to single Spaces
tr command Very useful
cat file7 | tr '[A-Z]' '[a-z]' > file8 changes all Capital letter to small leters

tr [ options ] [ set1 [ set2 ] ]
options -d to delete ,ex cat temp | tr -d [123456789] delete all numbers
-s to squezze (to remove repetation : we will use this )
cat file | tr -s ' ' ' ' >newfile
or tr -s' ' ' ' < file9 > file10
repeated element of set 1 will be changed to single instance of set2

5)STEP is to cut on the basis of -d" " get -f8 (8 field )
example of cut
cut -f4-7 -d"" foo # cuts fields 4, 5, 6, and 7 from foo.
cut -f5- -d: foo # would cut from field 5 to the end of the line from foo delimitter is coclon

Wednesday, June 27, 2007

FIle command n Type command

File command
performs three sets of tests, performed in this order: filesystem tests, magic number tests, and language tests. The first test that succeeds causes the file type to be printed.

File system test : checks for "text" (the file contains only printing characters and a few common control characters and is probably safe to read on an ASCII terminal),

" executable" (the file contains the result of compiling a program in a form understandable to some UNIX kernel or another),
or "data" meaning anything else (data is usually `binary' or non-printable)


example
$file dirname
dirname:directory
$file a.out
a.out:ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU
$file examine.html
examine.html: HTML document text
$file view_this picture.gif
view_this: ASCII English text
picture.gif: GIF image data, version 89a, 88 x 31

My Linux learnings

HI
daily i will learn something new in linux and post it here to share the same with others......

Tuesday, June 26, 2007

hit counter
Hit counter provided by website hit counters site.