posts - 3, comments - 0, trackbacks - 0, articles - 1
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

2011年12月17日

Shell, shell script and other scripts are very important to learn and master linux.

  1. Fetch lines containing 'MAN' from /etc/man.config, and exclude comment lines.
    $ cat /etc/man.config | grep 'MAN' | grep  -v '^#'
    $ cat /etc/man.config | grep 'MAN' | sed 's/#.*$//g' | sed '/^$/d'
  2. Delete comment and blank lines using extended regular express.
    $ egrep -v '^$|^#' /etc/man.config

posted @ 2011-12-17 14:50 CT 阅读(116) | 评论 (0)编辑 收藏

2011年12月15日

# Note: using '#' as command prompt.

# dd if=/dev/zero of=/tmp/swap bs=1M count=512
# mkswap /tmp/swap
# free; swapon /tmp/swap; free

posted @ 2011-12-15 09:49 CT 阅读(149) | 评论 (0)编辑 收藏

2011年12月13日

Linux shell commands which will be used: groupadd, useradd, usermod, gpasswd, id, mkdir, ll, chgrp, chmod, su, cd, touch.
// Note: '#' is used as command prompt.

1) use perl as script to handle the new users adding.
#!/usr/bin/perl
$user=$ARGV[0];
$passwd=$ARGV[1];
if (!$user || !$passwd)
{
   print "Note: user name and passwd cannot be NULL.\n";
   exit 0;
}
@saltchars = (a..z, A..Z, 0..9); # as a whole for assignment
srand(time || $$);
$salt = $saltchars[rand($#saltchars)].$saltchars[rand($#saltchars)]; # $# is the last index of array
$encrypt_passwd = crypt($passwd, $salt);
$add_exec = "/usr/sbin/useradd -p ".$encrypt_passwd." ".$user;                                
print $add_exec."\n ";
system($add_exec);
#This perl script runs well in perl v5.10.1 built for i386-linux-thread-multi using root permission.
#saved this file as user_add.pl and
#chmod u+x user_add.pl
#./user_add.pl Tom 123456
#./user_add.pl Lily 123456
2) groupadd project; gpasswd -a Tom project; gpasswd -a Lily project; id Tom; id Lily;
3) mkdir /home/workspace; chgrp project /home/workspace; chmod 2770 /home/workspace;
#Now, directory '/home/workspace' can be shared by Tom and Lily for working or studying together.
#su, cd, touch, ll and other shell commands can be used to do a testing.

posted @ 2011-12-13 14:16 CT 阅读(145) | 评论 (0)编辑 收藏