Ubuntu 使用杂摘

[b]Useful Shortcut Keys In Ubuntu[/b]
[b]Ctrl + super(即start键,就是xp下常说的windows键) + d: 显示桌面;[/b]
Ctrl + Alt + t: 打开一个新的terminal;
[url]http://maketecheasier.com/useful-shortcut-keys-in-ubuntu/2008/07/14[/url][quote]须谨记的 terminal 命令摘录:

ctrl + d : 退出当前terminal
ctrl + l : shortcut for clear
ctrl + c : Kill the current process.
ctrl + z : Send the current process to background.
ctrl + a : 将光标移至行首
ctrl + e : 将光标移至行尾
ctrl + u : 删除行首至光标间的字符
ctrl + k : 删除光标处至行尾的字符
ctrl + w : 删除光标前的第一个单词
Shift + Ctrl + C = copy the highlighted text to the clipboard.
Shift + Ctrl + V (or Shift + Insert) = pastes the contents of the clipboard.
Shift + Ctrl + T : 在当前 terminal 窗口中打开一个新的 terminal tab.
[/quote][b]Screen Capture:[/b]
[url]http://askubuntu.com/questions/170163/how-do-i-set-a-shortcut-to-screenshot-a-selected-area[/url]


Multiple tabs in one Terminal:
[url]http://en.wikipedia.org/wiki/Terminal_multiplexer[/url]


[color=red][b]Unity Launcher & desktop entry:[/b][/color]
Desktop Entry Specification:[b]
[url]http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html[/url]
[url]https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles[/url][/b]

# 查看当前哪些 .desktop applications 被 “Lock to Launcher”:
$ gsettings get com.canonical.Unity.Launcher favorites
gsettings 就相当于是 windows 下的注册表,参见:
[url]http://ekd123.org/blog/long-intro-to-gsettings/[/url]
那 gsettings 相关的文件到底存在哪里那?答案是存在 ~/.config/dconf/user 这个二进制文件中:
[url]http://unix.stackexchange.com/questions/8922/where-does-gsettings-store-its-files[/url]
Ubuntu 下的文件类型是通过 MIME Types 定的,位于 /etc/mime.types:
[url]https://help.ubuntu.com/community/AddingMimeTypes[/url]
How to pin Eclipse to the Unity launcher?
[url]http://askubuntu.com/questions/80013/how-to-pin-eclipse-to-the-unity-launcher[/url]
怎么实现 ubuntu 下的 File Associations?这里以将java反编译工具 jd-gui 与 .class 和 .jar 文件关联为例,说明如下:[quote]首先,为 jd-gui 新建 desktop 文件 ~/.local/share/applications/opt-jd-gui.desktop:

[Desktop Entry]
Type=Application
Name=jd-gui
Icon=/home/lee/Dev/jd-gui-0.3.5.linux.i686/jd-gui.png
Exec=/home/lee/Dev/jd-gui-0.3.5.linux.i686/jd-gui
MimeType=application/java-archive;application/java-vm;
Terminal=false
Categories=decompiler;
上面文件定义的 MimeType 并不会实现 jd-gui 和 .class、.jar 文件的自动文件关联(那写在这里有什么用?待查),还需要在 ~/.local/share/applications/mimeinfo.cache 中对它们进行文件关联:

[MIME Cache]
application/java-archive=opt-jd-gui.desktop; // 对应 .jar 文件
application/java-vm=opt-jd-gui.desktop; // 对应 .class 文件
[/quote]关于 .desktop 文件,涉及到以下一些目录和文件:

~/.local/share/applications
mimeapps.list
mimeinfo.cache
/usr/share/applications
defaults.list
mimeinfo.cache
两个目录的区别无非就是一个针对当前用户有效,另一个是全局有效;有冲突的话,当前用户的设置覆盖全局设置。
一些应用,如 Wine、Okular,被安装后会将右键菜单的 "open with" menu 搞的一团糟,在 右键菜单的 "open with" menu 中会多出好几个名字叫 Wine/Okular 的选项;针对这种问题,直接删除 /usr/share/applications(或其子文件夹,如Okular的多个desktop文件在子文件夹 kde4 下,因为它是基于kde的) 中多余的该应用的 .desktop 文件即可。
[b]关于 desktop entry 的 StartupWMClass[/b]:[quote]在使用 squirrel-sql-3.5.3 时,发现一个奇怪的问题:自动生成的 desktop entry 无法 lock 到 unity 上。解决办法:
[url]http://muzso.hu/2013/08/29/how-to-create-a-custom-unity-launcher-for-a-java-app-eg.-squirrel-sql-client#comment-1893[/url]
[url]https://bugs.launchpad.net/ubuntu/+source/unity/+bug/878113/comments/8[/url]
[url]http://elliotth.blogspot.it/2007/02/fixing-wmclass-for-your-java.html[/url]
关于 WM_CLASS:
[url]http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.2.5[/url]
[url]http://standards.freedesktop.org/startup-notification-spec/startup-notification-0.1.txt[/url]
# 通过 xprop 查看一个 window 的 WM_CLASS (http://superuser.com/questions/142318/how-can-i-view-the-wmclass-attribute-of-a-window-in-xorg-linux):
$ xprop WM_CLASS (then click on the launched window)

[/quote]


[b]disable-mouse-wheel-paste on ubuntu:[/b]

#执行下面命令,看到 mouse 的 id 为 9
$ xinput list | grep -i mouse
#查看 id 为 9 的设备的 button map,输出为 1,2,3,....16
$ xinput get-button-map 9
#禁掉 id 为 9 设备,即鼠标,滚轮被按下时的粘贴功能。建议将这句话设为系统的 Startup applications。
$ xinput set-button-map 9 1 0
disable touchpad of laptop:
# 查看 touchpad 的名字、id 等
$ xinput list | grep -i touchpad
⎜ ↳ SynPS/2 Synaptics TouchPad id=13 [slave pointer (2)]
# 禁掉该 touchpad
xinput --disable "SynPS/2 Synaptics TouchPad"



[color=red][b]Softwares:[/b][/color]
[b]一[/b] 修改ubuntu(12.04)下烦人的eclipse black background color in hover:
[url]http://gladiacxtylish.wordpress.com/2011/12/06/eclipse-tooltips-black-background-color-fix-in-ubuntu-11-10/[/url]
[url]http://www.vogella.com/blog/2012/12/04/eclipse-papercut-10-eclipse-on-ubuntu-fixing-the-black-background-color-in-hover/[/url]
[url]http://askubuntu.com/questions/70599/how-to-change-tooltip-background-color-in-unity[/url][quote]如最佳答案所言,12.04只需要修改 /usr/share/themes/Ambiance/gtk-2.0/gtkrc 文件即可。将其中的tooltip_fg_color(弹出框中的文字颜色)设为#000000(黑色),tooltip_bg_color(弹出框中的背景颜色)设为#f5f5b5(黄色)。[/quote][b]二[/b] 在使用 SQuirreL 查询数据库时,默认情况下 as 后的列别名会被忽略掉(即即使加了 columnName as columnAlias, 查询结果中看到的列名依然是 columnName),可以更改其以下配置使其正常过来:
[url]http://stackoverflow.com/questions/12709814/column-aliasing-in-select-statements-doesnt-work-with-squirrel-sql-firebird[/url]
[b]三[/b] 升级 libreoffice:
[url]http://iloveubuntu.net/libreoffice-41-released-and-available-ppa[/url]


[b][color=red]Apt dpkg etc Commands:[/color][/b]
[b]apt-get:[/b]
[url]https://help.ubuntu.com/community/AptGet/Howto[/url]

# Run this command after changing /etc/apt/sources.list or /etc/apt/preferences .
apt-get update
# upgrades all installed packages.
apt-get upgrade
# The same as the above, except add the "smart upgrade" checkbox. It tells APT to use "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary. 另外, dist-upgrade 不会升级ubuntu系统,所以请放心使用("apt-get dist-upgrade" does not perform distribution upgrade. )
apt-get dist-upgrade
# search for a particular package by name or description
$ apt-cache search keyword
# 安装 deb 包
$ sudo dpkg -i packagename.deb
# dpkg 不会安装包的依赖,如果有依赖未安装会报错;遇到这种情况可以使用 gdebi 来安装 deb 包,该安装程序会将 deb 的依赖也安装上。参见 http://askubuntu.com/questions/40011/how-to-let-dpkg-i-install-dependencies-for-me
$ sudo gdebi package.deb
[b]Using apt-cache & aptitude search packages:[/b]
[url]http://www.cyberciti.biz/faq/searching-for-packages-in-debian-ubuntu-aptitude/[/url][quote]使用 apt-cache 搜索本地安装的包
使用 aptitude 搜索 Ubuntu repository 中的包[/quote]为 Ubuntu 做 apt-get 时使用代理:
[url]http://qixinglu.com/post/ubuntu_apt-get_proxy_setup.html[/url]
[url]http://askubuntu.com/questions/35223/syntax-for-socks-proxy-in-apt-conf[/url]
$ sudo apt-get -o Acquire::http::proxy="http://127.0.0.1:8087/" update(or, upgrade)
$ sudo apt-get -o Acquire::socks::proxy="socks://127.0.0.1:8099/" update
$ autossh -M0 -o "ServerAliveInterval 60" -o "ServerAliveCountMax 6" -D 8099 -g -Nqf user@ip



[b]修改 command prompt 的字体颜色和背景色,使其更加容易与其他颜色的文字做区分:[/b]

#浅灰近白背景色、黑色字体,没有任何的ubuntu默认颜色是与这个相同的,而且很醒目
export PS1="\e[1;30m\e[47m\u@\h:\w\$ \e[m"
上面的 export 只是临时更改当前的 command prompt,想要让修改对当前用户始终起作用,可以修改 ~/.bashrc 文件:
[url]http://askubuntu.com/questions/123268/changing-colors-for-user-computer-name-and-current-directory-in-terminal[/url][quote]ubuntu下对该文件涉及到的修改包括:
1 拿掉 force_color_prompt=yes 前的注释
2 打开 color_prompt 后,ubuntu默认的颜色并不是我想要的,我想要的是上面export的浅灰近白背景色、黑色字体,所以,修改

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian${JAVA_HOME}/jre _chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
中的PS1,使其变成
PS1='${debian_chroot:+($debian${JAVA_HOME}/jre _chroot)}\[\033[01;30m\]\[\033[47m\]\u@\h:\w\[\033[00m\]\$ '
[/quote]资料:
[url]http://www.thegeekstuff.com/2008/09/bash-shell-ps1-10-examples-to-make-your-linux-prompt-like-angelina-jolie/[/url]
关于linux 下的 PS1, PS2, PS3, PS4 (PS stands for [b]Prompt Statement[/b]):
[url]http://ss64.com/bash/syntax-prompt.html[/url]
[url]http://www.thegeekstuff.com/2008/09/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command/[/url]


[b]关于环境变量 LS_COLORS:[/b]
terminal中(只)查看环境变量 LS_COLORS:
$ dircolors
添加 -p 参数后的输出:[quote]...
# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#NORMAL 00 # no color code at all
#FILE 00 # regular file: use no color at all
[b]RESET 0 # reset to "normal" color (注:对应rs)[/b]
DIR 01;34 # directory
LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
# numerical value, the color is as for the file pointed to.)
[b]MULTIHARDLINK 00 # regular file with more than one link (注:对应mh)[/b]
FIFO 40;33 # pipe
SOCK 01;35 # socket
DOOR 01;35 # door
BLK 40;33;01 # block device driver
CHR 40;33;01 # character device driver
ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file
SETUID 37;41 # file that is setuid (u+s)
SETGID 30;43 # file that is setgid (g+s)
[b]CAPABILITY 30;41 # file with capability (注:对应ca)[/b]
STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable
# This is for files with execute permission:
EXEC 01;32
# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')
# If you use DOS-style suffixes, you may want to uncomment the following:
#.cmd 01;32 # executables (bright green)
#.exe 01;32
#.com 01;32
#.btm 01;32
#.bat 01;32
# Or if you want to colorize scripts even if they do not have the
# executable bit actually set.
#.sh 01;32
#.csh 01;32
# archives or compressed (bright red)
.tar 01;31
.tgz 01;31
...[/quote][url]http://www.bigsoft.co.uk/blog/index.php/2008/04/11/configuring-ls_colors[/url][quote]The directory lister under UNIX is called ‘ls’. In the deep and distant past this was a very black and white affair. GNU has changed all that by introducing an environment variable called LS_COLORS which allows you to set the colours of files [b]based on extension, permissions and file type.[/b][/quote][url]http://blog.twistedcode.org/2008/04/lscolors-explained.html[/url]
[url]http://ubuntuforums.org/showthread.php?t=1410897[/url][quote]一 用各自的颜色标示LS_COLORS中各个量的脚本:

#!/bin/bash

a=' '
for c in `echo $LS_COLORS | sed 's/[=:]/ /g'`; do
if [[ "$c" =~ ^([0-9]*;?[0-9]+)$ ]]; then
echo -en "\033[${c}m${a}\033[0m "
else
a=$c
fi
done

# for new line
echo
输出:
[img]http://dl.iteye.com/upload/attachment/0080/3507/dfd22b13-69d9-339d-a3b2-457b6cffdaf7.png[/img]
二 用各自的颜色标示dircolors命令中各个量的脚本:

#!/bin/bash

a=' '
for c in `dircolors -p | cut -d'#' -f1 | grep -v '^ *$'`; do
if [[ "$c" =~ ^([0-9]*;?[0-9]+)$ ]]; then
echo -en "\033[${c}m${a}\033[0m "
else
a=$c
fi
done

echo -e "\b"
输出:
[img]http://dl.iteye.com/upload/attachment/0080/3509/5d4d6cc3-339a-367a-827b-d71fc8efbf79.png[/img][/quote][url]http://askubuntu.com/questions/17299/color-meanings-in-terminal[/url][quote]另外一个(相比前两个不算完全)的ls_colors显示脚本:

#!/bin/bash

eval $(echo "no:global default;fi:normal file;di:directory;ln:symbolic link;pi:named pipe;so:socket;do:door;bd:block device;cd:character device;or:orphan symlink;mi:missing file;su:set uid;sg:set gid;tw:sticky other writable;ow:other writable;st:sticky;ex:executable;"|sed -e 's/:/="/g; s/\;/"\n/g')
{
IFS=:
for i in $LS_COLORS
do
echo -e "\e[${i#*=}m$( x=${i%=*}; [ "${!x}" ] && echo "${!x}" || echo "$x" )\e[m"
done
}
[/quote]


[b]Ubuntu 下定制合适的屏幕显示分辨率:[/b]
使用 xrandr 查看显示设备的名字:

$ xrandr
Screen 0: minimum 320 x 200, current 1600 x 900, maximum 8192 x 8192
VGA1 connected 1600x900+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
这里的 VGA1 即为显示设备的名字,下记为 <DEVICE_NAME>.
使用 cvt 查看指定分辨率对应的 Modeline(这里以16:9显示器比较常用的1600x900,刷新率 60 为例):
$ cvt 1600 900 60
# 1600x900 59.95 Hz (CVT 1.44M9) hsync: 55.99 kHz; pclk: 118.25 MHz
Modeline "1600x900_60.00" 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync
输出里 “Modeline” 这个单词后的东西即为对应的 Modeline, 其中"1600x900_60.00" 为 Modeline 的名字,后面的一堆乱八糟数字为其对应的显示参数。
为显示设备添加该新的 modeline 并使用:

xrandr --newmode "1600x900_60.00" 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync
xrandr --addmode <DEVICE_NAME> "1600x900_60.00"
这样就使用上了这个新的分辨率。但是这样设置在系统重启后就失效了。为了永远有效,可将上面添加并使用新modeline的代码写到 display manager 对应的启动脚本里去。查看当前使用的是哪个 display manager:

$ cat /etc/X11/default-display-manager
本人用的是 lightdm,lightdm对应的设置如下:
新建一个名为 lightdmxrandr.sh 的文件将其放入 /usr/local/bin 下,内容如下:

#!/bin/bash
xrandr --newmode "1600x900_60.00" 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync
xrandr --addmode VGA1 "1600x900_60.00"
xrandr --output VGA1 --mode "1600x900_60.00"
记得更改此文件的权限为可执行:

chmod +x lightdmxrandr.sh
修改 lightdm 的配置文件 /etc/lightdm/lightdm.conf,在文件最后添加下面一行:

display-setup-script=/usr/local/bin/lightdmxrandr.sh
Over.


[b]Problems or Bugs:[/b]
1. 14.04 下,如果拔掉笔记本的电源,则会出现鼠标丢失焦点的情况。解决办法是将 /etc/laptop-mode/conf.d/usb-autosuspend.conf 中 CONTROL_USB_AUTOSUSPEND 的值由 "auto" 该为空串 "",从而禁用 USB autosuspend feature,参见:
[url]http://askubuntu.com/a/318181/119407[/url]


UsingTheTerminal
[url]https://help.ubuntu.com/community/UsingTheTerminal[/url]


ubuntu速度慢的原因之内存和swap分区
[url]http://www.opensoce.com/2010/08/Ubuntu-Su-Du-Man-De-Yuan-Yin-Zhi-Nei-Cun-He-Swap-Fen-Qu/[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值