从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
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.
本文介绍两个实用的Linux命令技巧:一是使用column-t工具将输入数据转换为格式化的表格;二是通过bash历史记录管理和搜索增强来提高命令行工作效率。
1118

被折叠的 条评论
为什么被折叠?



