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常用命令详解 #### 一、文件管理 1. **ls**:此命令用于列出当前目录中的文件和子目录。通过使用不同的选项,可以改变其输出格式。 - `-l`:使用长格式列表输出,包括文件权限、拥有者、组、大小等详细...
以下是一些关于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 中最常用的命令进行了详细的总结和说明,涵盖了文件和目录管理、磁盘空间管理等方面的命令。 文件和目录管理命令 1. `pwd` 命令:显示当前目录 `pwd`...
Linux常用命令手册大全.zip 部分内容: Linux常用命令手册 NO 分类 PS1 命令名 用法及参数 功能注解 对应章节 1 文件管理 # ls ls -a 列出当前目录下的所有文件,包括以.头的隐含文件 文件管理 # ls ls -l或ll 列...
### Linux常用命令详解知识点 #### 一、命令格式与通配符 - **命令格式**: - **命令**:指定要执行的操作。 - **选项**:改变命令的行为方式,通常以`-`开头,多个选项可以用空格或直接连接的方式给出。 - **...