蓦然回首,那些命令都在灯火阑珊处

来源:互联网 发布:desmume mac 编辑:程序博客网 时间:2024/05/01 13:16

    从StackExchange中linux&unix发现一些好玩的问题,把他们先记录下来。

1. A shell tool to “tablify” input data

A long time ago I remember using a command that makes its input into a nicely formatted table.

For example, for this input,


apple 1 100
orange 20 19
pineapple 1000 87
avocado 4 30


The output will be similar to this:

apple 1 100
orange 20 19
pineapple 1000 87
avocado 4 30
I'd like to know the name of this tool.


Answer:

column -t

$ column -t <<END
> apple 1 100
> orange 20 19
> pineapple 1000 87
> avocado 4 30
> END
apple 1 100
orange 20 19
pineapple 1000 87
avocado 4 30


2. I have a lot of commands I routinely need to execute, often with the slightest variation.

Right now I'm storing them all in .bash_history and use CTRL-R to access them, but I wonder if there's a better way. What I'm looking for:

Easy to add a new command
Easy to search and re-execute a wanted command
Avoid unwanted commands in suggestions
Unfortunately, bash_history is not so strong on the third demand: if I do a few cd and ls, it fills the history file quickly. I have recently learned about HIST_SIZE and that you can configure the history to avoid duplicates or certain commands, but before configuring all that, I wanted to make sure it is the best way.

Answer:

A. Another tip: I sometimes use comments to bookmark/tag a command:

my_command #bookmark
then:
[ctrl-r]#bookmark

B. I find very useful the following readline commands

history-search-backward,
history-search-forward
(be aware they are different from the usual reverse-search-history, forward-search-history, tied to Ctrl-R, Ctrl-S).

I have these commands associated to Ctrl-Up and Ctrl-Down putting the following lines into ~/.inputrc:

"\e[1;5A": history-search-backward
"\e[1;5B": history-search-forward
How they work: write few chars of the beginning of the command, press Ctrl-Up and the next older command starting with that prefix will be shown, press again to see the next, and so on. When you are satisfied, after possibly modifying the command, press Enter to execute.

原创粉丝点击