Skip to content

Instantly share code, notes, and snippets.

@d0zingcat
Last active December 18, 2017 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d0zingcat/850b585af1dde9159e244d7473b2e78b to your computer and use it in GitHub Desktop.
Save d0zingcat/850b585af1dde9159e244d7473b2e78b to your computer and use it in GitHub Desktop.
linux notes

Without other narrates, this note is only intended for Debian or Ubuntu.

command function usage
update-alternatives multi-version runnable program preference management
test -x ${file} test if ${file} exists and granted with executable permission
if [ -f ${file} ] test if this file is a regular file
set -e cause the shell to exit if any subcommand or pipeline returns a non-zero status

Vim

  1. Column editing mode

    • Ctrl+v enter Block Visual Mode
    • Shift+i to insert
    • enter some chars
    • double press Esc to make it take effect
  2. disable auto visual mode

    when using vim, selecting some text with the mouse automatically enter visual mode. I rarely use the visual feature and when I use it I prefer using the v keyboard command. There must be a way to disable this "stupid" setting.

    • issue the command :set mouse-=a
    • insert the directive set mouse-=a into your ~/.vimrc file
  3. set line numbers

    : set number

Bash

  • Definition of function
function function_name {
}

or

function_name () {
}
  • $$|$?|$@|$#
    • $? contains the return status of the previously run command or function.
    • $# number of parameters

Desktop

- [Add items to Xfce Applications Menu](http://xubuntugeek.blogspot.com/2011/12/add-items-to-xfce-applications-menu.html)

Reference:

update-alternatives

实例:

  1. display参数列出一个命令的所有可选命令
# update-alternatives --display java
  1. config参数用于给某个命令选择一个link值,相当于在可用值之中进行切换吧。
# update-alternatives --config java  //有 3 个候选项可用于替换 java (提供 /usr/bin/java)  
 选择       路径                                       优先级  状态  
------------------------------------------------------------  
  0            /usr/lib/jvm/java-6-openjdk/jre/bin/java      1061      自动模式  
* 1            /home/wuekzhu/download/jdk1.6.0_23/bin/java   1         手动模式  
  2            /usr/lib/jvm/java-6-openjdk/jre/bin/java      1061      手动模式  
  1. install参数用于添加一个命令的link值,相当于添加一个可用值,其中slave非常有用。
# update-alternatives –-install /usr/bin/java java /usr/local/jre1.6.0_20/bin/javac 100  
# update-alternatives –-install /usr/bin/java java /usr/local/jre1.6.0_20/bin/javac 100 –slave /usr/bin/javac javac /usr/local/jre1.6.0_20/bin/javac  
  1. remove参数用于删除一个命令的link值,其附带的slave也将一起删除。
# update-alternatives –remove java /usr/local/jre1.6.0_20/bin/java  

update-alternative有两种模式:auto和manual,默认都为auto模式,因为大多数情况下update-alternatives命令都被postinst (configure) or prerm (install)调用的,如果将其更改成手动的话安装脚本将不会更新它了。

若是想将manual改回自动模式的话,执行命令: update-alternatives --auto name即可,如 update-alternatives --config java

set-e

Be careful of using set -e in init.d scripts. Writing correct init.d scripts requires accepting various error exit statuses when daemons are already running or already stopped without aborting the init.d script, and common init.d function libraries are not safe to call with set -e in effect. For init.d scripts, it's often easier to not use set -e and instead check the result of each command separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment