0067-cp企业案例-alias-unalias企业实践及应用场景总结

 

1 rmdir 目录  删除空的目录

2 grep 过滤需要的内容

-v 排除

  例子

  grep -v oldboy test.txt

  grep 过滤

 

[root@lxx test]# grep -v oldboy test.txt 
test
liyao

不加v 就是过滤什么出什么

[root@lxx test]#  grep  oldboy test.txt   
oldboy
[root@lxx test]# 

 

过滤有li的

[root@lxx test]#  grep  li  test.txt       
liyao

 

 3 head  头 读取文件的前n行,默认是前10行 head -n 数字 文件 n可以省略

[root@lxx test]# head -2 test.txt 
test
liyao

 3 tail    尾  读取文件的后n行,默认是后10行 tail -n 数字 文件 n可以省略

[root@lxx test]# tail -1 test.txt 
oldboy

 

 

想要不提示 命令行前加反斜杠 或命令全路径 /bin/cy

[root@lxx mnt]#  touch /tmp/test.txt
[root@lxx mnt]# touch /mnt/test.txt
[root@lxx /]#  cp /mnt/test.txt  /tmp/
cp: overwrite `/tmp/test.txt'? 
//方式一
[root@lxx /]# \cp /mnt/test.txt  /tmp/  

//方式二 
[root@lxx /]# /bin/cp /mnt/test.txt  /tmp/  

原因

写cp 其实内部调用了 cp -i 系统自动起了别名

可以查看系统已经定义的别名有哪些

[root@lxx /]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

 

二 别名

 

设置别名防止误操作

alias  rm='echo this comand dose not use '

简化写很长的指令

[root@lxx /]# alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
[root@lxx /]# net
DEVICE=eth0
HWADDR=00:0c:29:94:d8:45
TYPE=Ethernet
UUID=35086bd5-129c-41f8-a1ad-dded666236fe
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
USERCTL=no
PEERDNS=yes
IPV6INIT=no
[root@lxx /]# 

 

这样设置和删除的指令都是临时的,如果想要永久,就需要存到文件中

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值