【例1】显示当前使用的shell
[root@centos7 ~]# echo ${SHELL} /bin/bash
【例2】显示当前系统使用的所有shell
[root@centos7 ~]# cat /etc/shells /bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
【例3】查看/etc/passwd文件最后1行内容
[root@centos7 ~]# tail -n 1 /etc/passwd linux:x:1004:1004::/home/linux:/bin/bash
【例4】type查看内部显示的结果
[root@centos7 ~]# type cd cd is a shell builtin
【例5】type查看外部命令显示的结果
[root@centos7 ~]# type top
top is /usr/bin/top
【例6】设置命令别名为bkmysql,实现拷贝/etc/my.cnf为/home/back/my.cnf.bak,设置后查看别名
[root@centos7 ~]# alias bkmysql='cp /etc/my.cnf /home/my.cnf.bak'
[root@centos7 ~]# alias
alias bkmysql='cp /etc/my.cnf /hoem/my.cnf.bak'
alias cman='man -M /usr//share/man/zh_CN'
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'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
【例7】把上例中别名设置写在配置文件里,永久生效。有两个文件可以写,~/.bashrc文件仅当对当前用 户,/etc/bashrc文件是对所有用户有效。
[root@Magedu ~]# echo "alias bkmysql='cp /etc/my.cnf /hoem/my.cnf.bak'" >>~/.bashrc
[root@Magedu ~]# tail -1 ~/.bashrc
alias bkmysql='cp /etc/my.cnf /hoem/my.cnf.bak'
二、在linux命令行执行命令
最新推荐文章于 2024-09-12 21:45:00 发布