转到正文

走出Windows

抛弃Windows就是走向高效率

存档

分类: 使用

一般用法是

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命令成功运行而得到正确的结果。

以我目前使用的为例子

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就可以成功了

将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.

这个月没网费了,刚好在学校机房有个能做代理上网的服务器,上网问题是解决了,可是要用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,问题解决

sudo命令就是从普通用户切换到特权用户,也就是root,其实Windows Vista和Windows 7下面的UAC就是模仿这个做出来的,我只能说M$太不要脸了,从开源软件获取了那么多,没有任何付出,还要倒打一耙,可能有人会说,微软不是给开源捐过钱么,可是你敢相信微软么?当开源做出一点贡献了,微软就要拿来卖钱了,本来应该属于全人类的开源成果,就被微软独吞了,但是就微软捐的那点钱,在开源基金会里面有多大?可能连粮仓里面的一粒麦子都不到,我实在佩服微软。
扯的太远了,回归主题,在网上找找,你能找到很多解决方法,Google第一页就很多方法,当然你按照那些方法是可以成功,但是我觉得不安全,那些方法很多都是修改/etc/sudoers权限为740再加上一句

ALL=NOPASSWD:ALL

或者加一句

yourname ALL=(ALL) NOPASSWD: ALL

然后权限改回440

先说第一种,这样做,全部的用户都有了sudo权限,而且不要密码的,安全性非常差。两种共有的缺陷是,这样做没有检测语法,如果不下心手抖一下打错了,那你就再也没有sudo的权限了,非常危险

可能很多人还不知道有visudo这个东西,这种方法非常安全,我的方法是,执行
继续阅读

一般出现这个问题基本上都是都是因为想要装ibus输入法,添加了ppa的源,例如:

GPG error: http://ppa.launchpad.net jaunty Release: The following signatures
The last 3 times I have updated, this missing key keeps coming up. Can some one direct me to the public key?
W: GPG error: http://ppa.launchpad.net jaunty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 632D16BB0C713DA6

解决方法是 执行下面两行命令

$gpg --keyserver keyserver.ubuntu.com --recv NO_PUBKEY的最后8位
$gpg --export --armor NO_PUBKEY的最后8位 | sudo apt-key add -

首先安装ntp服务器

# apt-get install ntp

然后

# vim /etc/ntp.conf

继续阅读