Linux常用基础命令下(grep,history,du,date,通配符,alias,rm,mv,cp)

grep  工具 查找文本内容   用途:输出包含指定字符的行

          格式  grep  [选项]   '查找字符串'       目标文件 

[root@guowei ~]# cat sed.txt 
MacBook-Pro:tmp maxincai$ cat test.txt
my cat's name is betty
This is your dog
my dog's name is frank
This is your fish
my fish's name is george
This is your goat
my goat's name is adam

[root@guowei ~]# grep T  sed.txt             #查看包含T字符的行,其中也可以写成  grep 'T'
This is your dog
This is your fish
This is your goat
[root@guowei ~]# grep -i  T  sed.txt         #-i  不区分大小写
MacBook-Pro:tmp maxincai$ cat test.txt
my cat's name is betty
This is your dog
This is your fish
This is your goat
my goat's name is adam

[root@guowei ~]# grep -v This sed.txt        # -v 取反  也就是查看不包含This字符的行
MacBook-Pro:tmp maxincai$ cat test.txt
my cat's name is betty
my dog's name is frank
my fish's name is george
my goat's name is adam


[root@guowei ~]# grep ^Mac  sed.txt          #查看以Mac开头的行  ^word 以某个字符开头
MacBook-Pro:tmp maxincai$ cat test.txt

[root@guowei ~]# grep ge$  sed.txt           #查看以ge结尾的行   word$ 以某个字符结尾
my fish's name is george

[root@guowei ~]# cat zhushi.txt 





#  shan you mu xi mu you zhi 
xin yue jun xi jun bu zhi 

[root@guowei ~]# grep ^$  zhushi.txt         #匹配空行







[root@guowei ~]# grep ^#   zhushi.txt        #匹配注释行,shell默认的#为注释
#  shan you mu xi mu you zhi 

[root@guowei ~]# grep  -v ^$   zhushi.txt | grep -v ^#     #匹配不是空行也不是注释的行
xin yue jun xi jun bu zhi 

history  历史命令 管理/调用曾经执行过的命令

[root@guowei ~]# history                        #列出曾经执行过的命令
    1  yum repolist all
    2  yum list all
...
  240  vim love.sh 
  241  ls
  242  history 


[root@guowei ~]# !241                          #执行历史命令中的第241条命令  
ls
1611con          hell.sh               love1.sh  share    zhushi.txt  视频  下载
anaconda-ks.cfg  initial-setup-ks.cfg  love.sh   test     公共        图片  音乐
c-language       log-20190802.tar.gz   sed.txt   windows  模板        文档  桌面

[root@guowei ~]# !vim                          #执行最近一次以vim开头的命令
vim love.sh 

[root@guowei ~]# vim  /etc/profile 
...
 44 
 45 HOSTNAME=`/usr/bin/hostname 2>/dev/null`
 46 HISTSIZE=1000                                 #修改记录的最大条数
...

[root@guowei ~]# history -c                       #清空历史命令
[root@guowei ~]# history 
    1  history 

du  统计文件占用的空间    du  [选项]   目录或者文件

[root@guowei ~]# du love.sh                     #统计love.sh所占用的空间大小
8	love.sh
[root@guowei ~]# du -s love.sh                  #只统计每个参数所占用的空间大小
8	love.sh
[root@guowei ~]# du -sh love.sh                 #提供易读容量单位(k,M等)
8.0K	love.sh

date   查看/调整系统日期时间

[root@guowei ~]# date
2019年 08月 06日 星期二 11:07:48 CST
[root@guowei ~]# date +%F 
2019-08-06
[root@guowei ~]# date +%R
11:08
[root@guowei ~]# date +"%Y-%m-%d %H:%M:%S"             #%Y%m%d"  间隔字符可以随意
2019-08-06 11:09:00
[root@guowei ~]# date +"%Y%m%d %H%M%S"
20190806 110915
[root@guowei ~]# date +"%Y/%m/%d %H-%M-%S"
2019/08/06 11-09-38

[root@guowei ~]# date -s"2019-8-6"                     #可以设置时间和日期
2019年 08月 06日 星期二 00:00:00 CSTCMOS
[root@guowei ~]# clock -w                              #将时间写入硬件中

 通配符  针对不确定的文档名称,以特殊字符表示   *  任意多个字符   ? 单个字符

[a-z]:多个字符或连续范围中的一个,若无则忽略(识别[0-9])

{a,min,xy}:多组不同的字符串,全匹配

[root@wei ~]# ls /dev/tty{2[0-9],30}                 #列出dev设备中,tty20至tty30的设备
/dev/tty20  /dev/tty26
/dev/tty21  /dev/tty27
/dev/tty22  /dev/tty28
/dev/tty23  /dev/tty29
/dev/tty24  /dev/tty30
/dev/tty25
[root@wei ~]# ls  /dev/tty{2?,30}
/dev/tty20  /dev/tty26
/dev/tty21  /dev/tty27
/dev/tty22  /dev/tty28
/dev/tty23  /dev/tty29
/dev/tty24  /dev/tty30
/dev/tty25

alias  别名  简化复杂的命令 

alias  [别名名称]           查看已设置的别名

alias  别名名称='实际执行的命令行'         定义新的别名

unalias     [别名名称]       取消已设置的别名

[root@wei ~]# alias 
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
...

[root@wei ~]# hn
bash: hn: 未找到命令...
[root@wei ~]# alias  hn='hostname'
[root@wei ~]# hn 
wei
[root@wei ~]# unalias  hn
[root@wei ~]# hn
bash: hn: 未找到命令...

 为真机设置永久的别名       /root/.bashrc 

rm 删除   rm——remove

格式:rm [选项]...   文件或目录

-r 、-f :递归删除(含目录)、强制删除 

注意:rm -rf  慎用

mv  移动/重命名   mv ——move

格式:mv  原文件...    目标路径 

重命名:路径不变的移动

[root@wei ~]# mv love1.sh    test
[root@wei ~]# ls test/
a  love1.sh

cp  复制  cp——copy 

格式:cp [选项]...  源文件...    目标路径

-r  递归 ,复制目录时必须有此选项 

  复制时重名文档 在本次操作中,临时取消别名

  复制支持两个以上参数,永远把最后一个参数作为目标,其他参数全部作为源

  复制的时候,可以重新命名,目标路径下文档的名字

[root@wei ~]# cp love.sh   love2.sh
[root@wei ~]# ls  
1611con               love2.sh  zhushi.txt  下载
anaconda-ks.cfg       love.sh   公共        音乐

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值