获得Shell脚本所在目录的绝对路径

0

要得到正在执行的程序/脚本自身所存放的绝对路径,在 PHP 里面可以用 dirname(realpath(__FILE__)) ; C# 则有 System.Windows.Forms.Application.StartupPath ; java 似乎没有什么比较直接的方法,只能利用 CodeSource 来间接获取 。而在 linux shell 脚本里面如果想得到当前脚本文件存放的绝对路径,也没有太现成的命令可以调用,不过可以通过下面的语句来获取:

baseDirForScriptSelf=$(cd “$(dirname “$0″)”; pwd)
echo “full path to currently executed script is : ${baseDirForScriptSelf}”

虽说大部分情况下我们并不需要这样的绝对路径来完成工作;但如果要把多个脚本、数据文件等内容打包作为一个整体来交付别人使用,又希望不论用户拷贝到哪个目录下执行脚本都能够正确的找到这个包里面的其他内容的话,用这样的脚本来自动定位包的根目录应该是个比较鲁棒的做法。

如何恢复Firefox内建的关闭窗口提示时是否保存标签页的功能?

如何恢复Firefox内建的关闭窗口提示时是否保存标签页的功能?

0

原来关闭火狐时会弹出一个
“您想允许Firefox保存您的标签页并在下次启动时打开它们吗?”的窗口
但在一次关闭时不小心选了“不再询问”,从此它就再也不出来了!!该怎么恢复呢?

解决方法:
在地址栏中输入:
about:config
进入设置,搜索并修改
browser.startup.page=1
即可。

make -j 的并行任务个数选择

0

在多CPU上编译Linux内核时可以用 make -jn 多个任务并行编译加快速度。印象中在某个文档看到过 n 选择为 ncpu + 1,但不清楚理论依据何在。查了一下也没看到这个说法的原始来源,因此在一个四核的CPU上做了一下简单的测试,结论是在 n 等于 CPU 个数时的速度最快。下面是结果数据:

n system user real
1 52.477 662.534 693.391
2 48.227 606.096 318.699
3 40.066 500.220 184.886
4 38.619 474.832 140.242
5 38.360 479.650 141.821
6 37.721 480.068 141.241
7 38.188 481.979 141.872
8 38.685 483.338 142.171
用到的脚本如下(为降低其他因素的干扰,所有的文件及编译过程都放在内存之中进行):
#!/bin/sh
tar -C /dev/shm -xjf linux-2.6.34.tar.bz2 

mount -o remount,exec /dev/shm

pushd /dev/shm/linux-2.6.34

for i in `seq 1 8`; do
[ -d ../${i} ] && rm -fr ../${i}/* || mkdir ../${i}
cp /boot/config ../${i}/.config
time make O=../${i} -j ${i} oldconfig > /dev/null
time make O=../${i} -j ${i} > /dev/null
rm -fr ../${i}
done

popd

mount -o remount,noexec /dev/shm

CentOS yum 更新 网易源(mirrors.163.com)

0

如果你安装了CentOS系统,并且yum更新慢的话,可以考虑将更新源更换为 网易提供的源:mirrors.163.com

具体操作如下:

cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak

vi CentOS-Base.repo

加入如下内容:

CentOS-Base.repo
# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.    You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever – Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#released updates
[updates]
name=CentOS-$releasever – Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever – Addons
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

让firefox下载不进行病毒扫描

0
每次用Firefox下载完图片或者其他文件的时,总是自作聪明自动扫描病毒,很浪费资源和时间.
去除方法:
   在地址栏输入about:config,找到Browser.download.manager.scanWhenDone,双击设置为false

Firefox 4 将橙色按钮的文本替换掉

0

userChrome.css

如下:
#appmenu-button .button-box .box-inherit:before {
content: “Firefox“;
}
#appmenu-button .button-box .box-inherit .button-text {
display: none;
}

可以直接使用汉字(在stylish中可行),或者在Unicode编码的前面加上反斜杠(\)
如下:
#appmenu-button .button-box .box-inherit:before {
content: “\706b\72d0“; /* 火狐 的对应编码 */
}
#appmenu-button .button-box .box-inherit .button-text {
display: none;
}

去掉firefox sync状态栏图标

0

在userChrome.css里添加:

#sync-status-button, #sync-notifications-button {display: none !important;}

或者使用organize status bar扩展

安装mysql,在./configure时出现错误:error: No curses/termcap library found的解决办法

0

在./configure后,make时出现以下错误:
make: *** No targets specified and no makefile found. stop.

在网上找到相关资料,确认是./configure出了问题,于是回头查看,果然发现问题:
最后几行出了错,完整错误信息如下:
checking for tgetent in -lncurses… no
checking for tgetent in -lcurses… no
checking for tgetent in -ltermcap… no
checking for tgetent in -ltinfo… no
checking for termcap functions library… configure: error: No curses/termcap library found

原因:
缺少ncurses安装包

解决办法:
下载安装相应软件包
一、如果你的系统是RedHat系列:
yum list|grep ncurses
yum -y install ncurses-devel
yum install ncurses-devel

二、如果你的系统是Ubuntu或Debian:
apt-cache search ncurses
apt-get install libncurses5-dev

待安装completed!之后,再./configure,顺利通过,然后make && make install,成功安装,一切OK!~~~

禁用火狐浏览器的plugin-container.exe[zt]

0

firefox版本3.6.6,我最近发现多了个plugin-container.exe,手动结束这个进程后,firefox的flash插件立马崩溃。这个进程的作用描述如下:
使某些plugin崩溃了也不影响firefox,不用重启fx,刷新下即可恢复正常。然而本功能比较占内存,不喜欢的可以禁用。

禁用方法:
输入about:config,会有一个“失去质保”的提示,确认继续。,(fileter:)plugins,以下是默认值,全部修改为false。
dom.ipc.plugins.enabled
dom.ipc.plugins.enabled.npctrl.dll
dom.ipc.plugins.enabled.npqtplugin.dll
dom.ipc.plugins.enabled.npswf32.dll
dom.ipc.plugins.enabled.nptest.dll

对于IFS的一点总结

0

(1)什么是IFS ?
IFS是bash的内部变量,称为内部域分隔符.这个变量用来决定Bash在解释字符串时如何识别域,或者单词边界.

(2)如何查看当前的IFS值?
[root@Dong tmp]# echo "$IFS"

由于IFS默认为空白(空格,tab和新行),所以使用以上的命令似乎看不到字符。没关系,你可以用od命令看16进制,或是2进制值:
[root@Dong tmp]# echo "$IFS" | od -t x1
0000000 20 09 0a 0a
0000004

注意:$*使用$IFS 中的第一个字符,比如:
[root@Dong tmp]# set w x y z;echo "$*"
w x y z

(3)如何修改IFS值?
普通的赋值命令即可:
[root@Dong tmp]# IFS=":"
[root@Dong tmp]# echo "$IFS"
:
[root@Dong tmp]# echo "$IFS" | od -t x1
0000000 3a 0a
0000002
[root@Dong tmp]# set w x y z;echo "$*"
w:x:y:z

(4)实验:$*使用$IFS 中的第一个字符
[root@Dong tmp]# IFS="\\:;"
[root@Dong tmp]# echo "$IFS"
\:;
[root@Dong tmp]# echo "$IFS" | od -t x1
0000000 5c 3a 3b 0a
0000004
[root@Dong tmp]# set w x y z;echo "$*"
w\x\y\z
[root@Dong tmp]# IFS=":;\\"
[root@Dong tmp]# echo "$IFS"
:;\
[root@Dong tmp]# echo "$IFS" | od -t x1
0000000 3a 3b 5c 0a
0000004
[root@Dong tmp]# set w x y z;echo "$*"
w:x:y:z

(5)备份IFS
[root@Dong tmp]# echo "$IFS" | od -t x1
0000000 20 09 0a 0a
0000004
[root@Dong tmp]# OLDIFS="$IFS"
[root@Dong tmp]# echo "$OLDIFS" | od -t x1
0000000 20 09 0a 0a
0000004
[root@Dong tmp]# IFS=":"
[root@Dong tmp]# echo "$IFS" | od -t x1
0000000 3a 0a
0000002
[root@Dong tmp]# IFS="$OLDIFS"
[root@Dong tmp]# echo "$IFS" | od -t x1
0000000 20 09 0a 0a
0000004

Go to Top