Thursday, October 4, 2007

Hot Keys for bash shell

Ctrl + l - Clears the Screen.
Ctrl + r - Does a search in previously given commands in shell.
Ctrl + u - Clears the typing before the hotkey.
Ctrl + a - Places cursor at the beginning of the command at shell.
Ctrl + e - Places cursor at the end of the command at shell.
Ctrl + f - Move forward by one Character
Ctrl + b - Move back by one Character
Ctrl + k - Clear from the current cursor position to the end of the line
Ctrl + w - Clear (word )from the current cursor position to Prwevious white space
Ctrl + d - Kills the shell.
Ctrl + z - Places the currently running process into background.
Ctrl + c - Kill the Process
---------------------------------
Disk Usage of file sizes under each directory in current Directory ?
du -k * | sort -nr (or) du -k . | sort -nr
-------------------------------------------
Display the all files recursively with path under current directory ?
- find . -depth -print
---------------------------------------
List the file by file Size
ls -lrt | sort -nr
-------------------------
Display the parent/child tree of a process ?
ptree Example: ptree 1267
-----------------------------------------------
Show the working directory of a process ?
pwdx Example: pwdx 1267
------------------------------------------------
Display the processes current open files ?
pfiles Example: pfiles 1267

Monday, August 13, 2007

Some VI commands we must know

To go to line
esc linno G            ---> esc 5 G

to go to last line     ---> G

to go to First line   ---> 1 + G

u               ----> undo
cntrl + r   ----> redo

:set nu              to show line no
:set nonu         hide line no
:synt off         Deactivate syntax
:synt on         activate syntax

SEARCH and REPLACE String in VI

First occurrence on current line :s/OLD/NEW

Globally (all) on current line :s/OLD/NEW/g

Between two lines #,#: :#,#s/OLD/NEW/g

Every occurrence in file: :%s/OLD/NEW/g

Working with multiple files

:e filename Edit a file in a new buffer
:bnext (or :bn) go to next buffer
:bprev (of :bp) go to previous buffer
:bd delete a buffer (close a file)
:sp filename Open a file in a new buffer and split window
ctrl+ws Split windows
ctrl+ww switch between windows
ctrl+wq Quit a window
ctrl+wv Split windows vertically


# Scroll forward a page with ---- ctrl-f
# Scroll back a page with ---- ctrl-b
# Scroll forward half a page with ---- ctrl-d
# Scroll back half a page with ---- ctrl-u
#move forward to the beginning of a word with w or W
#move forward to the end of a word with e or E
#move backward to the beginning of a word with b or B
-------------------------

Some Vim settings

set tabstop=4 "number of chars to be inserted when tab is used"
set shiftwidth=4 "To change the no. of space chars inserted for indent"
set softtabstop=4 "makes the spaces feel like real tabs"
set expandtab "convert the tabs to spaces"
we can put it in .vimrc

Vim Link
http://www.vim.org/tips/tip.php?tip_id=12

Friday, July 13, 2007

Cscope with CTAGS

Run this in the main Source code directory
to build the data base
cscope -b -q -R
-b = build
-q = qick
-R = recursive
Note by default cscope takes .c and .h only.  If files are in .cpp .cc or .java then use cscope.files
find . -name '*.cc' > cscope.files
find . -name '*.c' >> cscope.files

build cscope Database as

cscope -b
or cscope -b -q -k

-k = kernel mode
To open Cscope for code browsing :
cscope -d
-d = do not build

it will open menu to search
use Tab to change the fields
for CTAGS

find . -name "*.h" > cscopefileslist.txt
find . -name "*.c" >> cscopefileslist.txt

ctags -aBF -L cscopefileslist.txt
explaination
-a Append output to an existing tags file.
-B Use backward searching patterns (?...?).
-F Use forward searching patterns (/.../) (default).---------
# Ctrl-] Find the tag under the cursor.
# Ctrl-T Return to previous location before jump to tag.

Change default editor of cscope to VIM :
By default cscope opens file through Vi to change that do these in .bashrc
VISUAL=/usr/bin/vim;
export VISUAL;
EDITOR=/usr/bin/vim;
export EDITOR;

To set default shell as BASH change .profile

Monday, July 9, 2007

Some Commands

linux# lspci -v
list all pci buses and the devices connected to them

linux# lsusb
ist all USB buses and the devices connected to them
linux# fdisk -l
for partition
linux#demsg
dmesg - print or control the kernel ring buffer

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.