Unix 常用命令

cat:

cat file1 file2
就是把文件file1和file2连在一起,然后输出到屏幕上
cat file1 file2>file3
就是将文件file1和file2的内容输出到file3中。在Dos里这条命令被写成copy file1+file2 file3

使用 cat 创建文件的示例

$ cat > grocery.list
apples
bananas
plums

$

使用 ‘>>’ 操作符将标准输入追加到现有文件。

使用 cat 追加文件的示例

$ cat >> grocery.list
carrots

使用 cat 命令不加标志,可查看 grocery.list 文件的内容。请注意文件的内容如何包含来自重定向的输入以及追加操作符的示例。

命令:cat

使用权限:所有使用者

使用方式:cat [-AbeEnstTuv] [–help] [–version] fileName

说明:把档案串连接后传到基本输出(萤幕或加 > fileName 到另一个档案)

参数:

-n 或 --number 由 1 开始对所有输出的行数编号

-b 或 --number-nonblank 和 -n 相似,只不过对于空白行不编号

-s 或 --squeeze-blank 当遇到有连续两行以上的空白行,就代换为一行的空白行

-v 或 --show-nonprinting

wc

wc命令用来计算数字。利用wc指令我们可以计算文件的Byte数、字数或是列数,若不指定文件名称,或是所给予的文件名为“-”,则wc指令会从标准输入设备读取数据。

-c或–bytes或——chars:只显示Bytes数;
-m 或–chars : 打印字符数
-l 或——lines:只显示列数;
-w 或——words:只显示字数。

tr

tr用来从标准输入中通过替换或删除操作进行字符转换.
例子:
tr ‘A-Z’ ‘a-z’ < text 文件大写全部变小写
tr ‘a-zA-Z’ ‘b-zaB-ZA’ < text (a->b, b->c …z->a)
tr -d ‘0-9’ < text 文件内数字全部删除
tr -cs ‘a-zA0-9’ ‘\n’ < text (break text file into individual words, one per line)

Some options:
-c map all characters not occurring in sourceChars (complement)
-s squeeze adjacent repeated characters out (only copy the first)
-d delete all characters in sourceChars (no destChars)

head/tail

The tail prints the last n lines of input.
E.g. tail-n 30 file prints last 30 lines of file.
Combine head and tail to select a range of lines.
E.g. head -n 100 | tail -n 20 copies lines 81…100 to output.

egrep: select lines matching a pattern

The egrep command only copies to output those lines in the input that match a specified pattern.
The pattern is supplied as a regular expression on the command line (and should be quoted using single-quotes).
Some options:
-i ignore upper/lower-case difference in matching
-v only display lines that do not match the pattern
-w only match pattern if it makes a complete word

grep

(The name grep is an acronym for Globally search with Regular Expressions and Print)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值