[转]Linux下批量删除0K文件(空文件)

find . -name "*" -type f -size 0c | xargs -n 1 rm -f

用这个还可以删除指定大小的文件,只要修改对应的 -size 参数就行,例如:

find . -name "*" -type f -size 1024c | xargs -n 1 rm -f

就是删除1k大小的文件。(但注意不要用 -size 1k,这个得到的是占用空间1k,不是文件大小1k的)。
如果只要删除文件夹或者名字连接等,可以相应的改 -type 参数,具体细节见 man find

转自: http://hi.baidu.com/wuxicn/item/0911d3eecdc01e0f560f1d96

Centos 6.X 下编译安装deluge

1.安装更新源.

rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
wget -c -O /etc/yum.repos.d/linuxtech.repo http://pkgrepo.linuxtech.net/el6/release/linuxtech.repo

2.安装依赖库

yum install GeoIP PyXML SOAPpy boost-filesystem boost-python boost-system boost-thread pyOpenSSL python-chardet python-fpconst python-setuptools python-simplejson python-twisted-core python-twisted-web python-zope-filesystem python-zope-interface pyxdg rb_libtorrent rb_libtorrent-python python-beaker python-mako python-markupsafe python-twisted python-twisted-web

3.编译安装deluge

wget http://download.deluge-torrent.org/source/deluge-1.3.6.tar.gz
tar zxvf deluge-1.3.6.tar.gz
cd deluge-1.3.6/

#开始编译
python setup.py build
python setup.py install

#建立账户
/usr/sbin/groupadd deluge
useradd deluge -g deluge -s /bin/false

4.配置启动文件,把以下文件保存为/etc/init.d/deluge-daemon

#!/bin/bash
#
# Startup script for deluged
#
# chkconfig: - 86 14
# description: deluged is the Deluge bit torrent daemon. It manages torrents
# processname: deluged
# pidfile: /var/run/deluged.pid
# config:

# Source function library.
. /etc/init.d/functions

# Get network config
. /etc/sysconfig/network

[ "${NETWORKING}" = "no" ] && exit 0

prog=deluged
prog2=deluge
lockfile=/var/lock/subsys/deluged
lockfile2=/var/lock/subsys/deluge

LANG="zh_CN.UTF-8" 
LANGUAGE="zh_CN.UTF-8:zh_CN.UTF-8:zh_CN" 
SUPPORTED="zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en" 
SYSFONT="lat0-sun16"
ulimit -HSn 65535

start() {
  echo -n $"Starting deluged service: "
  daemon --user deluge "$prog $OPTIONS"
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch $lockfile

  echo -n $"Starting deluge web ui: "
  daemon --user deluge "$prog2 --ui web >/dev/null 2>&1 &"
  RETVAL=$(($RETVAL|$?))
  echo
  [ $RETVAL -eq 0 ] && touch $lockfile2

  return $RETVAL
}

stop() {
  echo -n $"Shutting down deluged service: "
  killproc $prog
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f $lockfile

  echo -n $"Shutting down deluge web ui: "
  killproc $prog2
  RETVAL2=$?
  echo
  [ $RETVAL2 -eq 0 ] && rm -f $lockfile2

  return $(($RETVAL|$RETVAL2))
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $prog
        status $prog2
        ;;
  restart)
        stop
        start
        ;;
  reload)
        exit 3
        ;;
  *)
        echo $"Usage: $prog {start|stop|status|restart|reload}"
        exit 1
esac

5.给启动脚本权限&启动deluge

chmod +x /etc/init.d/deluge-daemon
service deluge-daemon start

Centos下编译安装Vnstat.

Vnstat是一个Linux下强大的流量监控软件,使服务器管理员可以使用PHP程序来分析Vnsata的数据库文件来得到可视化的服务器流量图.

1.下载&安装Vnstat

wget http://humdi.net/vnstat/vnstat-1.11.tar.gz
tar zxvf vnstat-1.11.tar.gz
cd vnstat-1.11
make
make install

2.下载&设置init.d启动脚本

wget http://humdi.net/vnstat/init.d/redhat/vnstat -O /etc/init.d/vnstat
chmod +x /etc/init.d/vnstat
service vnstat start
chkconfig vnstat on

3.创建计划任务脚本.

cat << EOF > /usr/sbin/vnstat_dump.sh
#/bin/bash
/usr/bin/vnstat -u -i eth0
EOF

chmod +x /usr/sbin/vnstat_dump.sh

4.设置计划任务
(1).输入crontab -e
(2).加入: */1 * * * * /usr/sbin/vnstat_dump.sh

5.Done

[C++]使用循环输出图形(圆球)

话说这是某次assignment要求要的作业..
P.S: 代码不是我写的,是某个基友算出来的对应关系.

#include
using namespace std;

int main()
{
	for (int i=1; i <= 6; i++)
	{
		for (int k = 1; k <= 10 - (-i*i + 7*i -2) / 2; k++)
			cout << ' ';
		
		for (int j = 1; j <= (-i*i + 7*i -2); j++)
		{
			if((j == 1)||(j == (-i*i + 7*i -2)))
				cout << '*';
			else
				cout << ' ';
		}
		cout << endl;
	}
}

效果图:
20131106220340

[C++]10进制转换二进制(带计算过程)

某次的作业需要我们做10进制到2进制/8进制的转换为了偷懒就随手谢了下面的东西.

#include
using namespace std;

int main()
{
	const int BASE = 2;
	unsigned long num  = 0;
	
	int binaryNum[64] = {0};
	cout << "Enter a number: ";
	cin >> num;
	
	if(!cin.fail() && num > 0)
	{
		int numMod = 0, length = 0;
		while(num != 0)
		{
			numMod = num % BASE;
			binaryNum[length++] = numMod;
			cout << num << " / " <<  BASE << " = " <<
			num / BASE << " + " << numMod << endl;
			num /= BASE;
		}
		
		cout << endl  << "Length: " << length << endl;
		cout << "Result: ";
		for(int i = length-1; i >= 0; i--)
			cout << binaryNum[i];
		cout << endl;
	}
	else
		cerr << "Wrong Input.\n";
 
	return 0;
}

效果图:
20131106214952

Blog搬迁到国内VPS之后的一些吐槽

不知不觉BLOG搬迁到国内的VPS上已经3个多月了. 不得不说,国内电信的VPS对电信的速度真心很快.但是相对的联通和国外线路访问就很悲剧了…….并且在10月之后,中国电信对澳洲TPG几乎熄火,打开Blog的时间增加到5秒以上,而且还伴随着时不时的完全无法访问…ping值常年在390-500之间跳动..

唉,天朝的网络..真心伤不起.