Jan 16, 2008

Ubuntu Tips

1. Boot Options
root=/dev/ram or root=/dev/hda
ramdisk_size=n // 内存大小,单位kb
acpi=off // disable the Advanced Configuration and Power Interface
start_pcmcia=off // disable PCMCIA

2. list all install package
$ sudo dpkg -l | more

3. see what files are included in the package
$ sudo dpkg -L package

4. to identify conflicts before removing a package
$ sudo apt-get -s remove package // -s option says to simulate without
actually donging

5. removing every Gnome package on the system
$ dpkg --get-selections '*gnome*' | awk '{print $1}' | \
xargs sudo apt-get remove

6. burn CD-ROM
$ cdrecord dev=/dev/hdc blank=fast mini.iso

7. when write to a thumb drive, run the sync command. This flushes all
cached data to the disk.
$ sudo sync

8. make FAT file system
a. install the dosfstools package if mkdosfs is not already installed
$ sudo apt-get install dosfstools
b. unmount the drive (for example, /dev/sda1) if it is currently mounted
$ sudo umount /dev/sda1
c. format the drive using either FAT16 or FAT32
$ mkdosfs -F 16 /dev/sda1
$ mkdosfs -F 32 /dev/sda1
note: if you want to creat a FAT-formatted USB floppy drive, then use
the -I option.
For example : $ sudo mkdosfs -I -F 32 /dev/sda

9. convert a large USB floppy device into a small USB floppy device
a. use dd to create a file that is as big as the drive you want to
create. For example, to create a 32MB USB drive.
$ dd if=/dev/zero of=usbfloppy.img bs=32M count=1
b. treat this file as the base device. For example, you can format it
and mount it.
$ mkfs usbfloppy.img
$ sudo mkdir /mnt/usb
$ sudo mount -o loop usbfloop.img /mnt/usb
c. when you are all done configuring the USB drive image, unmount it and
copy it to the real USB
device(for example, /dev/sda). This will make the real USB device appear
as usb floppy device.
$ sudo umount /mnt/usb
$ dd if=usbfloppy.img of=/dev/sda

10. audio convert tools: sox, lame
sox application is a great tool for converting and modifying sound files.
lame is a powerful tool for creating MP3 files.

11. Bash also enables you to edit command lines in either vi or emacs mode.
$ set -o vi # enable vi-mode
$ set -o emacs # enable emacs-mode

12. cool command
a. Ctrl+T/t transposes the last two characters at the cursor. This way,
the common typing error sl can be quickly corrected to ls.
b. The CDPATH variable tells cd where to look when the directory is not
in your current directory.

13. Running Ragged

Ubuntu includes seven different run levels: 0-6 and S. Many of the run
levels provide
very specific services. For example, level 0 is a system halt, 6 reboots
the system, and
S provides the single-user mode. Under Ubuntu, level 1 provides an
alternate single-user
mode environment.

The remaining run levels provide different types of multi-user support.
Usually the system
uses level 2. This provides a graphical user interface (when available)
and network support.
The default level 3 provides support for accessibility devices, such as
a Braille TTY display.
Finally, levels 4 and 5 usually look like level 2, however, you can
modify them if you need
customized run-time environments.

14. Configuring Boot Options
a. services-admin can identify some of the better-know services. It does
not list custom services and does not
identify different run level.
$ services-admin
b. a better tool, sysv-rc-conf
$ sudo apt-get install sysv-rc-conf
$ sudo sysv-rc-conf
note: 1. The sysv-rc-conf command shows most of the system services.
However, it does not show all of them.
If the service's name ends with .sh, contains .dpkg-, or is named rc or
rcS, then it is treated as a
non-modifiable system service. To change these services, you will need
to manually modify the
/etc/init.d/ and /etc/rc*.d/ directory contents
2. there are some essential services. You should not turn off these
services unless you really know what you are doing.

dbus - Provides messaging services.
gdm - This is the Gnome Desktop. Only disable this if you do not want a
graphical desktop.
klogd - This is the kernel log daemon. Removing it disables system logging.
makedev and udev - These create all device nodes.
module-init-tools - Loads kernel modules specified in /etc/modules.
networking and loopback - These start and stop the network. Disabling
removes the network configuration at boot.
procps.sh - Any kernel tuning parameters added to /etc/sysctl.conf are
processed by this service.
urandom - This seeds the real random number generator that is used by
most cryptographic system. You
shouldleave it enabled.

15. simple backup script
a. backup2disk-full
#!/bin/sh
# backup files to disk
# (Be sure to make this executable! chmod a+rx backup2disk-full)
for i in bin boot etc home lib opt root sbin sys usr var ; do
tar --one-file-system -cf - "/$i" 2>/dev/null | \
gzip -9 > /mnt/backup/backup-$i-full.tgz
done

b. backup2disk-inc
#!/bin/sh
# backup files to disk
# (Be sure to make this executable! chmod a+rx backup2disk-inc)
for i in bin boot etc home lib opt root sbin sys usr var ; do
tar --newer /mnt/backup/backup-$i-full.tgz \
--one-file-system -cf - "/$i" 2>/dev/null | \
gzip -9 > /mnt/backup/backup-$i-inc.tgz

c. added the full backup script to my root crontab and configured it to
run once a week
$ sudo crontab -e
Add a line to make the full backup run weekly and the incremental run
daily.
# minute hour day-of-month month day-of-week command
5 0 * * 0 /usr/local/bin/backup2disk-full
5 0 * * 1-6 /usr/local/bin/backup2disk-inc

16. install packages from a shared or local directory:
edit /etc/apt/sources.list
deb file:/mnt/iso dapper main restricted

17. install packages from CD-ROM
a. insert the CD-ROM into the drive
b. run the command
$ apt-cdrom add # the CD-ROM is automatically added to the
/etc/apt/sources.list file

or

a. let's assume that the ubuntu installation CD-ROM is mounted at the
/cdrom
$ apt-cdrom -m -d /cdrom ident
Using CD-ROM mount point /cdrom
Mounting CD-ROM
Identifying.. [d9f91a1075ce140463bf88837cc07be6-2]
Stored label: Ubuntu 6.06 _Dapper Drake_ - Release i386 (20060531)
b. After finding the CD-ROM name, you can add it to the
/etc/apt/sources.list file with a cdrom:resource. For example,
to install the main component, would use:
deb cdrom:[Ubuntu 6.06 _Dapper Drake_ - Release i386 (20060531)]/dapper
main

18. search packages:
a. $ apt-cache search calculator
b. $ apt-cache search calculator calctool

19. show the entire package's description
$ apt-cache show bison

20. list all packages that contains a file
$ dpkg -S `which perl` # list all packages that contains perl

21. /var/log/dpkg.log contains a list of every addition and removal.
This log file is update every time Synaptic, apt, or
dpkg installs or removals packages.


22. 使用中文输入法-- scim-pinyin
$ sudo apt-get install im-switch scim-pinyin
$ sudo apt-get install language-pack-zh
$ export LANG=zh_CN.UTF-8
$ sudo im-switch -s scim-pinyin -z default

23. 关闭蜂鸣
首选,音效,系统响铃,关闭讨厌的蜂鸣声

24. 字体美化
http://wiki.ubuntu.org.cn/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8XP%E5%AD%97%E4%BD%93%E8%BF%9B%E8%A1%8C%E4%B8%AD%E6%96%87%E7%BE%8E%E5%8C%96


$ sudo mkdir -p /usr/share/fonts/zh_CN/TrueType
$ sudo cp simsun.ttc tahoma.ttf tahomabd.ttf
/usr/share/fonts/zh_CN/TrueType/
$ sudo chmod 644 /usr/share/fonts/zh_CN/TrueType/*
$ cd /usr/share/fonts/zh_CN/TrueType
$ sudo mkfontscale
$ sudo mkfontdir
$ sudo fc-cache /usr/share/fonts/zh_CN/TrueType/ # 更新字体列表
$ sudo cp /etc/fonts/language-selector.conf
/etc/fonts/language-selector.conf.old

将/etc/fonts/language-selector.conf改为:
<fontconfig>
<alias>
<family>serif</family>
<prefer>
<family>Bitstream Vera Serif</family>
<family>SimSun</family>
<family>DejaVu Serif</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL ZenKai Uni</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Bitstream Vera Sans</family>
<family>SimSun</family>
<family>DejaVu Sans</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL ZenKai Uni</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Bitstream Vera Sans Mono</family>
<family>DejaVu Sans Mono</family>
<family>SimSun</family>
</prefer>
</alias>
<match target="font" >
<test name="family" compare="contains" >
<string>Song</string>
<string>Sun</string>
<string>Kai</string>
<string>Ming</string>
</test>
<test compare="more_eq" target="pattern" name="weight" >
<int>180</int>
</test>
<edit mode="assign" name="embolden" >
<bool>true</bool>
</edit>
</match>
<match target="font" >
<test name="family" compare="contains" >
<string>Song</string>
<string>Sun</string>
<string>Kai</string>
<string>Ming</string>
</test>
<edit name="globaladvance">
<bool>false</bool>
</edit>
<edit name="spacing">
<int>0</int>
</edit>
<edit name="hinting">
<bool>true</bool>
</edit>
<edit name="autohint">
<bool>false</bool>
</edit>
<edit name="antialias" mode="assign">
<bool>true</bool>
</edit>
<test name="pixelsize" compare="less_eq">
<int>18</int>
</test>
<edit name="antialias" mode="assign" >
<bool>false</bool>
</edit>
</match>
<match target="pattern">
<test name="family">
<string>SimSun</string>
<string>SimSun-18030</string>
<string>AR PL ShanHeiSun Uni</string>
<string>AR PL New Sung</string>
<string>MingLiU</string>
<string>PMingLiU</string>
</test>
<edit binding="strong" mode="prepend" name="family">
<string>Tahoma</string>
<string>Verdana</string>
</edit>
</match>
<match target="pattern">
<test name="family"><string>宋体</string></test>
<edit name="family" mode="assign"><string>SimSun</string></edit>
</match>
<match target="pattern">
<test name="family"><string>新宋体</string></test>
<edit name="family" mode="assign"><string>SimSun</string></edit>
</match>
<match target="pattern">
<test name="family"><string>仿宋_GB2312</string></test>
<edit name="family" mode="assign"><string>FangSong_GB2312</string></edit>
</match>
<match target="pattern">
<test name="family"><string>楷体_GB2312</string></test>
<edit name="family" mode="assign"><string>KaiTi_GB2312</string></edit>
</match>
<match target="pattern">
<test name="family"><string>黑体</string></test>
<edit name="family" mode="assign"><string>SimHei</string></edit>
</match>
</fontconfig>

然后,设置字体渲染为单色 系统 --> 首选项 --> 字体

25. 不让Ctrl-Alt-Backspace组合键重启X
$ sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.old
$ sudo vim /etc/X11/xorg.conf # 在文件末尾添加下面内容
Section "ServerFlags"
Option "DontZap" "yes"
EndSection

note : 重启GNOME生效

26. 解决pdf中文乱码问题
$ sudo apt-get install xpdf-chinese-simplified
如果上面的方法仍然不起作用,你需要安装poppler-data

27. 安装Ati 驱动
http://shine-woods.blogspot.com/2007/05/atifeistyaiglxberyl.html
RV280 bug
https://help.ubuntu.com/community/Radeon_9200/9250_%28RV280%29_and_DVI

28. 多媒体支持
mp3 :
a. ffmpeg package from the universe repository
b. vorbis-tools package from the restricted repository.
MPEG, AVI, QuickTime, and other video formats : mjpegtools package
MPEG4 : libxvidcore4 and faad packages
Windows Codecs : w32codecs package
DVD : libdvdcss2

29. flash支持
$ sudo apt-get install flashplugin-nonfree
$ sudo update-flashplugin

30. play video in browser
$ sudo apt-get install totem-gstreamer-firefox-plugin
or
$ sudo apt-get install totem-xine-firefox-plugin

31. 安装字体
Chinese is supported through a variety of font packages including
ttf2pt1- chinese, ttf-arphic-ukai,
ttf-arphic-uming, xfonts-cmex-big5p, xfonts-intl-chinese, and
xfonts-intl-chinese-big.

The msttcorefonts package provides the core TrueType fonts found on
Microsoft systems
安装完字体运行:
$ sudo fc-cache -f -v # scan and list the font directories, and update
the shared font information

32. 源码的形式安装软件
$ sudo apt-get install dpkg-devpackage # 以源码的形式安装软件所必需的
$ apt-get source package_name # 下载源码
$ apt-get --compile source package_name # 自动编译源码

33. integrated development environment (IDE) :
anjuta # design for c/c++ software develop.
eclipse-cdt # eclipse for c develop tool.

34. install thunderbird2
1. Download Thunderbird 2. (Save to disk)
2. sudo tar -C /opt -zxvf ~/Desktop/thunderbird-*
3. sudo ln -s /opt/thunderbird/thunderbird /usr/local/bin/thunderbird
4. create a menu item: sudo gedit
/usr/share/applications/thunderbird.desktop

[Desktop Entry]
Encoding=UTF-8
Name=Thunderbird
Comment=Thunderbird Mail Client
Exec=thunderbird
Icon=/opt/thunderbird/icons/mozicon16.xpm
StartupNotify=true
Terminal=false
Type=Application
Categories=Applications;Network

35. ssh tips
转发X
$ ssh -X user@server
转发单一的应用程序,比如firefox
$ ssh -XC user@server firefox // -C 压缩数据
转发整个桌面
$ xinit -e ssh -XCT user@server gnome-session -- :1 // 在字符界面输入该命令
注: 如果想转发X,确定机器的/etc/ssh/sshd_config 中的X11Forwarding为yes

$ ssh -fCT user@server <command> // run a single command on the open-ssh
server
-f = Allows ssh to close after the connection is established.
-C = Use Compression
-T = No terminal session will be started

36. smbclient tips
smbclient 是Samba 的Linux 客户端,在Linux机器上用来查看服务器上的共享资
源,也可以象FTP一样,用户可以登录Samba服务器,
也可以上传put和下载get文件
1) 查看服务器上的资源
$ smbclient -L //192.168.1.5 -U administrator // smbclient -L //IP [-U
username]
2) 登录Samba服务器
$ smbclient //IP/共享文件夹 -U usrename // -U 用户名表示Samba 的用户;
note : 登录到Samba服务器上,就可以用smbclient的一些指令,可以象用FTP指令
一样上传和下载文件;

37. smbtar - for remote backup/restore
backup
$ smbtar -t archive.tar -s winServer -x big // 备份主机名为winServer上的
big共享
$ smbtar -t - -s winServer -x big | gzip -9 > archive.tar.tgz // 压缩
restore
$ smbtar -r -t archive.tar -s winServer -x big // 恢复备份
$ zcat archive.tar.tgz | smbtar -r -t - -s winServer -x big
注: windows不允许SMB访问系统目录和注册表

38. smbmount - 挂载共享文件
$ sudo apt-get install smbfs
$ sudo mkdir /mnt/smb
$ sudo smbmount //winServer/big /mnt/smb
注: smbmount <=> mount -t smb
$sudo umount /mnt/smb

39. 架设samba 服务器
1) Install samba
$ sudo apt-get install samba samba-common
2) Adding Samba Shares
$ sudo mkdir -p /home/shares/all
$ sudo chmod -R a+rwxt /home/shares/all
3) Adding and managing users
$ sudo useradd administrator -m -G users
$ sudo passwd administrator
$ sudo smbpasswd -a administrator // add user to samba user database
4) edit config file —— /etc/samba/smb.conf
In the global section, remove the ";" at the front of the line security
= user so it looks like this:
security = user

At the end of the file /etc/samba/smb.conf add the following lines:
[allusers]
comment = All Users
path = /home/shares/all
valid users = @users
force group = users
create mask = 0700
directory mask = 0700
writable = yes

If all users shall be able to read and write to their home directories
via Samba, add the following lines to /etc/samba/smb.conf:
[homes]
comment = Home Directories
browseable = no
valid users = %S
writable = yes
create mask = 0700
directory mask = 0700

5) OK, now restart you Samba
$ sudo /etc/init.d/samba restart

40. 访问Windows远程桌面(remote desktop)
这些工具都可以:rdesktop, gnome-rdp(for gnome), tsclient, krdc (for kde)

41. 系统资源查看
CPU
$ cat /proc/cpuinfo // cpu 硬件信息
$ uptime // cpu负载
$ top // 每个程序占用cpu的动态详细信息
$ ps aux // 类似top,是静态的
磁盘
$ fdisk -l // 显示每个磁盘分区
$ df -h // 以human-readable的形式显示磁盘使用情况
$ mount // 各分区的挂载点
$ du -h // disk-usage, 以human-readable的形式显示文件夹所占用的磁盘空间
$ du -h | sort -rn | head // 显示占用磁盘空间最多的10个文件夹
磁盘I/O
$ sudo apt-get install sysstat
$ iostat
$ watch --interval 0.5 iostat
$ lsof / (or /dev or /dev/hda) // 查看那个进程使用设备/文件
$ fuser // identify processes using files or sockets
内存
$ swapon -s // 显示可用的swap
$ pmap // 显示分配给具体pid的内存
$ ps aux
$ top
显存
$ lspci -v
$ lspci -t
网络
$ netstat -i inet
$ netstat -t // 显示tcp连接
$ netstat -u // 显示udp连接
$ netstat --protocol=ip // 显示所有的ipv4连接
$ netstat --protocol=ip6 // 显示ipv6连接
$ watch --interval 0.5 netstat -i inet
$ ifconfig eth0
lsof 显示那个进程使用网络
$ lsof -i4 // 显示那个进程使用ipv4
$ lsof -i6 // ...ipv6
$ lsof -i4 -n // 显示那个进程使用ipv4,并且以数字的形式表示ip地址
$ lsof -i tcp // 与上面类似
$ lsof -i udp

42. 运行级
查看
$ who -r
$ runlevel
注: 所有/etc/init.d/中的脚本的启动信息都写到/var/log/messages
改变
$ telinit runlevel
注: 改变运行级之前先执行所有的K(for kill)脚本

43. 动态设备配置
udev管理动态设备配置,udev进程检测并管理即插即用(plug and play)设备
配置文件: /etc/udev/rules.d/


44. autostart program
1) boot script: locate in /etc/init.d/
2) shell startup scritp
system-wide: /etc/bash.bashrc, /etc/profile
user-specific: ~/.bash_profile, ~/.bashrc
note: execute when user logout: /etc/bash.logout, ~/.bash_logout
3) desktop script: /etc/X11/Xsession, /etc/X11/Xsession.d/, ~/.gnomerc,
~/.Xsession
System -> Preferences -> Sessions // Gnome desktop
4) device startup:udev (watches and manages plug-and-play devices).
Configuration file in /etc/udev/rules.d/
note: System -> Preferences -> Removable Drives and Media // Gnome desktop
5) network services: /etc/network/
6) schedulers: at, cron, and anacron

45. view current kernel settings and adjust them.
wiew
$ sudo sysctl -a | sort | more
two ways to adjust the kernel parameters
$ sudo sysctl -w kernel.threads-max=20000 // this change takes effect
immediately but is not permanent. After reboot changes will be lost.
$ add "kernel.threads-max=20000" to /etc/sysctl.conf // this change
takes effect on the next reboot.

46. modifying shared memory
$ ipcs -m
$ ipcs -m -p
$ ipcrm
$ sudo sysctl kernel | grep shm

47. changing per user setting
$ ulimit -a // show current setting
$ ulimit -c 100 // enable core dumps, core size is 100 blocks.
note: 1) regular user cannot change some limit.
2) some values have an upper limit define by kernel.

48. files convert
DOC files to text : antiword
PDF files to text : xpdf-utils (provides pdftotext)
graphic converion : netpbm (provides programs such as giftopnm,
jpegtopnm, pnmtopng, pnmtogif, and pnmtojpeg)

49. a useful tools - dnotify
watches a specified directory for any change. A change may be a file
creation, update, renaming, deletion,
or permission modification. When a change happens, dnotify can run a
script.

50. network services
$ netstat | most
note : two states
ESTABLISHED - a network connection exist between the two systems.
TIME_WAIT - a connection has terminated and the system is just waiting
for any final packets before
tearing down the connection.

$ netstat -l | most // show all the listening servers
$ netstat -lt // show all tcp services
$ netstat -lu // show all udp services
$ netstat -lx // show the local unix services and sockets

$ sudo apt-get install nmpa
$ sudo nmap -sS -sV -p 0-65535 -O localhost

51. fcitx 安装
$ sudo apt-get install language-pack-zh // if not install chinese
language package
$ sudo apt-get install im-switch fcitx
$ im-switch -s fcitx -z default
英文locale下fcitx输入设置
修改/etc/gtk-2.0/gtk.immodules
找到
"/usr/lib/gtk-2.0/2.10.0/immodules/im-xim.so"
"xim" "X Input Method" "gtk20" "/usr/share/locale" "ko:ja:th:zh"
改为下面这样
"/usr/lib/gtk-2.0/2.10.0/immodules/im-xim.so"
"xim" "X Input Method" "gtk20" "/usr/share/locale" "en:ko:ja:th:zh"

英文界面下输入栏与输入文字为方块,而且修改~/.fcitx/config的字体:显示字
体(中)=SimSun 仍然是小方块
改为 显示字体(中)=AR PL ShanHeiSun Uni
tips : 1. fcitx修改配置文件后,在输入法处于激活状态下,只需按Ctrl+5即可加
载新的配置文件(无须重启X或是kill後再加载)
2. 锁定输入法:fcitx输入法的面板上有把小锁的图表,点击它使之变成红色时,将
无法通过ctrl+shift切换到其他输入法,点击它使之
变灰色时则可进行输入法之间的切换,对于单一输入法用户来说可避免误按ctrl+
shift的麻烦了.
3. 去掉多余的输入法
修改~/.fcitx/config,去掉双拼和区位
[输入法]
使用拼音=1
使用双拼=0
使用区位=0
使用码表=0
提示词库中的词组=1
$ sudo mv /usr/share/fcitx/data/tables.conf
/usr/share/fcitx/data/tables.conf // 去掉其他输入法
OK,现在就只剩下拼音输入法了

No comments:

Post a Comment

您的评论将使我blog更有动力~