转到正文

走出Windows

抛弃Windows就是走向高效率

存档

分类: Linux

一般用法是

if [ 条件 ]; then
执行语句
fi

要注意的是,条件要包含在方括号内,且条件和方括号相连的地方要有空格隔开,不然会出错
下面是转自网上的各种条件的写法

1、比较文件
-b file 若文件存在且是一个块特殊文件,则为真
-c file 若文件存在且是一个字符特殊文件,则为真
-d file 若文件存在且是一个目录,则为真
-e file 若文件存在,则为真
-f file 若文件存在且是一个规则文件,则为真
-g file 若文件存在且设置了SGID位的值,则为真
-h file 若文件存在且为一个符合链接,则为真
-k file 若文件存在且设置了"sticky"位的值
-p file 若文件存在且为一已命名管道,则为真
-r file 若文件存在且可读,则为真
-s file 若文件存在且其大小大于零,则为真
-u file 若文件存在且设置了SUID位,则为真
-w file 若文件存在且可写,则为真
-x file 若文件存在且可执行,则为真
-o file 若文件存在且被有效用户ID所拥有,则为真
2、比较字符串
-z string 若string长度为0,则为真
-n string 若string长度不为0,则为真
string1 = string2 若两个字符串相等,则为真
string1 != string2 若两个字符串不相等,则为真
3、比较整数
int1 -eq int2 若int1等于int2,则为真
int1 -ne int2 若int1不等于int2,则为真
int1 -lt int2 若int1小于int2,则为真
int1 -le int2 若int1小于等于int2,则为真
int1 -gt int2 若int1大于int2,则为真
int1 -ge int2 若int1大于等于int2,则为真

!expr 若expr为假则复合表达式为真。expr可以是任何有效的测试表达式
expr1 -a expr2 若expr1和expr2都为真则整式为真
expr1 -o expr2 若expr1和expr2有一个为真则整式为真
注意:作为一个通用的规则,你应该在所有的$变量加上双引号来避免shell发生不正确的变量的替代。例如[ "$XX" -eq 3]中,如果XX为空而没有”“的就变成了[ -eq 3]这样会导致test命令语法错误。加上双引号之后就是["" -eq 3],这样保证test命令成功运行而得到正确的结果。

软件名字叫MELD,ubuntu下面可以用 apt-get install meld 来安装,非常强大,并且很易用,需要的童鞋可以下载来装一下

以我目前使用的为例子

VG名字是 sp
/data/ 是从 /dev/sp/sp_data 挂载来的
那么

#umount /data

增加2G空间

# lvextend -L +2G /dev/sp/sp_data
# e2fsck -f /dev/sp/sp_data
# resize2fs /dev/sp/sp_data
# mount /dev/sp/sp_data /data

减少2G空间

# lvresize -L -2G /dev/sp/sp_data
# e2fsck -f /dev/sp/sp_data
# resize2fs /dev/sp/sp_data
# mount /dev/sp/sp_data /data

Ubuntu 9.10 有个apparmor.
my.cnf里面有段注释

[mysqld]
#
# * Basic Settings
#
#
# * IMPORTANT
# If you make changes to these settings and your system uses apparmor, you may
# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#

查看/etc/apparmor.d/usr.sbin.mysqld, 的确是一些目录的权限设置. 把/var/lib/mysql 改成 /data/mysql.

# /etc/init.d/apparmor restart

在启动mysql就可以成功了

plink -N -D 127.0.0.1:1080 -pw PASSWORD root@xxx.xxx.xxx.xxx

将avi格式视频转换成mpg的可以刻录vcd格式的命令

ffmpeg -i 11.avi -target vcd 11.mpg

将rmvb转换为avi格式

mencoder 11.rmvb -oac mp3lame -lameopts preset=64 -ovc xvid -xvidencopts bitrate=600 -of avi -o 11.avi

引言:前段时间一直没空翻译,所以直接贴了英文版的在上面,可能难为了那些英文比我还烂的童鞋(本人至今公共英语四级未通过),今天拿来翻译下,上面一行是英文,下面一行是中文,翻译的不好的地方请大家指教

Installing the Client Program
安装客户端程序
Install PPTP Client from the Ubuntu Project:
从Ubuntu Project安装PPTP客户端
apt-get install pptp-linux
上面那行是命令,在终端输入的,不翻译了
Installing the Configuration Program
安装配置程序
Note: you may wish to skip the configuration program and configure the client by hand.
注意:你可能想要跳过安装配置程序,并且手工配置客户端
1. add the following lines to the sources list file, /etc/apt/sources.list :
1.添加下面几行到源列表,/etc/apt/sources.list

# James Cameron's PPTP GUI packaging
deb http://quozl.netrek.org/pptp/pptpconfig ./

Note: can use a text editor, or simply cat the lines on to the end of the file using >>, but if you make a mistake in formatting you will likely be told by the apt-get update step.
注意:你可以使用文本编辑器,或者使用 >> cat这几行到文件末端,但是如果你的格式出错了,在apt-get update时可能会出问题

2. update the list of packages:
2.更新包列表

apt-get update
上面是命令

3. install the PPTP Client GUI:
3.安装PPTP客户端GUI程序

apt-get install pptpconfig
上面是命令

Note: you may be told that the packages could not be authenticated. For the moment, tell your system to install them anyway. We'll take patches to our release process if anyone can explain simply how to provide authentication.
这句太麻烦,不翻译了,大概意思是如果系统提示无法验证包,请选择无论如何都安装

Configuration, by hand
手工配置

1. obtain from your PPTP Server administrator:
1.从你的PPTP服务器管理员处获取:

* the IP address or host name of the server ($SERVER),
* 服务器的IP地址或名称(下面用$SERVER代替)
* the name you wish to use to refer to the tunnel ($TUNNEL),
* VPN连接的通道名称(下面用$TUNNEL代替)(译者注:一般情况下,通道名称可以自己起,比如我就是用vpn这三个字母做通道名称的)
* the authentication domain name ($DOMAIN),
* 验证域的名称(下面用$DOMAIN代替)(译者注:一般是没有这个东西,留空就好)
* the username you are to use ($USERNAME),
* 拨号用的用户名(下面用$USERNAME代替)
* the password you are to use ($PASSWORD),
* 拨号用的密码(下面用$PASSWORD代替)
* whether encryption is required.
* 是否要求加密

In the steps below, substitute these values manually. For example, where we write $PASSWORD we expect you to replace this with your password.
这句话的内容都在上面的注释里了,不翻译了

2. create or edit the /etc/ppp/options.pptp file, which sets options common to all tunnels:
2.创建或者编辑 /etc/ppp/options.pptp文件,这个是所有通道的共同设置

下面这个是文件的内容

lock noauth nobsdcomp nodeflate

3. create or add lines to the /etc/ppp/chap-secrets file, which holds usernames and passwords:
3. 创建或者添加下面这些行到 /etc/ppp/chap-secrets 文件,这个文件存储用户名和密码

$DOMAIN\\$USERNAME PPTP $PASSWORD * #备注:$DOMAIN可以不要

Note: if you are using a PPTP Server that does not require an authentication domain name, omit the slashes as well as the domain name.
这句是我上面的备注内容,不翻译了

Note: if the passwords contain any special characters, quote them. See man pppd for more details.
注意:如果密码中有特殊字符,用双引号引起来

4. create a /etc/ppp/peers/$TUNNEL file:
4. 创建 /etc/ppp/peers/$TUNNEL 文件内容如下

pty "pptp $SERVER --nolaunchpppd"
name $DOMAIN\\$USERNAME
remotename PPTP
require-mppe-128
file /etc/ppp/options.pptp
ipparam $TUNNEL

Note: if you do not need MPPE support, then remove the require-mppe-128 option from this file and /etc/ppp/options.pptp.
注意:如果你不需要MPPE支持,从这个文件和/etc/ppp/options.pptp删除 require-mppe-128
5. start the tunnel using the pon command:
5. 用pon命令连接VPN

pon $TUNNEL

to further diagnose a failure, add options to the command:

pon $TUNNEL debug dump logfd 2 nodetach

Note: we have further information on enabling debug mode, and on diagnosing problems.

6. stop the tunnel using the poff command:
6. 用poff命令断开连接

poff $TUNNEL

注:上面的翻译已经足够连接上VPN服务器了,下面是讲创建启动脚本的,这里就不翻译了,有空继续下面的翻译

7. to script the tunnel connection so that something is done as soon as the tunnel is up, use either ip-up.d scripts or the updetach keyword.

1. see the Routing HOWTO for examples of ip-up.d scripting that adds routes or iptables rules.

2. using updetach will cause pppd to fork, detach, and exit with success once the network link is up. This example connects a provider link, then the tunnel, then runs fetchmail to get new e-mail:

pon provider updetach && pon $TUNNEL updetach && fetchmail

Note: the double ampersand && means that the commands following it will only be executed if the command to the left of it was successful. If the tunnel fails to connect, the fetchmail will not happen.

8. to have the tunnel automatically restarted if it fails, add the option persist to either the command line or the /etc/ppp/peers/$TUNNEL file.

9. to have the tunnel started on system boot:

* for Debian Sarge and later, edit the /etc/network/interfaces file, and add this section:

auto tunnel
iface tunnel inet ppp
provider $TUNNEL

* for Debian Woody, edit the /etc/ppp/no_ppp_on_boot file, remove the first line comment, and change the word provider to the name of your tunnel, so that it looks like this:

#!/bin/sh
...
$PPPD call $TUNNEL

(The line ... means the other lines in the file, it doesn't mean a line with three dots.)

Then rename the no_ppp_on_boot file and make it executable:

# mv /etc/ppp/no_ppp_on_boot /etc/ppp/ppp_on_boot
# chmod +x /etc/ppp/ppp_on_boot

Every time your computer starts, the tunnel will be started automatically.

因为我要安装0.7.64版本,所以执行

# vim /usr/portage/www-servers/nginx/nginx-0.7.64.ebuild

因为我的 nginx-accesskey 放在 /root/nginx-accesskey 所以在 ./configure \ 下面加一句

--add-module=/root/nginx-accesskey \

# ebuild /usr/portage/www-servers/nginx/nginx-0.7.64.ebuild manifest

修改一下 /root/nginx-accesskey/config

#vim /root/nginx-accesskey/config

将 "$HTTP_ACCESSKEY_MODULE" 替换成 "ngx_http_accesskey_module"

然后执行

# vim /etc/portage/package.keywords

添加一行

=www-servers/nginx-0.7.64 ~x86

最后

# emerge =nginx-0.7.64

安装成功,配置参考
http://wiki.nginx.org/NginxChsHttpAccessKeyModule

这个月没网费了,刚好在学校机房有个能做代理上网的服务器,上网问题是解决了,可是要用SSH管理服务器咋办?
下面就来解决这个问题

$ sudo apt-get install corkscrew
$ sudo vim /etc/ssh/ssh_config

添加几行

Host 要通过代理连接的服务器地址,全部通过代理用*表示
ProxyCommand /usr/bin/corkscrew 代理服务器IP 代理端口 %h %p

现在ssh到服务器,是不是能连上了?

就在刚刚,我快崩溃了,因为Firefox下面不能输入中文了,iBus切换不出来了,原因未知,Google许久,非常艰难的,找到一个应急方法

$ sudo vim /usr/bin/firefox

在开头加入

###########
XMODIFIERS=@im=ibus
GTK_IM_MODULE=ibus
export XMODIFIERS GTK_IM_MODULE
###########

重启firefox,问题解决