Heroes in my heart

Just another WordPress.com weblog

vi basic manual

http://tech.ddvip.com/2006-08/11554028207553.html

June 20, 2008 Posted by Delta | programming | | No Comments Yet

Mac Terminal basic

full text at: http://bbs.pcbeta.com/viewthread.php?tid=218540

Some useful tips:

基本命令
列出文件
ls 参数 目录名
例: 想看看跟目录下有什么,
ls /
想看看驱动目录下有什么,
ls /System/Library/Extensions
参数 -w 显示中文,-l 详细信息, -a 包括隐藏文件
转换目录
cd
例:想到驱动目录下溜达一圈
cd /System/Library/Extensions

建立新目录
mkdir 目录名
例:在驱动目录下建一个备份目录 backup
mkdir /System/Library/Extensions/backup
在桌面上建一个备份目录 backup
mkdir /User/用户名/Desktop/backup

拷贝文件
cp 参数 源文件 目标文件
例:想把桌面的Natit.kext 拷贝到驱动目录中
cp -R /User/用户名/Desktop/Natit.kext /System/Library/Extensions
参数R表示对目录进行递归操作,kext在图形界面下看起来是个文件,实际上是个文件夹。
把驱动目录下的所有文件备份到桌面backup
cp -R /System/Library/Extensions/* /User/用户名/Desktop/backup

删除文件
rm 参数 文件
例:想删除驱动的缓存
rm -rf /System/Library/Extensions.kextcache
rm -rf /System/Library/Extensions.mkext
参数-rf 表示递归和强制,千万要小心使用,如果执行了 rm -rf / 你的系统就全没了

移动文件
mv 文件
例:想把AppleHDA.Kext 移到桌面
mv /System/Library/Extensions/AppleHDA.kext /User/用户名/Desktop
想把AppleHDA.Kext 移到备份目录中
mv /System/Library/Extensions/AppleHDA.kext /System/Library/Extensions/backup

更改文件权限
chmod 参数 权限 文件
例:把驱动目录下所有文件设定到root读写,其他用户只读
chmod -R 755 /System/Library/Extensions
参数R 表示递归,755表示各用户的权限

更改文件属主
chown 参数 用户:组 文件
例:把驱动目录下的所有文件属主改成根用户
chown -R root:wheel /System/Library/Extensions
参数R 表示递归操作

修复整个系统中文件的权限
diskutil repairpermissions /
严格的说这不是一个unix 命令,而是osx一个软件,记得修改或添加的驱动就执行一次。

文本编辑
nano 文件名
例:编辑natit Info.plist
nano /System/Library/Extensions/Natit.kext/Info.plist
编辑完成后 用 Ctrl +O 存盘,Ctrl+X 退出
另一个文本编辑软件是 vi,操作有些古怪,熟了是非常好用的,而且在所有类Unix系统中都它,走遍天下都不怕了。

运行脚本命令
sh 脚本文件名
例 修改驱动后所有需要的操作存成一个脚本,以后修改了驱动后只要运行一次这个脚本就可以了,方便吧
1. 终端中运行nano /clean
2. 把下列代码粘贴到 nano 中
rm -rf /System/Library/Extensions.kextcache
rm -rf /System/Library/Extensions.mkext
chown -R root:wheel /System/Library/Extensions
chmod -R 755 /System/Library/Extensions
diskutil repairpermissions /
kextcache -k /System/Library/Extensions/
3. Ctrl +O 存盘,Ctrl+X 退出
4. 以后只要动了驱动,就在终端中运行一次 sh /clean

————————————————————————————————————
小技巧

用 Tab 键自动补齐命令
比如想到 /System 目录中去,输入 cd /Sy 然后按一下Tab 键,命令就会自动补齐成 cd /System

操作带名字中带有空格的文件和目录
空格在命令中写成 空格, 比如要进入 My Documents,命令为 cd My Documents

查看命令的详细帮助
man 命令名
比如要看看 ls 命令的详细用法,执行 man ls

————————————————————————————————————
典型操作流程
(假设已经制作好清理脚本,记得每次操作前 sudo -s 获得系统权限)

假设下载了一个显卡驱动 Natit.zip,在桌面解压得到了一个Natit.kext,该怎么做呢?

为了保险起见,先把所有驱动备份了再说
mkdir /User/用户名/Desktop/backup 在桌面上建立备份文件夹
cp -R /System/Library/Extensions/* /User/用户名/Desktop/backup 备份驱动文件

现在可以安心安装了
cp -R /User/用户名/Desktop/Natit.kext /System/Library/Extensions 把它 拷贝到系统驱动目录位置
sh /clean 执行清理脚本,操作完成

重新开机失败,进不去桌面了,发现不应该安这个驱动,怎么恢复呢?
开机按F8,用 -s 参数启动
执行 mount -uw /
rm -rf /User/用户名/Desktop/Natit.kext 删除这个驱动
sh /clean 执行清理脚本,操作完成

重启,回到原先状态了,不死心啊,没有特效怎么行呢,又听说需要修改 Natit的 Info. plist 文件才行,好,再来
cp -R /User/用户名/Desktop/Natit.kext /System/Library/Extensions 把它 拷贝到系统驱动目录位置
nano /System/Library/Extensions/Natit.kext/Info.plist
编辑完成后 用 Ctrl +O 存盘,Ctrl+X 退出
sh /clean 执行清理脚本,操作完成

重启,这回对了,显卡特效都有了,该弄声卡了,天知道会出什么事,得把现有成果保护好。
mkdir /User/用户名/Desktop/gooddrivers 专为有效驱动建个目录
cp -R /System/Library/Extensions/Natit.kext /User/用户名/Desktop/gooddrivers 备份

这个声卡要求把 AppleHDA.kext 删除和编辑 AppleAzaliaAudio.kext中的Info.plist 文件,谁知道以后会不会还用AppleHDA呢,不如暂时禁用吧。
mkdir /System/Library/Extensions/disabled 建立个禁用目录
mv /System/Library/Extensions/AppleHDA.kext /System/Library/Extensions/disabled 移动过去
nano /System/Library/Extensions/Natit.kext/AppleAzaliaAudio.kext/Info.plist
编辑完成后 用 Ctrl +O 存盘,Ctrl+X 退出
sh /clean 执行清理脚本,操作完成
成功了,也把修改好的驱动备份一下把

June 20, 2008 Posted by Delta | Mac OS X | , | 1 Comment

Root, Lakers, wings

I’ve been installing root for two days and made many mistakes. At first I tried installing both from source and binary. Of course I failed. Then I thought maybe it will be better with the upgraded system. Thus I upgraded my OS. And the the first mistake came out.

The space for upgrading is about 11G and I still have 14G free. But after upgrading, I couldn’t get my system restarted. But my spare space became 3G. I asked customer service about this. A girl said it may need more space than that. When restarting the system, it may make other configurations and delete all the unnecessary files. That’s probably why I couldn’t get it restarted.

But I didn’t backup my files which was a very serious mistake. Any one with common sense wouldn’t do that. I never installed any OS and I took it for granted that upgrading should be very safe…

Luckily, I found a way out. I cleared up a removable hard disc, and connected to my Mac. Forced Mac to start using the upgrade disc (hold on c while starting until the startup interface shows up). Format the removable disc to the same format with the Hard disc. Then restore the disc image from my Mac hard disc to the removable. You can choose erase destination while doing that. Then all my stuff were safe.

I reinstall Mac OS X 10.4 again. There was something interesting happened. I forgot to bring my second disc while reinstalling. Then I inserted the upgrade disc, and forced Mac to restarted again from the disc. And then I can upgrade my system to 10.5 and it worked. But I didn’t feel confident on doing so. Thus I did it allover again with both of the discs.

After installation, I insert Disk1->customize installation -> Choose to install X11. It is strange that, X11 won’t work if I just download the package and install it myself. I installed the Xcode come with my Mac, but I still couldn’t start root. I downloaded another Xcode, install it again with gcc4.0. I couldn’t remember if I installed any other packages in Xcode.

After all these, I can get root running, but I can’t get the convas out. :’(

Accidentally, it turned out that I should always run X11 first and then start the terminal run root. I don’t know why. But anyway, it worked, FINALLY!

————————–

We went to the Wings for dinner yesterday and watched the first half NBA (Lakers vs. Celtics). It was fun. I haven’t seen much basketball since my high school while Micheal Jordan was the best at that time. I’m happy that Lakers won the game but I didn’t see much differences between the two teams. If Lakers couldn’t shoot better, it will be very hard for them to get to the champion.

June 11, 2008 Posted by Delta | Mac OS X, root | | No Comments Yet