sort,grep,cut,whereis,locate,which.find,wc常用命令的常用形式
来源:互联网 发布:java poi是什么 编辑:程序博客网 时间:2024/05/01 22:18
0 是标准输入,1 是标准输出,2是错误输出
例如
[root@localhost daixiangzi]# ls
code
[root@localhost daixiangzi]# ls code code1 1>right.log 2>err.log #表示把错误的信息2 输入到了 err.log文件中,正确信息1输入到right.log中
[root@localhost daixiangzi]# ls
code err.log right.log
[root@localhost daixiangzi]# cat err.log
ls: 无法访问code1: 没有那个文件或目录
[root@localhost daixiangzi]# cat right.log
code:
正确输出和错误输出一起输入到一个文件 &> all.log 另外一种形式是> all.log 2>&1
输出重定向符号>(会丢失原来文件所有内容)
输出追加>>(不该变原有内容)
输入重定向< 例如: cat < /etc/passwd 这行命令等同于 cat /etc/passwd
一般输入重定向用的很少
/dev/null 俗称系统黑洞,有点回收站的意思,但是丢进去的东西不可恢复
/dev/zero 零发射器,可以产生任意大小的文件。例如 dd if=/dev/zero of=aaa.log bs=1(1份) count=1M(大小)
wc统计命令 wc -l 文件(显示文件多少行)
wc -w (多少个单词)
wc -c (多少个字符)
grep过滤命令
grep ‘root’ /etc/passwd (过滤含有 root的一行显示)
grep ‘^root’ /etc/passwd (过滤以root开头的一行显示)
grep 'root$' /etc/passwd (过滤以root结尾的一行显示)
grep -n 显示过滤的行号
grep -c (count)显示总共有多少行符合条件
grep -v 'root‘ /etc/passwd 显示没有root的行(取反)
grep -i ‘root’ /etc/passwd 显示含有root的一行忽略大小写(ignore)
tr替换或者字符的删除
例如 tr 'a' 'A' < /etc/passwd
把a替换成A
范围替换tr 'a-z' 'A-Z' < /etc/passwd 将小写换大写
注意它是1对1单个替换
例如 tr 'abc' 'A‘ < /etc/passwd 是将 a字母b字母c字母都替换成A,并不是将abc整体替换成A
sort 排序输出,默认是根据首字母来排序的
sort -t(指定分隔符) -k(指定第几列排序)
例如: sort -t: -k 3 /etc/passswd 是以:为分割符,用第三列进行排序
sort -r 表示倒序或者是逆序排列
cut裁剪 -d(指定分隔符) -f (指定显示的某些列数)
例如 cut -d: -f 1,3,7 /etc/passswd 表示以:为分割符,只显示第1,,3,7列
xargs 作用:将参数列表转换成小块分段传递
例如
[root@localhost daixiangzi]# cut -d: -f1 passwd
root
bin
daemon
adm
sshd
tcpdump
daixiangzi
xfs
[root@localhost daixiangzi]# cut -d: -f1 passwd |mkdir
mkdir: 缺少操作数
请尝试执行"mkdir --help"来获取更多信息。
[root@localhost daixiangzi]# cut -d: -f1 passwd |xargs mkdir
[root@localhost daixiangzi]# ls
adm all.log code daixiangzi passwd root tcpdump
alla.log bin daemon err.log right.log sshd xfs
[root@localhost daixiangzi]#
which 是linux系统内置命令
例如查找一个 命令位置
[root@localhost daixiangzi]# which ls
alias ls='ls --color=auto'
/bin/ls
whereis 也可以查找一个命令位置
查找一个命令的源头就是从$PATH变量的路径中查找的当然若要添加变量在path路径中
可以这么写PATH=$PATH:/路径
locate 查找一个文件,依赖的是updatedb这个数据库
当然这个库并不是实时更新,对于新创建的文件,重启或者直接执行updatedb更新,然后才能查找到
find /目录 -name "passwd” 在/目录下查找名字为passwd的文件
find /目录 -type d(f表示文件,d表示目录,p是管道类型的,s套间字文件,c字符,b块文件,l链接文件等等)按照文件类型查找
find /目录 -size 根据大小查找 1M 1K +1M(大于1m,) -1M(小于1M)
find /目录 -user root ...根据文件所属者来查找
find /目录 -group root .....根据文件所属组查找
如果想找到的内容不用管道的形式输出出来可以用下面这样一种
例如 find / -name "root" passwd -exec ls -l { } \;
当然也可以删除,只需要稍微改一下
find / -name "root" passwd -exec rm -rf { } \;
如果需要删除的时候提示直接将 exec改成ok 就行了
find / -name "root" passwd -ok rm -rf { } \;
- sort,grep,cut,whereis,locate,which.find,wc常用命令的常用形式
- linux常用命令(locate,whereis,which,find,grep)
- find locate which whereis grep 命令
- Linux :grep find locate whereis which
- linux常用命令locate,which,whereis,grep
- Linux常用命令002之搜索命令locate、whereis、which、find、grep
- Linux常用命令002之搜索命令locate、whereis、which、find、grep
- find, locate, whereis, which
- which, whereis, locate, find
- which whereis locate find
- whereis、locate、find、which的区别
- which whereis locate find的区别
- Linux的find、locate、whereis、which、type
- which,whereis,locate,find,type的区别
- 五个查找命令:grep、find、locate、whereis、which
- Linux 搜索命令(locate/find/whereis/which/grep)
- linux命令:文件搜索(locate、whereis、which、find、grep)
- find、grep,which、whereis
- 开始了
- BZOJ 2809 [Apio2012]dispatching
- 数据库基础知识
- IntellIj 在SSH框架下做Junit测试单元
- OkHttp 3.x框架简要分析
- sort,grep,cut,whereis,locate,which.find,wc常用命令的常用形式
- 算法学习-4
- IO流_输出指定目录下指定后缀名的文件名称案例
- 大数据开发工程师岗位分析
- 鸿观特辑:潜流2017笔记
- 由自动装箱和拆箱引发我看Integer源码
- SSH框架搭建和整合(struts2、spring4、hibernate5)
- 第5章 深入理解Android输入系统(节选)
- 【设计模式】—-(8)装饰模式(结构型)