Showing posts with label Linux Commands. Show all posts
Showing posts with label Linux Commands. Show all posts

Monday, May 12, 2014

Screen Command in Linux

screen:
=========
Ctrl-a c Create new window (shell)
Ctrl-a k Kill the current window (could be ctrl+a <shift k>)
Ctrl-a w List all windows (the current window is marked with "*")
Ctrl-a 0-9 Go to a window numbered 0-9
Ctrl-a n Go to the next window
Ctrl-a Ctrl-a Toggle between the current and previous window
Ctrl-a [ Start copy mode
Ctrl-a ] Paste copied text
Ctrl-a ? Help (display a list of commands)
Ctrl-a Ctrl-\ Quit screen
Ctrl-a D (Shift-d) Power detach and logout
Ctrl-a d Detach but keep shell window open
Ctrl-a Esc TO SCROLL THROUGH THE PREVIOUS BUFFERS (V V USEFUL)

References:
http://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/
http://aperiodic.net/screen/quick_reference

Tuesday, October 11, 2011

Sample vimrc file

For vimdiff colorschemes:
- Download github & molokai like below

curl -fLo ~/.vim/colors/molokai.vim --create-dirs https://raw.githubusercontent.com/tomasr/molokai/master/colors/molokai.vim
curl -fLo ~/.vim/colors/github.vim --create-dirs https://raw.githubusercontent.com/endel/vim-github-colorscheme/master/colors/github.vim
Then add the below in .vimrc file
if &diff
"   colorscheme github
    colorscheme molokai
endif
<or> ":colorscheme github" diff mode

syntax enable
set incsearch
set nocompatible
set showcmd
set hlsearch
set ai
set si
set ts=4 sw=4 smarttab
set nu
"set nowrap
set formatoptions+=r
set softtabstop=4
set smartindent
set autoindent
set showmatch
"set cursorline

source $HOME/.vim/plugin/taglist.vim
source $HOME/.vim/plugin/comments.vim

"highlight DiffAdd term=reverse cterm=bold ctermbg=white ctermfg=black
"highlight DiffChange term=reverse cterm=bold ctermbg=cyan ctermfg=black
"highlight DiffText term=reverse cterm=bold ctermbg=gray ctermfg=black
"highlight DiffDelete term=reverse cterm=bold ctermbg=cyan ctermfg=black

nnoremap <silent> <F1> :TlistToggle<CR>
"map <C-v><C-v> : vs<cr>
"map <C-q> : q<cr>

command CDC lcd %:p:h

hi LineNr   ctermfg=darkyellow
"hi Function ctermfg=cyan
hi Function ctermfg=yellow
"hi Type  ctermfg=cyan
hi Type  ctermfg=lightred
hi String ctermfg=darkgreen
"hi String ctermfg=150
hi Number ctermfg=brown
"hi Operator ctermfg=brown
hi Search ctermbg=yellow
hi Conditional ctermfg=green
hi Comment ctermfg=lightblue
"""
"if &term =~ "xterm\\|rxvt"
  " use an orange cursor in insert mode
  "let &t_SI = "\<Esc>]12;orange\x7"
  " use a red cursor otherwise
  "let &t_EI = "\<Esc>]12;red\x7"
  "silent !echo -ne "\033]12;red\007"
  "" reset cursor when vim exits
  "autocmd VimLeave * silent !echo -ne "\033]112\007"
  " use \003]12;gray\007 for gnome-terminal and rxvt up to version 9.21
"endif
highlight Cursor ctermfg=yellow ctermbg=black
"highlight iCursor guifg=white guibg=steelblue
"set guicursor=n-v-c:block-Cursor
"set guicursor+=i:ver100-iCursor
"set guicursor+=n-v-c:blinkon0
"set guicursor+=i:blinkwait10
"""

" Copyright abbreviations
iab cfn /*<CR>Function<CR><CR>Description<CR><CR>Parameter(s)<CR><CR>Return Value<CR>/<Up><Up><Up><Up><Up><Up>
iab todo // TODO Remove this
iab cpr Broadcom Proprietary and Confidential. Copyright © 2019 Broadcom.<CR>All Rights Reserved.<CR>The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.

iab testbin TOPDIR<TAB>= ../../..<CR>MAKEDIR<TAB>= $(TOPDIR)/make<CR><CR>include $(MAKEDIR)/Tools.make<CR>include $(MAKEDIR)/Targets.make<CR>include $(MAKEDIR)/Fabos.make<CR>include $(MAKEDIR)/Man.make<CR><CR>TESTBIN = testbin<CR>TESTBIN_SRCS = testbin.c<CR>TESTBIN_OBJS = $(TESTBIN_SRCS:.c=.o)<CR><CR>$(TESTBIN): $(TESTBIN_OBJS)<CR><TAB>$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)<CR>all:: $(TESTBIN)<CR><CR>clean::<CR><TAB>rm $(TESTBIN) $(TESTBIN_OBJS)


iab log_this #define LOG_THIS(format, ...) { \<CR>if (access("/harish", F_OK) != -1) { \<CR>char buf1[128] = {}; char buf2[256] = {}; \<CR>char tbuf[20] = {}; time_t now = time(0); struct tm *sTm = gmtime(&now); \<CR>strftime(tbuf, sizeof (tbuf), "%Y-%m-%d %H:%M:%S", sTm); \<CR>snprintf(buf1, sizeof (buf1), "[%s %s:%d]" format, tbuf, __func__, __LINE__, ##__VA_ARGS__); \<CR>snprintf(buf2, sizeof (buf2), "echo '%s' >> /harish_log", buf1); \<CR>system(buf2); } }


function! LoadCscope()
  let db = findfile("cscope.out", ".;")
  if (!empty(db))
    let path = strpart(db, 0, match(db, "/cscope.out$"))
    set nocscopeverbose " suppress 'duplicate connection' error
    exe "cs add " . db . " " . path
    set cscopeverbose
  " else add the database pointed to by environment variable
  elseif $CSCOPE_DB != ""
    cs add $CSCOPE_DB
  endif
endfunction
"au BufEnter /* call LoadCscope()

" http://cscope.sourceforge.net/cscope_maps.vim
nmap <C-\>ss :cs find s <C-R>=expand("<cword>")<CR><CR>
"nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>cc :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>tt :cs find t <C-R>=expand("<cword>")<CR><CR>
"nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>ff :cs find f <C-R>=expand("<cfile>")<CR><CR>
"nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
"nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>s :cs find s
nmap <C-\>g :cs find g
nmap <C-\>c :cs find c
nmap <C-\>t :cs find t
nmap <C-\>e :cs find e
nmap <C-\>f :cs find f
nmap <C-\>i :cs find i
nmap <C-\>d :cs find d

" quick fix options
nmap qf :set cscopequickfix=s-,c-,d-,i-,t-,e-
nmap noqf :set cscopequickfix=""
nmap cw :cwindow

"function! AddCscope()
    "echom "Adding CSCOPE file.. please wait"
    "silent! exec "r!goto_base_ws"
    ":cs add cscope.files
"endfunction
"nnoremap <silent> <F3> :call AddCscope()<CR>
"nnoremap <F3> :! ~/bin/goto_base_ws && cd vobs/projects/springboard/fabos <CR>:cs add cscope.files<CR>

Monday, March 7, 2011

Background and Foreground Process

1. When you run a command (process), you can make it to run as a background process using $<cmd> &
2. If you forget to make that command as background, and if you feel you should do it now, then
- Press CTRL+Z (Suspend that process)
- $> bg disown 1 (make that process to be a background
3. Now if you want to check the list of background processes, type $> jobs
4. If you want to bring the background process to foreground, then type
$> fg %1
Again to make it a background process,
$> bg %1

Monday, June 21, 2010

GDB unknown commands

All in gdb> prompt

1. Ctrl + p => To get the previous command
2. p array@sizeof(array) => To print all the array elements
3. set print pretty on => To print the structure elements' values in a neat way
4. p /x => prints the value in hexa decimal format

Tuesday, March 30, 2010

VI keyboard Shortcuts

:set hlsearch (:nohl)

:set mouse=a

:set nocompatible

:set smartindent
:set nowrapscan (to disable the wrap search)

:highlight String ctermfg=red

:highlight search ctermfg=black


  • To indent a block of code, keep the cursor in any of the {} braces, and do =%
  • To comment a block of line, keep the cursor in the first line (from where you want to comment), 
          - press CTRL + v (to enter visual mode)
          - use UP DOWN arrows (or j/k keys) to select the lines
          - press I (shift + i) (this enters into visual mode)
          - type "//" 
          - Once you press ESC, the // will be applied to all the lines you selected.
  • To uncomment a block of code, keep the cursor in the first line (from where you want to uncomment)
          - press CTRL + v (to enter visual mode)
          - select RIGHT LEFT arrows to select only the "//" characters
          - press "d" (to delete all the // characters)
  • To search and replace a text ("src" to "dest"), use
          :%s/src/dest/ ==> Replaces first occurence of "src" in each line
          :%s/src/dest/g ==> Replaces all the occurences of "src" with "dest" in all the lines
          :%s/src/dest/gc ==> Asks for confirmation to replace or not for each occurence


  • Vimdiff commands:
    • ]c - to go to the next change
    • [c - to go to the previous change
    • do - diff obtain; means get the changes from other file
    • dp - diff put; means put the changes into other file

Friday, March 26, 2010

Emacs Keyboard shortcuts

Movements:

M - f  <==> Move forward by one word
M - b <==> Move backward by one word

C - f   <==> Move forward by one letter
C - b  <==> Move backward by one letter
C - p  <==> Move up by one line
C - n  <==> Move down by one line

M - v  <==> PAGE UP
C - v  <==> PAGE DOWN

M - >  <==> Goto end of the file (U have to press "SHIFT" here to enter "<" )
M - <  <==> Goto the beginning of the file (same as above)

File operations:









C - x C- f  <==> To open a file
C - x k  <==> Close the current buffer (kill buffer)


M - d  <==> Delete next word
C - k   <==> Delete current line
C - y   <==> Paste (watever copied)

C - [space] <==> Start marking the portion
C - w  <==> Cut the portion till the cursor is in currently
M - w  <==> Copy the portion till the cursor is in currently

C - x u  <==> Undo last operation

M - g g  <==> Goto the line
M - x replace-string  <==> Search and replace

C - s [string]  <==> To search a string forward
C - r [string]  <==> To search a string backward

Windows:


C - x 0   <==> Close the current window
C - x 1   <==> Close all the windows except current window
C - x 2   <==> Split the current window vertically (means top and bottom)
C - x 3   <==> Split the current window horizontally (means left and right)
C - x o ('o' for 'others')   <==> Switch between windows

Shell:

M -x shell  <==> Open shell (terminal)

Setting Tab Size:


M - x set-variable [ENTER] c-basic-offset [ENTER]  8 <==> Setting tab size to 8


Auto-Indentation:

M -x indented-text-mode   <==> set auto indent (does not work through putty)

To search for a string in all the files in a directory:


M - x grep-find [Enter]  <==> This will generate a command; at the end of the command, give the string you want to search; and also set the directory in which you wana search

Wednesday, May 13, 2009

Frequently used commands

1. To find a file in current directory
find . -name "something.h"

2. To find a file (in current directory) with some text in it
grep "sometext" . -wrn
-r is for recursive; -n is to print the line numbers; -w for "whole" words only

3. To find the dependencies of an exe on .so files
ldd exe-name

4. To remove the debug symbols from an exe
strip --strip-debug or
strip -g or
strip - d

6. To list down exported symbols from kernel
cat /proc/kallsyms | grep "__ksymtab_proc_root"

NOTE: "__ksymtab" prefixed symbols are the symbols exported from the kernel.

7. To install from the spec file
rpm -ba "spec"


8. To find the distribution of the Linux (11.1 or 10.2 or 10.3), use
lsb_release -a
NOTE: lsb stands for Linux Standard Base


9. To find the size of the files (in friendly format) in a directory, go inside that directory
du -ch *