Programmer's Blog

Programmer's reference

Category Archives: Linux

[Linux] set password never expire

//check local user accounts
#> cat /etc/passwd

//show password expiry time span
#> chage -l <username>

//change expiry date to 99999
#> chage -M 99999 <username>

[gdb] Commands for examining program in assembly

i r
i all-r
i f
i proc m
x/4xw (10w) $sp
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


[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


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


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


[Linux] filter distinct rows in vim

:sort u