Programmer's Blog

Programmer's reference

Category Archives: Linux

[gdb] Commands for examining program in assembly

i r
i all-r
i f
i proc m
disas 
x/4xw (10w) $sp
x/5i
x/i $pc

[vim] settings for .vimrc

set hidden

set nowrap        " don't wrap lines
set tabstop=4     " a tab is four spaces
set backspace=indent,eol,start
                    " allow backspacing over everything in insert mode
set autoindent    " always set autoindenting on
set copyindent    " copy the previous indentation on autoindenting
set number        " always show line numbers
set shiftwidth=4  " number of spaces to use for autoindenting
set shiftround    " use multiple of shiftwidth when indenting with '<' and '>'
set showmatch     " set show matching parenthesis
set ignorecase    " ignore case when searching
set smartcase     " ignore case if search pattern is all lowercase,
                    "    case-sensitive otherwise
set smarttab      " insert tabs on the start of a line according to
                    "    shiftwidth, not tabstop
set hlsearch      " highlight search terms
set incsearch     " show search matches as you type
set history=1000         " remember more commands and search history
set undolevels=1000      " use many muchos levels of undo
set wildignore=*.swp,*.bak,*.pyc,*.class
set title                " change the terminal's title
set visualbell           " don't beep
set noerrorbells         " don't beep
set nobackup
set noswapfile

[regex] inverse selection

/\<\(THEWORD\>\)\@!\k\+\>

[Linux] Useful commands

Execute commands on files found by the find command
$ find -iname "MyCProgram.c" -exec md5sum {} \;

Find all empty files in home directory
# find ~ -empty

converts the DOS file format to Unix file format using sed command.
$sed 's/.$//' filename

Print only specific field from a file.
$ awk '{print $2,$5;}' employee.txt

Go to the 143rd line of file
$ vim +143 filename.txt

Open the file in read only mode.
$ vim -R /etc/passwd

[C++] Check memory leaks by top

top -b -n 1

To see applications which are leaking memory, look at the following columns:

RPRVT – resident private address space size
RSHRD – resident shared address space size
RSIZE – resident memory size
VPRVT – private address space size
VSIZE – total memory size

[RHEL] update dev packages

yum update

yum install libtool gcc-c++ glib*

# This installs autoconf, automake, cloog-ppl, cpp, gcc, mpfr, ppl

yum groupinstall "development tools"

[Linux] Script for change hostID

#!/bin/bash

if [[ -n "$1" ]]; then
 host_id=$1
 # chars must be 0-9, a-f, A-F and exactly 8 chars
 egrep -o '^[a-fA-F0-9]{8}$' <<< $host_id || exit 1
else
 host_id=$(hostid)
fi

a=${host_id:6:2}
b=${host_id:4:2}
c=${host_id:2:2}
d=${host_id:0:2}

echo -ne \\x$a\\x$b\\x$c\\x$d > /etc/hostid &&
 echo "Success" 1>&2

exit 0

[Linux] Reverse all lines in vi/vim

:g/^/m0

[Linux] filter distinct rows in vim

:sort u

[Linux] Crontab Settings

#crontab –e

0 30 * * * * /root/runcorn.sh > /dev/null 2>&1

//format of the cron time
# Minute   Hour   Day of Month       Month          Day of Week        Command    
# (0-59)  (0-23)     (1-31)    (1-12 or Jan-Dec)  (0-6 or Sun-Sat)                
    0        2          12             *                *            /usr/bin/find