Linux下ISO处理

其实本贴是给各种小白准备的。

还记得Windows下DT的ISO支持吗?还在DT地找UltraISO for Linux版吗?你out了!(准确说你太超前了)在多少年前,UNIX就有了牛B的dd和mount(包括umount),它们就可以操作ISO了(这里不包括刻录,刻录请移步cdrecord和dvdrecord)

从光盘搞到映像文件

还在从光盘获取映像文件上不知所措?用dd吧!比如你用dvd,就直接这样

dd if=/dev/dvd of=[输出文件名]

cd就把dvd替换成cd,是不是很简单?

挂载映像文件

这也太简单了,在mnt下创建一个目录,然后直接:

sudo mount [映像文件名] [刚才创建的空目录地址]

that's all.

如果只读,会有提示。

卸载

umount 刚才创建的空目录地址

其他

除第一个操作外,其他全部需要root权限。

这些东西其实都有GUI版,但是命令行还是快一点。(除非GUI智能了)

只让Emacs以守护进程模式运行

这里又写到废话了,如果你想直接要一个可以运行的办法,请直接跳转到III的第二个脚本。

I. Why?

众所周知,Emacs如此庞然大物,在不进行任何配置的情况下,启动速度还说得过去,要是.emacs里面有上几千几百行的,那这个速度就……

II. What?

咳咳,不说伤心往事了,其实Emacs最近的版本提供了“守护进程”(什么?你居然不知道守护进程?你用的是Windows吧?),也就是让它在后台运行,如果再次运行,找到了守护进程的话,就可以立刻进入运行状态。

III. How?

要启动Emacs的守护进程,就用 emacs --daemon。

要用这个daemon运行,就执行 emacsclient -a "" -c。

这里,-c指GUI模式,-t指终端模式,指定-nw后会覆盖-c语义。如果它没找到守护进程,就会调用 emacs --daemon ,然后重试。

但是每次运行都得入终端或者用“运行”,太麻烦了,点菜单的话进入的还是 emacs ,就把daemon忽略了……

好吧,我去alias一下,可是发现只在终端下有用,555,没办法了么,不过嘛,办法还是有的,当然不是改启动器,很简单,就是在/usr/bin下写一个emacs同名脚本,执行emacsclient,这招我常用,也很实用。

(注意,这里的操作全部需要root权限。另外,所建立的emacs脚本必须用chmod +x emacs赋予执行权限)

首先,进/usr/bin,把emacs重命名成run-emacs(mv emacs run-emacs,当然也可以随你所愿,比如emacsserver啥的,我用的是emacs-23)。然后建立一个脚本,写入如下内容。

#!/bin/sh
emacsclient -a '' "$@" -c

然后,试试从菜单启动,哇,瞬时启动诶!!

不过当你心情很好地重启后,却发现不能启动了……哦,想想前面提到的,emacsclient是用emacs --daemon启动守护进程的!这样,emacs已经被我们重写了,指向的是emacsclient,但是emacsclient没有--daemon参数,所以,怎么办?很简单,建立一个if判断。

#!/bin/sh
if [[ "$1" = "--daemon" ]] #可以处理$1为空的现象
then
    run-emacs --daemon
else
    emacsclient -a '' "$@" -c
fi

哈哈,这下就完美了,如果没有启动,也可以自动切到run-emacs上。

IV. Notes

但是我们要说的是,Emacs的守护进程相当笨,它居然不会自动检查.emacs或其他配置有没有修改(其实这也很简单,对吧?),但是当我们折腾Emacs时,总是会改写.emacs,然后需要重启emacs看效果,怎么办?这也没办法,只能先pkill掉run-emacs,然后再运行emacs。

这次没好好写,大家谅解。

Over~

Emacs MEW GMAIL IMAP设置

终于比较完整了,贡献给大家参考学习

(大量参考了某日文网站和Emacser的相关文章)

5-1 第一次发布,含有帐号设置

5-2 增加回复、签名档、密码缓存和GPG签名验证设置

;;;;; 该部代码节选自 Ekd123 的 .emacs 文件,略有改动 ;;;;;;;;;

;;;;; 其中注释内容用 <M-;> 取消注释 ;;;;;;;;

;;Mew
;--------------------
;回复
(setq mew-summary-reply-with-citation-position 'body)
(setq mew-cite-fields '("Date:" "From:"))
(setq mew-cite-format "\n\nOn %s %s wrote:\n")
(add-hook 'mew-before-cite-hook 'mew-header-goto-body)
(add-hook 'mew-draft-mode-newdraft-hook 'mew-draft-insert-signature)
;签名档 请确认你写好了签名文件,不自动加分隔符
;; (setq mew-signature-file "~/Mail/signature")
;; (setq mew-signature-as-lastpart t)
;; (setq mew-signature-insert-last t)
;Spam
(setq mew-summary-form-mark-spam t)
;帐号设置
(setq mew-proto "%")
(setq mew-user "whoami")
(setq mew-name "Who AmI")
(setq mew-mail-domain "gmail.com")
(setq mew-imap-server "imap.gmail.com")
(setq mew-imap-user "whoami@gmail.com")
(setq mew-imap-auth t)
(setq mew-imap-ssl t)
(setq mew-imap-ssl-port "993")
(setq mew-smtp-auth t)
(setq mew-smtp-ssl t)
(setq mew-smtp-ssl-port "465")
(setq mew-smtp-user "whoami@gmail.com")
(setq mew-smtp-server "smtp.gmail.com")
(setq mew-ssl-verify-level 0) ;;没有会导致验证失败
;密码缓存
(setq mew-use-cached-passwd t)
;GPG签名设置(非加密) 首先确认你有没有GPG ID。
;; (setq mew-pgp-ascii-suffix "84599A3C")
;; (setq mew-protect-privacy-always t)
;; (setq mew-protect-privacy-always-type 'pgp-signature)

Openbox 体验记

话外一下,建议用Cairo-dock替代Docky,我觉得Cairo-dock更好。

一些有用的链接见文末。

本文为了使行文生动加了好多废话,如果你是实务派,可以忽略所有有括号的文字。

零。由来

我觉得GNOME 2默认的metacity实在不怎么样,又慢又占资源,偶然在LinuxTOY上看到了Openbox的介绍PDF),感觉非常适合我等不喜欢配置的懒人(所以fvwm直接被排除),于是在安装了openbox。

作为使用X的用户,怎么能天天在dock上点终端用yum安装呢,岂不把自带的“添加/删除软件”给冷落了……

该玩意经本人测试在Fedora官方源里有。

据说在Debian/Ubuntu里面也有。

一。初识

好了,安装完成了,我们临时启动看看效果吧。

Alt+F2打开“运行”窗口,输入 openbox --replace ,回车,看看效果吧!

(最棒的是,还有一些动态效果!更多内容见链接[4])

嗯,速度貌似快了不少呢……

关于透明窗口请看《三》。

二。启动?自动的!!

嗯,安装完了,好吧,我们注销看看效果。

注:据我所知,在Fedora中的注销也会杀掉X,所以会重启X。

呃,不对,这个界面怎么看着这么面熟?好像和openbox不一样?我想想……哦!这是Gnome默认的metacity!怎么办?凉拌!只好去再次运行 openbox --replace 了……

但是每次启动运行openbox --replace 很麻烦,在.bash_profile里面写上exec openbox也不行,突然想起来改GConf就行了。

具体方法:

  1. 应用程序 > 系统工具 > 配置编辑器 (这是官方文档的习惯)
  2. 依次进入 </desktop/gnome/session/required_components/>
  3. 找到windowmanager,双击之
  4. 在“值”里输入“openbox”(不含引号)
  5. 点击确定,关闭配置编辑器

三。Dock等透明窗口怎么办?

好吧,恕我现在才讨论这个问题。

你可能早在《二》就已经发现Dock等透明窗口的背景是黑色的,而compiz漂亮的阴影效果也消失不见,这让我们既爱美又爱快的纠结用户们纠结不已——怎么办呢?(孟子曾经曰过:“鱼与熊掌不可兼得也”……啊,谁扔的西红柿!我不喜欢吃啊!)

透明问题在官方常见问答文件中简单地作了回答,大概意思是尚不支持(以后也许会是),需要借助别的东西。(“到底是个啥你快说啊!”“呃,别急,下面就说到。”)

所以我们需要借助X的东西了——xcompmgr!这个东东是X自己的,所以……它是用命令行控制的……

该包一般在源里都有。

要体验它,和openbox一样用“运行”就成。

在openbox的常见问答中,推荐命令行是这个:

xcompmgr -c -t-5 -l-5 -r4.2 -o.55

好吧,你可能会有与刚刚用openbox相同的疑惑——怎么一重启X这玩意就挂了呢?你也许会去GConf中找,很不幸,GConf中还真没有这玩意……但是作为伟大的Linux用户,怎么可能找不到这个东东呢?“启动应用程序”就是配置自启动程序的集中地。

具体方法:

  1. 系统 > 首选项 > 启动应用程序
  2. 点击 “添加 (A)”
  3. 名称可以填“让Openbox支持透明窗口”,命令就写上面的,点保存。
  4. 关闭。
  5. 之后就能看到效果了。

嗯,如果你有其他要自动启动的程序也可以用这种办法。

在我这里的问题:有时阴影重绘不到位,但我知道这只是xcompmgr的问题。

四。难道要我手动写配置不成?

“我用暗色调的GNOME主题,openbox的默认天蓝格格不入,能不能干掉它啊?”

当然啰!去改配置吧!

配置在哪里?嗯,这是个很严重的问题,我才想到那个东西是个XML文本配置文件,难道要让我们可怜的大脑记忆这么多无关紧要的东西,抑或是改一个主题都要查一个小时的手册?不行!绝对不行!

怎么办?当然咯,已经有人做了这个东西了——obconf!

安装它,就能在“系统 > 首选项 > Openbox Configuration Manager(Openbox 配置管理器)”找到了,唯一的缺点就是它还没有中文翻译,所以,凑合着用Google 翻译吧。

我用的GNOME主题是Shiki-Colors-Brave,配合Openbox主题Onyx还挺搭调的~

五。进阶内容

本部分内容不适用于初学者。

要将你的桌面彻底替换为Openbox风格,可以将GConf键值</desktop/gnome/session/default-session>改为[openbox-session]或[openbox-gnome-session]。

六。结束词

怎么样,又快又灵便的openbox就这样正式上任了,开始享受它的疾速吧!

而且,再它的配置中,我没有使用任何与终端有关的内容,不必害怕!

如果对你有任何帮助,请留言支持一下!

七。其它

一些有用的链接

[1] Openbox 官网

[2] Openbox 常见问答

[3] Openbox 指南

[4] 更多截图

声明

本文除了参考第二个链接和LinuxTOY中有关ObConf的内容以外,其他均为个人摸索。

本文不是简单地抄袭LinuxTOY,只是想给不想看长篇大论的用户一个简单的文档(我就没那个耐心)。

编程珠玑番外篇D~J——高级语言怎么来的

一 http://blog.youxu.info/2009/05/13/hpl/

二 http://blog.youxu.info/2009/06/13/vm/

三 http://blog.youxu.info/2009/07/02/fortran/

四 http://blog.youxu.info/2009/08/31/lisp-and-ai-1/

五 http://blog.youxu.info/2010/02/10/lisp-and-ai-2/

六 http://blog.youxu.info/2010/07/12/scheme-1/

添加软件仓库到系统的小程序:addrepo(Fedora-Only)

代码已经推送到我的github,这里不再更新了

https://github.com/ekd123/ekode/tree/master/RepoUtilities (还有delrepo)

看ubuntu的一句话添加仓库的命令很眼红,为什么fedora没有?

为了让仓库添加更方便,我花了一个小时写了一个100行的python程序(看来我python才入门,Orz,其实都用在查找怎么下载文件上了)。

刚开始准备用shell写,刚写10行就又用Python写了(想了一会,shell基本上无力高级情况)

(比较丰富的例子,入门python可以看看~)

(本来里面用到了try..catch..,用来处理网址无效的,但是他居然说has no,一怒之下删掉了)

#!/usr/bin/python

## addrepo (GNU LGPLv3+)
## Written by Mike Ma
##
## This file can help you add a repo
## to your system

import os
import getpass
import sys
import urllib

#def var
repo_dir="/etc/yum.repos.d"
type=""
info1=""
info2=""
sfp_header="http://repos.fedorapeople.org/repos"

#def func
def show_usage():
    print ("""Usage: addrepo TYPE INFO [INFO]
TYPE:
     www       download repo from Internet.
                   info1: URL.
     sfp       standard fedora people repo. need two information
                   info1: group name.
                   info2: software name.
     fp        fedora people repo. need two information
                   info1: The username in FedoraPeople.
                   info2: repo file name. (no .repo)""")

def download_by_url(url,filename):
    print ("downloading " + url + " to " + filename)
    data = urllib.urlopen(url).read()
    f = file(filename,"w")
    f.write(data)
    f.close()
    print (data)
    print ("Done. Please check the file (if it's wrong, please delete that file and try the correct URL again)")

def check_http_and_add(url):
    if url.find("http://") == -1:
        return "http://" + url
    return url

def get_filename_from_url(url):
    arr=url.split("/")
    return arr[len(arr)-1]

def check_string(sstr):
    if sstr==None: return False
    if sstr==""  : return False
    return True

def show_error_and_exit_info():
    print ("information is invalid!")
    exit(-1)

# is it fedora?
if os.path.exists("/etc/fedora-release") == False:
    print ("You must run addrepo in Fedora");
    exit(-1)

# arg...
if len(sys.argv) < 3:
    show_usage()
    exit(-1)
if len(sys.argv) > 4:
    print ("Too many arguments")
    show_usage()
    exit (-1)
# is it root?
if getpass.getuser() != "root":
    print ("You must run addrepo as root")
    exit(-1)
# check dir
if os.path.exists(repo_dir) == False:
    print ("Can't find "+repo_dir)
    exit(-1)

############################################
type = sys.argv[1]  # doesn't need to check
info1 = sys.argv[2]
if check_string(info1) == False: show_error_and_exit_info()
if len(sys.argv) == 4: info2 = sys.argv[3]
if check_string(info2) == False: show_error_and_exit_info()

if type == "www":
    print ("Type: Repo from Internet")
    info1 = check_http_and_add(info1)
    download_by_url(info1, repo_dir + "/" + get_filename_from_url(info1))
    exit (0)
elif type == "sfp":
    print ("Type: Standard Fedorapeople.org Repo")
    url = sfp_header+"/"+info1+"/" + info2 + "/fedora-"+info2+".repo"
    download_by_url(url, repo_dir + "/" + get_filename_from_url(url))
    exit (0)
elif type == "fp":
    print ("Type: Non-standard Fedorapeople.org Repo")
    url = "http://"+info1+".fedorapeople.org/"+info2+".repo"
    download_by_url(url, repo_dir + "/" + get_filename_from_url(url))
    exit (0)
else:
    print ("Invalid type")
    show_usage()
    exit (0)

把它丢在/usr/bin下面,命名为addrepo,然后chmod +x addrepo就能用了。

有了这个东东,你就可以这样添加iceplayer的RPM源:

addrepo sfp zhtx iceplayer

(已死,别用)

这样添加chromium源:

addrepo sfp spot chromium

这样安装163源:

addrepo www mirrors.163.com/.help/fedora-163.repo
addrepo www mirrors.163.com/.help/fedora-updates-163.repo

(这里有自动判断有无http://功能)

哇咔咔,很方便吧?

其实我最大的希望是让这个东东成为Fedora的预装组件

如果有py大牛,修改了一定要给我说说啊,我当然也想用更好的~

PS:如果你在非Fedora的Linux上使用,结果会是……嘿嘿

Vala/GTK+2 系统Clipboard(剪贴板)读取

using Gtk;
using Gdk;

public class ClipboardReader
{
	public static int main (string[] args)
	{
		Gtk.init (ref args);
		Gtk.Clipboard clipboard = Gtk.Clipboard.get_for_display (Gdk.Display.get_default(), Gdk.SELECTION_CLIPBOARD);
		string text = clipboard.wait_for_text ();
		stdout.printf ("%s\n", text);

		return 0;
	}
}

// BUILD: $ valac clipboard.vala --pkg gtk+-2.0

更多的剪贴板操作见Valadoc.org

此处用的是GTK+ 2.0。

GObject简单示例

Gobject终于研究出来了(这个示例还没涉及到另外两个重要概念——信号/Signals,属性/Properties)。。。

声明:本代码直接参考GTK+代码实现,严格按照(最差也就是接近)GNOME标准书写。

演示了简单的继承功能(gobj规定所有类均直接或间接地基于GObject类)、私有成员、公有成员、构造函数和析构函数,而且也不是很难,很容易看懂。

直接在终端执行以下代码(发现直接复制粘贴容易出错,所以大家最好先存为一个.sh文件,然后允许它即可)

## begin funperson.h ##
cat >> funperson.h << EOF
#ifndef __FUN_PERSON_H__
#define __FUN_PERSON_H__

#include <glib-object.h>

G_BEGIN_DECLS

#define FUN_PERSON_TYPE (fun_person_get_type ())
#define FUN_PERSON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), FUN_PERSON_TYPE, FunPerson))
#define FUN_PERSON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FUN_PERSON_TYPE, FunPersonClass))
#define FUN_IS_PERSON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FUN_PERSON_TYPE))
#define FUN_IS_PERSON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FUN_PERSON_TYPE))
#define FUN_GET_PERSON_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FUN_PERSON_TYPE, FunPersonClass))

typedef struct _FunPerson FunPerson;
typedef struct _FunPersonPrivate FunPersonPrivate;
typedef struct _FunPersonClass FunPersonClass;

struct _FunPerson
{
    GObject parent;
/*< private >*/ //这儿很有意思,emacs会加亮private和public
    FunPersonPrivate *priv;

/*< public >*/
    GString *name;
};

struct _FunPersonClass
{
    GObjectClass parent_class;
};

GType fun_person_get_type (void);

FunPerson *fun_person_new (void);
FunPerson *fun_person_new_with_name (gchararray bloodtype);

void fun_person_set_blood_type (FunPerson *obj, gchararray bloodtype);
gchararray fun_person_get_blood_type (FunPerson *obj);

void fun_person_set_name (FunPerson *obj, gchararray name);
gchararray fun_person_get_name (FunPerson *obj);

G_END_DECLS

#endif /* __FUN_PERSON_H__ */
EOF
## End Of funperson.h ##

## Begin funperson.c ##
cat >> funperson.c << EOF
#include <glib.h>

#include "funperson.h"

struct _FunPersonPrivate
{
    gchararray bloodtype;
};

G_DEFINE_TYPE (FunPerson, fun_person, G_TYPE_OBJECT)

enum 
{
    PROP_0 /* 没有属性和信号 */
};

static void fun_person_dispose (GObject *gobject)
{
    /* TODO: 添加需要解除引用的对象 */
    /* TIP: dispose可能会被调用多次,所以必须使用g_object_undef解除引用 */
    
    G_OBJECT_CLASS (fun_person_parent_class)->dispose (gobject);
}

static void fun_person_finalize (GObject *gobject)
{
    /* TODO: 添加析构代码到这里 */
    FunPerson *self = FUN_PERSON (gobject);
    if (self->priv->bloodtype)
    {
        g_free (self->priv->bloodtype);
        self->priv->bloodtype = NULL;
    }
    if (self->name)
    {
        g_string_free (self->name, TRUE);
        self->name = NULL;
    }
    g_print ("A person was dead!\n");
    G_OBJECT_CLASS (fun_person_parent_class)->finalize (gobject);
}

FunPerson *fun_person_new ()
{
    FunPerson *obj;
    obj = g_object_new (FUN_PERSON_TYPE, NULL);
    return obj;
}

static void fun_person_class_init (FunPersonClass *klass)
{
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

    gobject_class->dispose = fun_person_dispose;
    gobject_class->finalize = fun_person_finalize;

    g_type_class_add_private (gobject_class, 
                              sizeof(FunPersonPrivate));
}

static void fun_person_init (FunPerson *obj)
{
    /* TODO: 添加初始化代码到这里 */
    obj->priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
                                             FUN_PERSON_TYPE,
                                             FunPersonPrivate);
    g_print ("A person was born!\n");
}

FunPerson *fun_person_new_with_name (gchararray name)
{
    FunPerson *obj;
    FunPersonPrivate *priv;

    obj = fun_person_new ();
    g_return_if_fail (obj>0);
    
    fun_person_set_name (obj, name);
    
    return obj;
}

void fun_person_set_blood_type (FunPerson *obj, gchararray bloodtype)
{
    FunPersonPrivate *priv;
    gchararray newstr;
    
    g_return_if_fail (FUN_IS_PERSON (obj));
    priv = obj->priv;
    g_return_if_fail (priv != NULL);

    newstr = g_strdup (bloodtype);
    g_free (priv->bloodtype);
    priv->bloodtype = newstr;
}

gchararray fun_person_get_blood_type (FunPerson *obj)
{
    g_return_if_fail (FUN_IS_PERSON(obj));
    return obj->priv->bloodtype;
}

void fun_person_set_name (FunPerson *self, gchararray name)
{
    GString *gstr;
    
    g_return_if_fail ((name != NULL) && (FUN_IS_PERSON (self)));

    gstr = g_string_new (name);
    g_return_if_fail (gstr != NULL);
    if (self->name)
        g_string_free (self->name, TRUE);
    self->name = gstr;
}

gchararray fun_person_get_name (FunPerson *self)
{
    g_return_if_fail (FUN_IS_PERSON (self));
    return self->name->str;
}
EOF
## end of file ##

## begin main.c ##
cat >> main.c << EOF
#include <glib.h>
#include "funperson.h"

gint main ()
{
    g_type_init (); /* init gtype */
    FunPerson *per = fun_person_new_with_name ("Tom");
    fun_person_set_blood_type (per, "AB");
    g_print ("%s's blood type is %s\n", fun_person_get_name (per),fun_person_get_blood_type (per));
    g_object_unref (per); /* free the object */

    per = fun_person_new ();
    fun_person_set_name (per, "Mike");
    fun_person_set_blood_type (per, "B");
    g_print ("Hi, all.\n%s makes this app. %s's blood type is %s\n", fun_person_get_name (per), fun_person_get_name (per), fun_person_get_blood_type (per));
    g_object_unref (per);
    return 0;
}
EOF
## end of main.c ##

然后就可以在这个目录下找到funperson.[ch]和main.c了

编译

cc main.c funperson.c $(pkg-config  --cflags --libs gobject-2.0 glib-2.0)

运行

./a.out

结果

A person was born!
Tom's blood type is AB
A person was dead!
A person was born!
Hi, all.
Mike makes this app. Mike's blood type is B
A person was dead!

Emacs中的K&R C风格设置

最近开始用emacs了,可是被这个问题困扰,就是我一般这样输入C代码

int foo(int x)
{
    int y, z;
    if( x < y )
        return y-x;
    else if ( x == y )
        return 0;
    else
        return x-y;
}

可是emacs就非得给我格式化成

int foo(int x)
    {
      int y, z;
      if( x < y )
        {
          return y-x;
        }
      else if ( x == y )
        {
          return 0;
        }
      else
        return x-y;
    }

后来一查,原来我一般用的就是K&R风格,而Emacs默认是GNU风格,在emacs的手册上找到了解决方法,自我发挥一下,就彻底解决这个问题了:

$ emacs ~/.emacs

追加如下代码:

;; c code indentation
(setq c-default-style
    '((c-mode . "k&r") (other . "gnu")))
(setq c-basic-offset 4)

现在就找回熟悉的自我了smiley

 

无根的根:无名师的Unix心传(Rootless Root: The Unix Koans of Master Foo)补遗

无名师与MCSE能者(Master Foo And the MCSE)

一通熟Windows之能者见无名师,曰:“闻师深修Unix之道,吾以密巧相述,相益,可乎?”

无名师曰:“求智,善矣;然Unix之道并无甚密巧。”

能者惑:“人曰师乃当世Unix大道之贤者,通晓其中之变法,如吾之于Windows;吾乃MCSE,有世所罕之证书,吾铭记各注册表项功能于心,更可细述任一Windows API,乃至微软所未曾详述者。师,所以为师,为智,皆揭而知他人之不知也。”

无名师曰:“怠矣,本无秘,何以揭?”

能者嗔:“若无密巧,何以修乃成师之业?”

无名师曰:“求智者,以他人之不知为智,犹如求光明者,拥烛笼火,以为珍贵,乃终被灼也。”

听此,能者顿觉灵光。

Master Foo and the MCSE

Once, a famous Windows system administrator came to Master Foo and asked him for instruction: “I have heard that you are a powerful Unix wizard. Let us trade secrets, that we may both gain thereby.”

Master Foo said: “It is good that you seek wisdom. But in the Way of Unix, there are no secrets.”

The administrator looked puzzled at this. “But it is said that you are a great Unix guru who knows all the innermost mysteries. As do I in Windows; I am an MCSE, and I have many other certifications of knowledge not common in the world. I know even the most obscure registry entries by heart. I can tell you everything about the Windows API, yes, even secrets those of Redmond have half-forgotten. What is the arcane lore that gives you your power?”

Master Foo said: “I have none. Nothing is hidden, nothing is revealed.”

Growing angry, the administrator said “Very well, if you hold no secrets, then tell me: what do I have to know to become as powerful in the Unix way as you?”

Master Foo said: “A man who mistakes secrets for knowledge is like a man who, seeking light, hugs a candle so closely that he smothers it and burns his hand.”

Upon hearing this, the administrator was enlightened.

转载自:http://blog.sinzy.net/jinjian/entry/22169

 

 

下面的都是自己翻译的,有误之处请指出:

无名师与命令行工具(Master Foo and the Shell Tools)

一Unix初学者谓无名师曰:“吾甚惑矣。此非Unix大道邪?程序皆应完成己职?”

师颔首。

此初学者又曰:“轮不可更之亦Unix之大道邪?”

师再颔首。

“然,于文本之处理有相同之物:sed、awk与Perl何也?于Unix大道孰可制成至佳?”

师问初学者曰:“若汝有一文本,何物汝用之生一副本替自尔之选之文本?”

初学者蹙眉曰:“Perl之正则对此甚简单,吾不知awk,吾将书一sed脚本。吾深通sed,斯时吾之愿矣。然若此职仅一次,而非重复,一文本之编辑器足矣。”

师颔首答曰:“汝饿而食,渴而饮,困而眠,与之同也。”

闻此,初学者顿觉灵光。

A Unix novice came to Master Foo and said: “I am confused. Is it not the Unix way that every program should concentrate on one thing and do it well?

Master Foo nodded.

The novice continued: “Isn't it also the Unix way that the wheel should not be reinvented?

Master Foo nodded again.

Why, then, are there several tools with similar capabilities in text processing: sed, awk and Perl? With which one can I best practice the Unix way?

Master Foo asked the novice: “If you have a text file, what tool would you use to produce a copy with a few words in it replaced by strings of your choosing?

The novice frowned and said: “Perl's regexps would be excessive for so simple a task. I do not know awk, and I have been writing sed scripts in the last few weeks. As I have some experience with sed, at the moment I would prefer it. But if the job only needed to be done once rather than repeatedly, a text editor would suffice.

Master Foo nodded and replied: “When you are hungry, eat; when you are thirsty, drink; when you are tired, sleep.

Upon hearing this, the novice was enlightened.

无名师与老手(Master Foo and the Old Hand)

一强Unix程序员,闻无名师之智,访而求教。至师前三鞠躬,曰:

“师,吾忐忑至深。吾幼,人皆追随Unix大道,其软件若ed,mailx之简明、无碍。今,其用vim与mutt。明,吾惧其欲用KMail与Evolution,Unix欲为Windows矣。其臃肿且图形之界面之多。”

师曰:“然汝欲制一海报,将用何物?”

程序员答曰:“吾未尝制之……然吾之于Unix大道之无用图形界面,而用LaTeX或图制之。”

师曰:“此二人谁人能及对岸:其一思一舟,其二行至一桥?”

闻此,程序员顿觉灵光。

An experienced Unix programmer, hearing of Master Foo's wisdom, came to him for guidance. Approaching the Master, he bowed three times and said:

Master Foo, I am gravely troubled. In my youth, those who followed the Great Way of Unix used software that was simple and unaffected, like ed and mailx. Today, they use vim and mutt. Tomorrow I fear they will use KMail and Evolution, and Unix will have become like Windows — bloated and covered over with GUIs.

Master Foo said: “But what software do you use when you want to draw a poster?

The programmer replied: “I...have never done that. But I am sure that I could use LaTeX or pic to accomplish it without GUIs, in the proper Unix way.

Master Foo then said: “Which one will reach the other side of the river: The one who dreams of a raft, or the one that hitchhikes to the next bridge?

Upon hearing this, the programmer was enlightened.

无名师与傻瓜新手(Master Foo and the Nervous Novice)

(虚位以待)

There was a novice who learned much at the Master's feet, but felt something to be missing. After meditating on his doubts for some time, he found the courage to approach Master Foo about his problem.

Master Foo,” he asked “why do Unix users not employ antivirus programs? And defragmentors? And malware cleaners?

Master Foo smiled, and said “When your house is well constructed, there is no need to add pillars to keep the roof in place.

The novice replied “Would it not be better to use these things anyway, just to be certain?

Master Foo reached for a nearby ball of string, and began wrapping it around the novice's feet.

What are you doing?” the novice asked in surprise.

Master Foo replied simply: “Tying your shoes.

Upon hearing this, the novice was enlightened.

无名师论返回Windows(Master Foo Discourses on Returning to Windows)

虚位以待

A student said: “We have learned that Unix is not just an operating system, but also a style of approaching problems.

Master Foo nodded in agreement.

The student continued: “Then, the Great Way of Unix can be applied on other operating systems?

Master Foo sat silent for a moment, then said: “In every operating system there is a path to the Great Way, if only we can find it.

The student continued: “What, then, of Windows? It is preinstalled on most computers, and though its tools are mostly far inferior, they are easy to use for beginners. Surely, Windows users could benefit from the Unix philosophy.

Master Foo nodded again.

The student said: “How, then, are those enlightened in the Unix Way to return to the Windows world?

Master Foo said: “To return to Windows, you have but to boot it up.

The student said, growing agitated: “Master Foo, if it is so easy, why are there so many monolithic and broken software packages for Windows? Elegant software should also be possible with a GUI and fancy colors, but there is little evidence that this occurs. What becomes of an enlighted one who returns to Windows?

Master Foo: “A broken mirror never reflects again; fallen flowers never go back to the old branches.

Upon hearing this, all present were enlightened.