2008年7月11日

10 handy bash aliases

Cut down on Linux command-line typing with these 10 handy bash aliases | 10 Things | TechRepublic.com
Cut down on Linux command-line typing with these 10 handy bash aliases
The Linux desktop has come a long, long way, but there are still times when I have to use the command line. (I am a hardcore user, after all.) But even though I’m used to typing, spending hours upon hours with my fingers at the keyboard, I still grow tired of typing the same commands over and over. To reduce that tedium, I always add aliases to my .bashrc file.
What is an alias?

An alias is basically a shortcut for a command you place in your ~/.bashrc file. Aliases cut down on typing and can save you from having to look up a command. (If your memory is like mine, this can be a real boon!)

Aliases are set up near the bottom of the of the .bashrc file. You’ll see a commented-out section that indicates where you should put them. The format of an alias is:

Alias NICKNAME='full command here'

The keyword alias must be used. The nickname is what you will type at the command line. Make this nickname easy to remember. The = sign must also be used. After the = sign, you enter the full command, including flags and switches, enclosed in single quotes. Once you are done, save the .bashrc file and open up a new terminal. I always find it best to leave the original terminal window open in case there are problems. In the new terminal, type the alias nickname and the command will run.

To get you started, I’ve compiled the following list of aliases I have used over the years to help make my command-line experience a bit easier.

Note: This information is also available as a PDF download.
#1: The ssh alias

This one should be a no-brainer for those of you who frequently secure shell into particular boxes. For this I add an alias like so:

alias server_name='ssh -v -l USERNAME IP ADDRESS'

Just change server_name to a memorable name for the server. Then, change USERNAME and IP ADDRESS to suit your needs.
#2: The ls aliases

Some distributions don’t include some of the handier ls commands. Generally, I like to see full listings instead of just filenames. For that I always include this alias:

alias ll='ls -l'

Another handy ls alias is this:

alias la='ls -a'

#3: The rm safety net

I can’t tell you how many times I have “rm’d” a file I shouldn’t have “rm’d”. To avoid this, I add this alias:

alias rm='rm -i'

Adding the ‘-i’ flag it forces rm into interactive mode, which will ask you whether you’re sure you want to remove a file.
#4: The more useful df command

This handy tool tells you how much space you have left on a drive. Only thing is, if you run the command by itself it replies in 1K blocks. Most people would prefer to see this in terms of MB. To make that happen, add this alias:

alias df='df -h'

Now, every time you run the df command, the information will be returned in a human-readable format.
#5: The nonstandard Firefox

Many times, I install Firefox in strange directories (or have more than one version of Firefox installed for testing purposes). For this, I will add an alias to start the correct Firefox. Say, for example, I have the beta of the newest, upcoming Firefox release installed, as well as the current stable Firefox. They are both installed in my home directory in different subdirectories. I will then add two aliases like so:

alias ff1='/home/jlwallen/firefox/firefox'

alias ff2='/home/jlwallen/firefoxb3/firefox'

Now I can start the stable firefox with ff1 or the beta with ff2.
#6: The bookmark alias

Speaking of Firefox, let’s create an alias to open up it to a specific URL:

alias fftr='/home/jlwallen/firefox/firefox http://www.techrepublic.com'

This alias will open Firefox directly to the TechRepublic Web site.
#7: The constant editing of a file

There are certain files that I am constantly editing. For instance, when I used Enlightenment E16 (I now use E17), I was frequently editing the menu file ~/e16/menus/user_apps. Instead of constantly opening up a terminal and entering nano ~/.e16/menus/user_apps, I used an alias that allowed me to type emenu and start editing. I used this alias:

alias emenu='aterm nano -e ~/.e16/menus/user_apps'

Now, I just enter the command emenu (or I can enter that in the run command dialog) to open up this file in an editor.
#8: The apt-get update

There are numerous ways to use an alias to help you with apt-get. One of my favorite is to add this alias:

alias update='sudo apt-get update'

I only need to enter update and will be prompted for the sudo password. You can modify this to suit your frequent apt-get needs.
#9: The rpm batch install

I like to do a lot of batch installing with rpm. I will typically dump a bunch of rpm files into an empty directory (created for this specific purpose) and run the command rpm -ivh ~/RPM/*rpm. Of course, an alias makes this even easier:

alias brpm='rpm -ivh ~/RPM/*rpm'

You have to create the ~/RPM directory and enter the root password for this to work.
#10: The long, arduous path

There are some paths that I often change to that seem to take eons to type. When I was working on the Afterstep window manager, I had to constantly change to the ~/GNUstep/Library/AfterStep/start to edit menus. After a while, you get tired of typing cd ~/GNUstep/Library/AfterStep/start just to get to the directory. So I added an alias like so:

alias astart='cd ~/GNUstep/Library/AfterStep/start'

Naturally, you can change that to fit your needs. This will save you a lot of typing.

So there you have it: a few simple bash aliases that will ease the load on your fingers. You can modify them to suit you, and they’ll give you a good start on creating your own handy bash aliases.

2008年7月9日

Protocol Buffers

Google Open Source Blog: Protocol Buffers: Google's Data Interchange Format
Protocol Buffers: Google's Data Interchange Format
Monday, July 7, 2008 at 3:01 PM
By Kenton Varda, Software Engineering Team

At Google, our mission is organizing all of the world's information. We use literally thousands of different data formats to represent networked messages between servers, index records in repositories, geospatial datasets, and more. Most of these formats are structured, not flat. This raises an important question: How do we encode it all?

XML? No, that wouldn't work. As nice as XML is, it isn't going to be efficient enough for this scale. When all of your machines and network links are running at capacity, XML is an extremely expensive proposition. Not to mention, writing code to work with the DOM tree can sometimes become unwieldy.

Do we just write the raw bytes of our in-memory data structures to the wire? No, that's not going to work either. When we roll out a new version of a server, it almost always has to start out talking to older servers. New servers need to be able to read the data produced by old servers, and vice versa, even if individual fields have been added or removed. When data on disk is involved, this is even more important. Also, some of our code is written in Java or Python, so we need a portable solution.

Do we write hand-coded parsing and serialization routines for each data structure? Well, we used to. Needless to say, that didn't last long. When you have tens of thousands of different structures in your code base that need their own serialization formats, you simply cannot write them all by hand.

Instead, we developed Protocol Buffers. Protocol Buffers allow you to define simple data structures in a special definition language, then compile them to produce classes to represent those structures in the language of your choice. These classes come complete with heavily-optimized code to parse and serialize your message in an extremely compact format. Best of all, the classes are easy to use: each field has simple "get" and "set" methods, and once you're ready, serializing the whole thing to – or parsing it from – a byte array or an I/O stream just takes a single method call.

OK, I know what you're thinking: "Yet another IDL?" Yes, you could call it that. But, IDLs in general have earned a reputation for being hopelessly complicated. On the other hand, one of Protocol Buffers' major design goals is simplicity. By sticking to a simple lists-and-records model that solves the majority of problems and resisting the desire to chase diminishing returns, we believe we have created something that is powerful without being bloated. And, yes, it is very fast – at least an order of magnitude faster than XML.

And now, we're making Protocol Buffers available to the Open Source community. We have seen how effective a solution they can be to certain tasks, and wanted more people to be able to take advantage of and build on this work. Take a look at the documentation, download the code and let us know what you think.

Permalink

A slightly advanced Introduction to Vim

A slightly advanced Introduction to Vim LG #152
Who is it for?

This is not a five minute introduction to vim for a complete newbie. I presume you have used vim before and are comfortable with moving around, and making changes. Though :vimtutor is not a prerequisite to this tutorial, I highly recommend it.

This document contains some mnemonics, and some slightly advanced features of vim that can help the average vim user/programmer increase his/her productivity by leaps and bounds.

2008年7月7日

locale 設定相關說明

1. 如何知道自己的 locale 狀態?
代碼:
locale

2. 如何知道自己 export 了什麼東西?
代碼:
export

3. locale 相關知識
代碼:
dpkg-reconfigure locales

執行這個指令時, 設定的是 LANG, 這是最沒效力的。
如果沒有安裝 locales, 預設的 LANG 通常稱為 C 或 POSIX
man page 或其他文字通常是以 en 或 en_US 顯示

最強效的是 LC_ALL, 設定下去, 底下這些都會強制跟 LC_ALL 相同。LC_ALL 沒有預設值。

LC_CTYPE 字元分類和處理, 一般的輸入法只要設定這個就能用
LC_NUMERIC 處理非金錢相關的數字格式
LC_TIME 處理時間、日期等
LC_COLLATE 處理字元比較和排序
LC_MONETARY 處理金錢相關的格式和符號
LC_MESSAGES 處理顯示的格式, 訊息想看中文要設定這個
LC_PAPER
LC_NAME
LC_ADDRESS
LC_TELEPHONE
LC_MEASUREMENT
LC_IDENTIFICATION

另外還有一個 LANGUAGE
這只有少數程式會用到

4. 範例:
代碼:
export LANG=zh_TW.UTF-8
export LC_ALL=zh_TW.UTF-8
export LC_CTYPE=zh_TW.UTF-8

在這裡設定 LANG 和 LC_CTYPE 都是沒意義的, 因為 LC_ALL 已經設定了

代碼:
export LANG=zh_TW.BIG5
export LC_ALL=zh_TW.UTF-8

在這裡 LANG 無效

代碼:
export LANG=zh_TW.BIG5
export LC_CTYPE=zh_TW.UTF-8
export LC_MESSAGES=zh_TW.UTF-8

顯示輸入都是用 UTF-8, 其他的東西則是 big5

代碼:
export LANG=POSIX
export LC_CTYPE=zh_TW

全部都是美式英文, 但可以輸入繁體中文

代碼:
export LC_MESSAGES=zh_TW

通常設定這個之後, 軟體的介面和選單就會用中文(如果有支援的話)
例外是 openoffice, 還要設定
代碼:
export LANGUAGE=zh_TW

gpupdate -- Refreshes Group Policy settings

Gpupdate
Gpupdate

Refreshes local Group Policy settings and Group Policy settings that are stored in Active Directory, including security settings. This command supersedes the now obsolete /refreshpolicy option for the secedit command.
Syntax

gpupdate [/target:{computer | user}] [/force] [/wait:Value] [/logoff] [/boot]

2008年7月5日

fon hack

Rex’s blah blah blah » Fonera 與 SD Card!
可能不少人都知道 La Fonera 上用了 SPI Bus ,而且尚留有一組 SW 腳位可用。透過這個腳位,我們可蠻容易的加上 SD Card 或 MMC Card。
» Fonera SD Card Hack on Jkx@home » Blog Archive
Fonera SD Card Hack

I read on several websites, that some people managed to wire a SD Card (or a MMC) to a Fonera access point. After a little googling, I discover this can be done easily, so I decided to test.. but I run into one issue so I decided to describe the process here.
(T)ttrick Infinite Space: Important Patch for FreeWLAN Addons
Important Patch for FreeWLAN Addons
特別感謝

感謝阿德、Freddy提供發生問題的FON進行研究,才會有這個解決方法的誕生!相關留言可在FreeWLAN的介紹網頁找到。
(T)ttrick Infinite Space: Make a Serial Console Cable for La Fonera
Make a Serial Console Cable for La Fonera
前言

這次要介紹的主角是Serial Console Cable。它最主要的用途,就是透過Serial Port來操作FON的Console,並能在FON一開機時取得內部訊息,對於想要完全惡搞的人來說,是一把強力的螺絲起子。
FreeWLAN - Trac

2008年7月2日

Poderosa -- SSH client under Windows

Tabbed style GUI
It is convenient to open multiple connections at the same time. Moreover, you can split the window into panes and allocate each connection.
Many different ways to connect.
In addition to Telnet and SSH1/2, local cygwin shell and serial ports are supported.

Fulfilling options and tools
A lot of terminal functions are available. Examples are: SSH2 port forwarding, SSH Key generation wizard, and SOCKS connections.

index - Terminal Emulator Poderosa