`
dalezhu
  • 浏览: 205925 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

linux常用命令

    博客分类:
  • OS
阅读更多
linux常用命令


(Tools of Shell)sort sort -cfile 查看此文件是否是排序过的
$ sort names
Charlie
Emanuel
Fred
Lucy
Ralph
Tony
Tony
$
-u去掉重复的列
$ sort -u names
Charlie
Emanuel
Fred
Lucy
Ralph
Tony
$
-r逆序
$ sort -r names
Tony
Tony
Ralph
Lucy
Fred
Emanuel
Charlie
$
-o 把排序结果写入文件
$ sort names -o sorted_names
$
$ sort names > sorted_names
$
-n表明按照把第一列当成数字,并按照第一列来排序
$ sort data
-5 11
14 -9
15 6
2 12
23 2
3 33
5 27
$ sort -n data
-5 11
2 12
3 33
5 27
14 -9
15 6
23 2
$
跳过第一列进行排序
$ sort +1n data
14 -9
23 2
15 6
-5 11
2 12
5 27
3 33
$

-t按照指定的字符分隔,
$ sort +2n -t: /etc/passwd 第三列进行排序
root:*:0:0:The Super User:/:/usr/bin/ksh
cron:*:1:1:Cron Daemon for periodic tasks:/:
bin:*:3:3:The owner of system files:/:
uucp:*:5:5::/usr/spool/uucppublic:/usr/lib/uucp/uucico
asg:*:6:6:The Owner of Assignable Devices:/:
sysinfo:*:10:10:Access to System Information:/:/usr/bin/sh
george:*:75:75::/users/george:/usr/lib/rsh
steve:*:203:100::/users/steve:/usr/bin/ksh
pat:*:300:300::/users/pat:/usr/bin/ksh
mail:*:301:301::/usr/mail:
$
( 2005年09月19日, 03:10:09 下午 CST ) Permalink 留言 [0]

(Tools of Shell)grep grep '[A-Z]' list Lines from list containing a capital letter

grep '[0-9]' data Lines from data containing a number

grep '[A-Z]...[0-9]' list Lines from list containing five-character patterns that start with a capital letter and end with a digit

grep '\.pic$' filelist Lines from filelist that end in .pic

$ grep shell *
cmdfiles:shell that enables sophisticated
ed.cmd:files, and is independent of the shell.
ed.cmd:to the shell, just type in a q.
grep.cmd:occurrence of the word shell:
grep.cmd:$ grep shell *
grep.cmd:every use of the word shell.
$

-i表示忽略大小写
grep –i 'the' intro
-v表示查找不包含此字符串的行
$ grep -v 'UNIX' intro Print all lines that don't contain UNIX
Thompson and Dennis Ritchie at Bell Laboratories
in the late 1960s. One of the primary goals in
environment that promoted efficient program
development.
$
-l表示列出包含此字符串的文件名 $ grep -l 'Move_history' *.c List the files that contain Move_history
exec.c
makemove.c
testch.c
$
$ grep -l 'Move_history' *.c | wc -l
3
$
-n打印所包含字符串的行数
$ grep -n 'Move_history' testch.c Precede matches with line numbers
13:GLOBAL MOVE Move_history[100] = {0};
197: Move_history[Number_half_moves-1].from = move.from;
198: Move_history[Number_half_moves-1].to = move.to;
$
( 2005年09月19日, 02:18:34 下午 CST ) Permalink 留言 [0]

(Tools of Shell)tr tr from-chars to-chars tr 'X' 'x' Translate all capital X's to small x's tr '()' '{}' Translate all open parens to open braces, all closed parens to closed braces tr '[a-z]' '[A-Z]' Translate all lowercase letters to uppercase ...
Read More
( 2005年09月19日, 01:41:38 下午 CST ) Permalink 留言 [0]

(Tools of Shell)Sed sed '5d' Delete line 5

sed '/[Tt]est/d' Delete all lines containing Test or test

sed -n '20,25p' text Print only lines 20 through 25 from text

sed '1,10s/unix/UNIX/g' intro Change unix to UNIX wherever it appears in the first 10 lines of intro

sed '/jan/s/-1/-5/' Change the first -1 to -5 on all lines containing jan

sed 's/...//' data Delete the first three characters from each line of data

sed 's/...$//' data Delete the last 3 characters from each line of data

sed -n 'l' text Print all lines from text, showing nonprinting characters as \nn (where nn is the octal value of the character), and tab characters as \t


$ cat intro
The Unix operating system was pioneered by Ken
Thompson and Dennis Ritchie at Bell Laboratories
in the late 1960s. One of the primary goals in
the design of the Unix system was to create an
environment that promoted efficient program
development.

$

$ sed 's/Unix/UNIX/' intro Substitute Unix with UNIX

The UNIX operating system was pioneered by Ken
Thompson and Dennis Ritchie at Bell Laboratories
in the late 1960s. One of the primary goals in
the design of the UNIX system was to create an
environment that promoted efficient program
development.
$

$ sed -n '1,2p' intro Just print the first 2 lines

The UNIX operating system was pioneered by Ken
Thompson and Dennis Ritchie at Bell Laboratories

$

$ sed -n '/UNIX/p' intro Just print lines containing UNIX

The UNIX operating system was pioneered by Ken
the design of the UNIX system was to create an

$

$ sed '1,2d' intro Delete lines 1 and 2

in the late 1960s. One of the primary goals in
the design of the UNIX system was to create an
environment that promoted efficient program
development.

$

$ sed '/UNIX/d' intro Delete all lines containing UNIX

Thompson and Dennis Ritchie at Bell Laboratories
in the late 1960s. One of the primary goals in
environment that promoted efficient program
development.

$
( 2005年09月19日, 01:15:04 下午 CST ) Permalink 留言 [0]

(Tools of Shell)Paste $ cat names
Tony
Emanuel
Lucy
Ralph
Fred
$

$ cat numbers
(307) 555-5356
(212) 555-3456
(212) 555-9959
(212) 555-7741
(212) 555-0040
$

$ paste names numbers Paste them together
Tony (307) 555-5356
Emanuel (212) 555-3456
Lucy (212) 555-9959
Ralph (212) 555-7741
Fred (212) 555-0040
$

$ cat addresses
55-23 Vine Street, Miami
39 University Place, New York
17 E. 25th Street, New York
38 Chauncey St., Bensonhurst
17 E. 25th Street, New York

$ paste names addresses numbers
Tony 55-23 Vine Street, Miami (307) 555-5356
Emanuel 39 University Place, New York (212) 555-3456
Lucy 17 E. 25th Street, New York (212) 555-9959
Ralph 38 Chauncey St., Bensonhurst (212) 555-7741
Fred 17 E. 25th Street, New York (212) 555-0040
$

paste -dchars 用chars来做分隔符,第一个字符分隔第一个和第二个字符串,第二个字符分隔第二个和第三个字符串,依此类推.分隔符要用' '号标记
$ paste -d'+' names addresses numbers
Tony+55-23 Vine Street, Miami+(307) 555-5356
Emanuel+39 University Place, New York+(212) 555-3456
Lucy+17 E. 25th Street, New York+(212) 555-9959
Ralph+38 Chauncey St., Bensonhurst+(212) 555-7741
Fred+17 E. 25th Street, New York+(212) 555-0040
$

$ paste -d'+-' names addresses numbers
Tony+55-23 Vine Street, Miami-(307) 555-5356
Emanuel+39 University Place, New York-(212) 555-3456
Lucy+17 E. 25th Street, New York-(212) 555-9959
Ralph+38 Chauncey St., Bensonhurst-(212) 555-7741
Fred+17 E. 25th Street, New York-(212) 555-0040
$

paste -s filename 是把一个文件里的内容打印在一行里

$ paste -s names Paste all lines from names
Tony Emanuel Lucy Ralph Fred
$ ls | paste -d' ' -s - Paste ls's output, use space as delimiter
addresses intro lotsaspaces names numbers phonebook
$
( 2005年09月19日, 10:58:27 上午 CST ) Permalink 留言 [0]


星期五 2005年09月16日
Unix中的正则表达式 Regular Expression Characters Notation Meaning Example Matches . any character a.. a followed by any two characters ^ beginning of line ^wood wood only...
Read More
( 2005年09月16日, 09:45:37 下午 CST ) Permalink 留言 [0]

(Tools of Shell)Cut cut命令
cut的基本语法是 cut -cchars file chars表明要每行要输出的个数,可以用单个数字,比如-c5的话,就表明输出第五个字符,中间可以用,号间隔,比如-c1,2就输出第一个和第二个字符; 如果中间有-符号,就表明要输出一个范围 比如-c1-5,就输出第一个到第五个字符,如果想输出一直到最后一个字符的话,可以忽略最后一个数字,例如 cut -c5- data

举例说明:

$ who
root console Feb 24 08:54
steve tty02 Feb 24 12:55
george tty08 Feb 24 09:15
dawn tty10 Feb 24 15:55
$

$ who | cut -c1-8 Extract the first 8 characters
root
steve
george
dawn
$

$ who | cut -c1-8 | sort
dawn
george
root
steve
$

$ who | cut -c1-8,18-

root Feb 24 08:54
steve Feb 24 12:55
george Feb 24 09:15
dawn Feb 24 15:55
$
The -d and -f Options $ cat /etc/passwd
root:*:0:0:The Super User:/:/usr/bin/ksh
cron:*:1:1:Cron Daemon for periodic tasks:/:
bin:*:3:3:The owner of system files:/:
uucp:*:5:5::/usr/spool/uucp:/usr/lib/uucp/uucico
asg:*:6:6:The Owner of Assignable Devices:/:
steve:*:203:100::/users/steve:/usr/bin/ksh
other:*:4:4:Needed by secure program:/:
$
/etc/passwd 是一个包含本机器所有用户姓名的控制文件.还有包含类似用户编号,根目录,还有这个用户登陆后运行的程序. -d 和 -f表明要输出的字符串包含特殊字符 用法为: cut -ddchar –ffields file dchar表明这个字符是用来分割这个数据的, fields指定输出的位置,比如说-f1,2,8 -f1-3, -f4- 等等 $ cut -d: -f1 /etc/passwd Extract field 1
root
cron
bin
uucp
asg
steve
other
$

$ cut -d: -f1,6 /etc/passwd Extract fields 1 and 6 root:/
cron:/
bin:/
uucp:/usr/spool/uucp
asg:/
steve:/users/steve
other:/
$
分享到:
评论

相关推荐

    最全Linux常用命令大全.pdf

    以下是一些关于Linux常用命令的详细说明: 1. **pwd**:`pwd`(Print Working Directory)命令用于显示当前工作目录,即用户当前所在的目录路径。 2. **cd**:`cd`命令用于切换目录。例如,`cd /`进入根目录,`cd ...

    LINUX常用命令全集

    LINUX常用命令全集 LINUX常用命令全集 LINUX常用命令全集 LINUX常用命令全集 LINUX常用命令全集 LINUX常用命令全集 LINUX常用命令全集 LINUX常用命令全集 LINUX常用命令全集 LINUX常用命令全集 LINUX常用命令全集 ...

    最全Linux常用命令大全-linux常用命令全集

    "最全Linux常用命令大全-linux常用命令全集" 本文档对 Linux 中最常用的命令进行了详细的总结和说明,涵盖了文件和目录管理、磁盘空间管理等方面的命令。 文件和目录管理命令 1. `pwd` 命令:显示当前目录 `pwd`...

    Linux常用命令详解.pdf

    ### Linux常用命令详解知识点 #### 一、命令格式与通配符 - **命令格式**: - **命令**:指定要执行的操作。 - **选项**:改变命令的行为方式,通常以`-`开头,多个选项可以用空格或直接连接的方式给出。 - **...

    Linux常用命令教学视频

    04.1.1 Linux常用命令-文件处理命令-命令格式与目录处理命令ls.mp4 04.1.2 Linux常用命令-文件处理命令-目录处理命令.mp4 04.1.3 Linux常用命令-文件处理命令-文件处理命令.mp4 04.1.4 Linux常用命令-文件处理...

    最新-Linux常用命令大全-非常实用

    Linux 常用命令大全 Linux 操作系统是一个功能强大且灵活的操作系统,拥有众多实用的命令来帮助用户管理和维护系统。下面是 Linux 中一些常用的命令,旨在帮助用户快速掌握 Linux 操作系统。 TTY 控制台终端 在 ...

    Linux常用命令汇总

    Linux常用命令汇总中,首先涉及到的是检查Java开发工具包(JDK)是否已安装以及版本信息。使用命令`java –version`和`javac –version`可以实现该功能。`java –version`用于查看Java运行环境的版本,而`javac –...

    LINUX常用命令语言

    LINUX 常用命令语言总结 LINUX 操作系统提供了大量的命令语言,以下是常用的命令语言概述: 1. 远程桌面连接命令:mstsc mstsc 是一种远程桌面连接命令,可以连接到另一台计算机,并在远程桌面上进行操作。 2. ...

    Linux常用命令.xls

    Linux常用命令.xls Linux常用命令.xls Linux常用命令.xls Linux常用命令.xls Linux常用命令.xls Linux常用命令.xls Linux常用命令.xls Linux常用命令.xls Linux常用命令.xls Linux常用命令.xls Linux常用命令.xls ...

    Linux常用命令.md

    linux常用命令md文件

    Linux常用命令大全

    Linux常用命令全集.CHM Linux vi命令大全.txt liunx命令大全.txt liunx 下如何用命令行设置网络?.txt 请问怎么设置DNS的命令?.txt Red Hat Linux下配置Tomcat+JSP+Apache服务器的步骤.txt Linux 下 Apache 与 ...

    Linux 常用命令大全

    linux常用命令大全; linux常用命令大全; linux常用命令大全; linux常用命令大全; linux常用命令大全; linux常用命令大全; linux常用命令大全; linux常用命令大全; linux常用命令大全; linux常用命令大全; ...

    linux常用命令大全 ppt

    linux常用命令大全 ppt linux常用命令大全 ppt linux常用命令大全 ppt linux常用命令大全 ppt

    Linux常用命令及实用命令万字总结.doc

    "Linux常用命令及实用命令万字总结" 本文档旨在总结Linux系统中常用的命令和实用命令,涵盖了基本的文件管理、目录操作、文件查询、系统管理等方面的命令。 1. ls命令 ls命令是Linux系统中最常用的命令之一,用于...

    常用linux常用命令大全.zip

    linux常用命令大全常用linux常用命令大全.常用linux常用命令大全.常用linux常用命令大全.常用linux常用命令大全.常用linux常用命令大全.常用linux常用命令大全.常用linux常用命令大全.常用linux常用命令大全.常用...

    Linux常用命令全集.zip

    本资料"Linux常用命令全集.zip"包含了丰富的Linux命令知识,旨在帮助用户深入理解并应用这些命令。CHM文档是一种常见的Windows帮助文件格式,它将HTML页面集合在一个文件中,方便用户查阅。 以下是一些主要的Linux...

    Linux常用命令大全Linux常用命令深入理解Linux内核鸟哥的Linux私房菜Linux命令学习资料(12个).zip

    Linux常用命令大全Linux常用命令深入理解Linux内核鸟哥的Linux私房菜Linux命令学习资料(12个): Linux命令大全(Linuxidc.com修改版).chm Linux命令学习.chm Linux基础命令教程(豪华版).chm LINUX安全加固手册.doc ...

Global site tag (gtag.js) - Google Analytics