Tuesday, 25 September 2012

sed 去掉windows下的回车符

用 sed 去掉 去掉windows下的回车符
 (注意^M 在linux 下写法 按^M 是回车换行符,输入方法是按住CTRL+v,松开v,按m)
sed -i 's/^M//g' df.txt  

word swith field

Switch field codes [Alt]+[F9]

Monday, 12 March 2012

check if a year is a leap year.

read this codes from Linux Device Driver, think it is good :)
record it here.

/*
 * return 1 if year is leap year, 0 otherwise.
 */
static int inline
leap_year(int year)
{
    return !(year % 400) || ( !(year % 4) && (year % 100)) ;
}

/* Number of days in each month (not leap year). */
static const char no_of_days[] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

Monday, 27 February 2012

usermod command

usermod command

the default path of the command is /usr/sbin

add one user to one group:
here use the option '-a'

from the manul
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                him/her from other groups

/usr/sbin/usermod -a -G group1 user_name

remove one user from one group, you have to move that user to another group:
/usr/sbin/usermod -G group2 user_name