Linux fmt命令用于编排文本文件。
fmt指令会从指定的文件里读取内容,将其依照指定格式重新编排后,输出到标准输出设备。若指定的文件名为"-",则fmt指令会从标准输入设备读取数据。
语法
fmt [-cstu][-p<列起始字符串>][-w<每列字符数>][--help][--version][文件...]
参数说明:
-c或--crown-margin 每段前两列缩排。
-p<列起始字符串>或-prefix=<列起始字符串> 仅合并含有指定字符串的列,通常运用在程序语言的注解方面。
-s或--split-only 只拆开字数超出每列字符数的列,但不合并字数不足每列字符数的列。
-t或--tagged-paragraph 每列前两列缩排,但第1列和第2列的缩排格式不同。
-u或--uniform-spacing 每个字符之间都以一个空格字符间隔,每个句子之间则两个空格字符分隔。
-w<每列字符数>或--width=<每列字符数>或-<每列字符数> 设置每列的最大字符数。
--help 在线帮助。
--version 显示版本信息。
实例
重排指定文件。如文件testfile共5 行文字,可以通过命令对该文件格式进行重排,其命令为:
fmt testfile
输出结果如下:
$ fmt testfile #重排testfile 文件
hello Linux! Linux is a free Unix-type operating system. This is a
Linux testfile! Linux Linux
将文件testfile重新排成85 个字符一行,并在标准输出设备上输出,其命令应该为:
fmt -w 85 testfile
为了对比,先使用cat 命令查看文件内容:
$ cat testfile #查看testfile 文件的内容
hello Linux!
Linux is a free Unix-type operating system.
This is a Linux testfile!
Linux
Linux
使用fmt命令重排之后,输出结果如下:
$ fmt -w 85 testfile #指定重排宽度为85个字符
hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile!
Linux jed命令用于编辑文本文件。
Jed是以Slang所写成的程序,适合用来编辑程序原始代码。
语法
jed [-2n][-batch][-f<函数>][-g<行数>][-i<文件>][-I<文件>][-s<字符串>][文件]
参数:
-2 显示上下两个编辑区。
-batch 以批处理模式来执行。
-f<函数> 执行Slang函数。
-g<行数> 移到缓冲区中指定的行数。
-i<文件> 将指定的文件载入缓冲区。
-i<文件> 载入Slang原始代码文件。
-n 不要载入jed.rc配置文件。
-s<字符串> 查找并移到指定的字符串。
实例
jed主要用于编辑程序的源码,编辑源码时将以彩色高亮的方式显示程序的语法。例如使用jed编辑一个C语言的源代码文件,可使用如下命令:
jed main.c #用jed编辑器打开main.c 文件
输出结果如下:
F10 key ==> File Edit Mode Search Buffers Windows System Help #编辑器菜单
/*-*- linux-c-*-*/ #编辑区
#include <linux/mm.h>
#include <linux/sysctl.h>
#include <linux/nsproxy.h>
static struct list_head *
net_ctl_header_lookup(struct ctl_table_root *root, struct nsproxy *namespaces)
{
return &namespaces->net_ns->sysctl_table_headers;
}
static struct ctl_table_root net_sysctl_root = {
.lookup = net_ctl_header_lookup,
};
static int sysctl_net_init(struct net *net)
{
INIT_LIST_HEAD(&net->sysctl_table_headers);
return 0;
}
-----+(Jed 0.99.18U) Emacs: main.c (C) All 6:06pm-----------------------------
#从左到右分别为jed版本编号、当前是模拟emacs编辑器、打开的文件名、现在的时间
loading /usr/share/jed/lib/modeinfo.slc