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

    从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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值