sort 按序重排文本并送显示
sort [参数]
-r
-t 设置栏位间的间隔符号
-k 对第几栏进行排序
diff 报告文本差异内容
diff file1 file2
grep//查找文件里符合条件字符的命令,显示文件中匹配关键字的行
查看当前目录以及子目录下文件里面含有realm的字符
#明确要求搜索子目录:grep -r
grep -r realm ./*
$ grep "被查找的字符串" 文件名
例子:在当前目录里第一级文件夹中寻找包含指定字符串的.in文件
grep"thermcontact" */*.in
从文件内容查找与正则表达式匹配的行:
$grep –E “正则表达式” 文件名
Matcher Selection
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, seebelow). (-E is specified by
POSIX.)
查找时不区分大小写:
$ grep–i "被查找的字符串" 文件名
-i, --ignore-case
Ignore case distinctions in boththe PATTERN and the input files. (-i isspecified by POSIX.)
查找匹配的行数:
$ grep-c "被查找的字符串" 文件名
-c, --count
Suppress normal output; insteadprint a count of matching lines for each input file. With the
-v, --invert-match option (see below), countnon-matching lines. (-c is specified byPOSIX.)
从文件内容查找不匹配指定字符串的行:
$ grep–v "被查找的字符串" 文件名
-v, --invert-match
Invert the sense of matching, toselect non-matching lines. (-v isspecified by POSIX.)
alias grep='grep --color=auto'
grep [选项] [查找模式] [文件名]
grep-[acinv] '搜索内容串' filename
eg:
-n 显示查找字符的行号
[root@node201~]# grep -n 'httpd' passwd
51:httpd:!!:517:518::/var/chroot:/usr/local/jail/bin/jail
grep命令去除配置文件中的注释行和空行
grep-v ^$去除空行
grep-v ^#去除注释行
egrep去除文件中指定的行:
[root@node1~]# egrep -v "#|\*|--|^$" test.bak
[root@localhost shell_scripts]# cat /etc/ssh/sshd_config | grep -v ^# |grep -v ^$
[root@localhost shell_scripts]# cat /etc/ssh/sshd_config | grep -vE"^#|^$"
[^oldboy]:表示非oldboy的行或字符
^$表示空行
让过虑的内容显示颜色:
#cat/etc/profile
PATH=/shell_scripts/:$PATH
aliasgrep='grep --color=auto'
#source/etc/profile
[root@localhostoldboy]# grep --color=auto www test.txt
http://www.rscpass.com
[root@localhost shell_scripts]# ls -Fl | grep /$
[root@localhost shell_scripts]# ls -pl | grep /$ #$表示以...结尾
查看当前目录下所有的一级目录:
[root@localhost shell_scripts]# ls -al | grep ^d
^意思是以...开头的意思
[root@localhost shell_scripts]# ls -al | grep ^-
-v 显示没有被搜索字符串的行
[root@node201~]# grep -nv 'httpd' passwd
51:httpd:!!:517:518::/var/chroot:/usr/local/jail/bin/jail
搜索字符合集
[root@node201~]# grep -n 'qus[er]r*' passwd
45:quser1:$1$zexIs1iB$M9ewVqKOTJL5ehr7WGKyT/:512:515::/home/quser1:/bin/bash
46:quser:!!:513:515::/home/quser:/bin/bash
47:quser2:$1$SqEj4FBp$XxFlO/u6gSpkJBMWtj33x.:514:515::/home/quser2:/bin/bash
[root@node201~]# grep -n 'qus[^234]r*' passwd //除234之外的
45:quser1:$1$zexIs1iB$M9ewVqKOTJL5ehr7WGKyT/:512:515::/home/quser1:/bin/bash
46:quser:!!:513:515::/home/quser:/bin/bash
47:quser2:$1$SqEj4FBp$XxFlO/u6gSpkJBMWtj33x.:514:515::/home/quser2:/bin/bash
[a-z]:表示26个小写字母
[A-Z]:表示26个大写字母
[0-9]:表示0~9数字
[a-zA-Z0-9]:表示所有数字与英文字符
[root@node203rsc]# grep '1' -n good
1:12 3
[root@node203rsc]# grep '8' -v good
12 3
456
grep 'test file' kkk //在文件kkk中查找test file
grep 'test' d*//显示所有以d开头的文件中包含test的行
grep 'test' aa bb cc //显示在aa bb cc 文件中匹配test的行
grep '[a-z]\{5\}' aa //在文件aa中显示所有包含至少有5个连续小写字符的字符串的行
ls -l | grep '^a' //显示以a开头的行
Find//列出文件系统内符合条件的文件的命令
find[路径] [选项] [-print]
选项说明:
-name:按照文件名来查找文件
-perm:按照文件权限来查找文件
-user:按照文件属性来查找文件
-group:按照文件所属的组来查找文件
-cmin n:在过去n分钟内被修改过的文件
-ctime n:在过去n天内被修改过的文件
-size n:大小为n的文件
-type:查找某一类型的文件
eg:
find /boot -name grub.conf -print
find / -name "*.conf" -print
find . -ctime -20 //列出当前目录及其子目录下所有最近20min内更新过的文件
whereis //查找指定文件,命令和手册页位置的命令
whereis[选项] [文件名]
OPTIONS
-b Search only for binaries.//查找文件的二进制部分
-m Search only for manual sections.//查找文件的手册部分
-s Search only for sources.//查找文件的源部分
-u Search for unusual entries. A file is said to be unusual if it
does not have one entry of each requested type. Thus
‘whereis -m -u *’ asks for those files in the current direc-
tory which have no documentation.//查找不寻常的文件
-B Change or otherwise limit the places where whereis searches for
binaries.
-M Change or otherwise limit theplaces where whereis searches for
manual sections.
-S Change or otherwise limit the places where whereis searches for
sources.
-f Terminate the last directory listand signals the start of file
names, and must be used when anyof the -B, -M, or -S options
are used.
eg:
whereis -b mv
wherreis -m mv
find./ -type d # 查看当前目录所有的目录
#find ./ -type d ! -name "."
[root@localhost~]# find ./ -type d ! -name "." -prune #只查当前目录,忽略遍历整个目录树
[root@localhost~]# find ./ -maxdepth 1 -type d ! -name "."
File//查询文件类型的命令
file[选项][文件名]
-v, --version
Print the version of the programand exit.
-z, --uncompress
Try to look inside compressedfiles.
-L, --dereference
option causes symlinks to befollowed, as the like-named option
in ls(1) (on systems thatsupport symbolic links). This is the
default if the environmentvariable POSIXLY_CORRECT is defined.
-f, --files-from namefile
Read the names of the files to be examined from namefile (one
per line) before theargument list. Either namefile or at
least one filename argument must be present; totest the stan-
dard input, use ‘‘-’’ as afilename argument.
whatis //查询命令功能的命令
whatis[命令]
eg:
whatis ls
which//显示可执行命令路径的命令
which[命令]
eg:
which ls