Linux alias命令别名编写shell脚本以及find常用命令实例演示

1、定义一个对所有用户都生效的命令别名,例如:lftps='lftp 172.168.0.1/pub'

例:将mv修改命令别名为“123”

[[email protected] ~]# alias 
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
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'

Linux alias命令别名编写shell脚本以及find常用命令实例演示

[[email protected] ~]# alias mv="123"
[[email protected] ~]# alias 
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='123'
alias rm='rm -i'

Linux alias命令别名编写shell脚本以及find常用命令实例演示

2、显示/etc/passwd文件中不以/bin/bash结尾的行

[[email protected] ~]# grep -v '/bin/bash$' /etc/passwd

Linux alias命令别名编写shell脚本以及find常用命令实例演示

3、找出/etc/passwd文件中,包含二位数字或者三位数的行

[[email protected] ~]#  grep -o "\<[0-9]\{2,3\}\>" /etc/passwd

Linux alias命令别名编写shell脚本以及find常用命令实例演示

4、显示/proc/meminfo文件中以大或小写S开头的行;用三种方式实现

[[email protected] ~]#  grep "^[Ss]" /proc/meminfo

Linux alias命令别名编写shell脚本以及find常用命令实例演示

[[email protected] ~]#  grep -i "^s" /proc/meminfo

Linux alias命令别名编写shell脚本以及find常用命令实例演示

[[email protected] ~]# grep -E "^(S|s)" /proc/meminfo

Linux alias命令别名编写shell脚本以及find常用命令实例演示

5、使用echo输出一个绝对路径,使用egrep取出路径名,类型执行dirname /etc/passwd的结果。

[[email protected] ~]# echo /etc/passwd | grep -o "^/.*/"

Linux alias命令别名编写shell脚本以及find常用命令实例演示

6、找出ifconfig中的IP地址,要求结果只显示IP地址

[[email protected] ~]# ifconfig | grep inet | cut -d ' ' -f10 |head -1

Linux alias命令别名编写shell脚本以及find常用命令实例演示

7、vim定制自动缩进四个字符

[[email protected] ~]# vim a.sh

[[email protected] ~]# chmod +x a.sh 

[[email protected] ~]# cat a.sh 
set ai
set ts=4

Linux alias命令别名编写shell脚本以及find常用命令实例演示

8、 编写脚本,实现自动添加三个用户,并计算这三个用户的UID之和

[[email protected] ~]# cat san.sh 
#!/bin/bash
useradd test1 >&/dev/null
useradd test2 >&/dev/null
useradd test3 >&/dev/null
a=`id test1 -u`
b=`id test2 -u`
c=`id test3 -u`
echo $a+$b+$c|bc

Linux alias命令别名编写shell脚本以及find常用命令实例演示

[[email protected] ~]# sh san.sh 
3024

Linux alias命令别名编写shell脚本以及find常用命令实例演示

9、find用法以及常用用法的实例演示

[[email protected] /]# find / -name grub2.cfg
/etc/grub2.cfg

Linux alias命令别名编写shell脚本以及find常用命令实例演示