五周第四次课(1月11日) 8.6 管道符和作业控制 8.7/shell变量 8.8 shell变量 8.9 环境变量配置文件...

五周第四次课(1月11日)
8.6 管道符和作业控制
8.7/shell变量
8.8 shell变量
8.9 环境变量配置文件
扩展
bashrc和bash_profile的区别 http://ask.apelearn.com/question/7719

简易审计系统: http://www.68idc.cn/help/server/linux/2014042190951.html

关于PROMPT_COMMAND环境变量的含义 http://www.linuxnote.org/prompt_command-environment-variables.html


env命令:
用于显示系统中已存在的环境变量,以及在定义的环境中执行指令。该命令只使用"-"作为参数选项时,隐藏了选项"-i"的功能。若没有设置任何选项和参数时,则直接显示当前的环境变量。

如果使用env命令在新环境中执行指令时,会因为没有定义环境变量"PATH"而提示错误信息"such file or directory"。此时,用户可以重新定义一个新的"PATH"或者使用绝对路径。

语法
env(选项)(参数)
选项
-i:开始一个新的空的环境;
-u<变量名>:从当前环境中删除指定的变量。
参数
变量定义:定义在新的环境中变量,定义多个变量定义用空格隔开。格式为“变量名=值”;
指定:指定要执行的指令和参数。
实例
[root@localhost ~]# env
hostname=LinServ-1
TERM=linux
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=192.168.2.111 2705 22
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:
mail=/var/spool/mail/root
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
INPUTRC=/etc/inputrc
pwd=/root
LANG=zh_CN.UTF-8
SHLVL=1
HOME=/root
logname=root
SSH_CONNECTION=192.168.2.111 2705 192.168.2.2 22
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env

 

 

 

 

 

 

 

 

 

 

 

 

Connecting to 192.168.183.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Wed Jan 10 23:08:05 2018
[root@localhost ~]# ls
234 anaconda-ks.cfg.1 新建文本文档_(2).txt
[root@localhost ~]# ls |wc -l
3
[root@localhost ~]# find ./ -type f
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./.bash_history
./.ssh/.suthorized_keyx.swp
./.ssh/.suthorized_keyx.swo
./.ssh/.suthorized_keyx.swn
./.ssh/authorized_keys
./.ssh/suthorized_keyx
./.ssh/known_hosts
./.ssh/id_rsa
./.ssh/id_rsa.pub
./anaconda-ks.cfg.1
./234/adxxx
./新建文本文档_(2).txt
./.viminfo
[root@localhost ~]# find ./ -type f |wc -l
18
[root@localhost ~]# vim 新建文本文档_\(2\).txt

[1]+ 已停止 vim 新建文本文档_\(2\).txt
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 1.5G 37G 4% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.6M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sdb 20G 33M 20G 1% /mnt
/dev/sda1 497M 124M 373M 25% /boot
tmpfs 407M 0 407M 0% /run/user/0
[root@localhost ~]# w
21:23:44 up 35 min, 1 user, load average: 0.00, 0.01, 0.03
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.183.1 20:49 0.00s 0.11s 0.00s w
[root@localhost ~]# fg
vim 新建文本文档_\(2\).txt

[1]+ 已停止 vim 新建文本文档_\(2\).txt
[root@localhost ~]# fg
vim 新建文本文档_\(2\).txt

[1]+ 已停止 vim 新建文本文档_\(2\).txt
[root@localhost ~]# vim aa.txt

[2]+ 已停止 vim aa.txt
[root@localhost ~]# jods
-bash: jods: 未找到命令
[root@localhost ~]# jobs
[1]- 已停止 vim 新建文本文档_\(2\).txt
[2]+ 已停止 vim aa.txt
[root@localhost ~]# fg2
-bash: fg2: 未找到命令
[root@localhost ~]# fg 2
vim aa.txt
[root@localhost ~]# vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 3823284 876 165956 0 0 13 1 21 27 0 0 100 0 0
0 0 0 3823144 876 165988 0 0 0 0 61 87 0 0 100 0 0
0 0 0 3823144 876 165988 0 0 0 0 58 95 0 0 100
[root@localhost ~]# fgprocs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 3819456 876 166380 0 0 0 0 85 100 0 0 100 0 0

vmstat 1
0 0 0 3819456 876 166380 0 0 0 0 49 59 0 0 100 0 0
0 0 0 3819456 876 166380 0 0 0 0 29 42 0 0 100 0 0
0 0 0 3819456 876 166380 0 0 0 0 32 41 0 0 100 0 0
0 0 0 3819456 876 166380 0 0 0 0 30 44 0 0 100 0 0
^C
[root@localhost ~]# jobs
[root@localhost ~]# env
XDG_SESSION_ID=1
HOSTNAME=localhost.localdomain
TERM=xterm
SHELL=/bin/bash
HISTSIZE=10000
SSH_CLIENT=192.168.183.1 51247 22
SSH_TTY=/dev/pts/0
USER=root
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
LANG=zh_CN.UTF-8
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
SSH_CONNECTION=192.168.183.1 51247 192.168.183.128 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/usr/bin/env
[root@localhost ~]# set
BASH=/bin/bash
BASHOPTS=checkwinsize:cmdhist:expand_aliases:extglob:extquote:force_fignore:histappend:interactive_comments:login_shell:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_COMPLETION_COMPAT_DIR=/etc/bash_completion.d
BASH_LINENO=()
BASH_REMATCH=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="2" [2]="46" [3]="1" [4]="release" [5]="x86_64-redhat-linux-gnu")
BASH_VERSION='4.2.46(1)-release'
COLUMNS=92
COMP_WORDBREAKS=$' \t\n"\'><=;|&(:'
DIRSTACK=()
EUID=0
GROUPS=()
HISTCONTROL=ignoredups
HISTFILE=/root/.bash_history
HISTFILESIZE=10000
HISTSIZE=10000
HISTTIMEFORMAT='%Y/%m/%d %H:%M:%S'
HOME=/root
HOSTNAME=localhost.localdomain
HOSTTYPE=x86_64
ID=0
IFS=$' \t\n'
LANG=zh_CN.UTF-8
LESSOPEN='||/usr/bin/lesspipe.sh %s'
LINES=41
MAILCHECK=60
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu

fi
}
dequote ()
{
eval printf %s "$1" 2> /dev/null
}
quote ()
{
local quoted=${1//\'/\'\\\'\'};
printf "'%s'" "$quoted"
}
quote_readline ()
{
local quoted;
_quote_readline_by_ref "$1" ret;
printf %s "$ret"
}
[root@localhost ~]# set |grep 111
a=111
[root@localhost ~]# set |less
[root@localhost ~]# a1=2
[root@localhost ~]# echo $a1
2
[root@localhost ~]# a_1=3
[root@localhost ~]# echo $a_1
3
[root@localhost ~]# _a1=4
[root@localhost ~]# echo $_a1
4
[root@localhost ~]# 1aa=2
-bash: 1aa=2: 未找到命令
[root@localhost ~]# 2aa=3
-bash: 2aa=3: 未找到命令
[root@localhost ~]# a=a b c
-bash: b: 未找到命令
[root@localhost ~]# echo $a
111
[root@localhost ~]# a='a b c'
[root@localhost ~]# echo $a
a b c
[root@localhost ~]# a=“a b c“
-bash: b: 未找到命令
[root@localhost ~]# a=“a b c”
-bash: b: 未找到命令
[root@localhost ~]# a=“a b c”
-bash: b: 未找到命令
[root@localhost ~]# a="a b c"
[root@localhost ~]# echo $a
a b c
[root@localhost ~]# a="a$bc"
[root@localhost ~]# echo $a
a
[root@localhost ~]# a='a$bc'
[root@localhost ~]# echo $a
a$bc
[root@localhost ~]# a=1
[root@localhost ~]# b=2
[root@localhost ~]# echo $a$b
12
[root@localhost ~]# a='a$bc'
[root@localhost ~]# echo $c

[root@localhost ~]# echo $a
a$bc
[root@localhost ~]# echo $a$b
a$bc2
[root@localhost ~]# c="a$bc"
[root@localhost ~]# echo $c
a
[root@localhost ~]# c="a$b"c
[root@localhost ~]# echo $c
a2c
[root@localhost ~]# c='a$b'c
[root@localhost ~]# echo $c
a$bc
[root@localhost ~]# c=a"b"c
[root@localhost ~]# echo $c
abc
[root@localhost ~]# w
22:26:11 up 1:37, 2 users, load average: 0.00, 0.01, 0.04
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.183.1 20:49 3.00s 0.17s 0.00s w
root pts/1 192.168.183.1 22:25 18.00s 0.00s 0.00s -bash
[root@localhost ~]# echo ¥SSH_TTY
¥SSH_TTY
[root@localhost ~]# echo $SSH_TTY
/dev/pts/0
[root@localhost ~]# aming=liunx
[root@localhost ~]# echo #aming

[root@localhost ~]# echo #aming

[root@localhost ~]# aming=liunx
[root@localhost ~]# echo #aming

[root@localhost ~]# vim .bash_profile
[root@localhost ~]# ..bash_profile ^C
[root@localhost ~]# vim .bashrc
[root@localhost ~]# vim /etc/bashrc
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# echo $PS1
[\u@\h \W]\$
[root@localhost network-scripts]# PS1='[\u@\h \W]\$
[root@localhost network-scripts]#ls
ifcfg-ens33 ifdown-ipv6 ifdown-tunnel ifup-isdn ifup-TeamPort
ifcfg-lo ifdown-isdn ifup ifup-plip ifup-tunnel
ifcfg-有线连接_1 ifdown-post ifup-aliases ifup-plusb ifup-wireless
ifdown ifdown-ppp ifup-bnep ifup-post init.ipv6-global
ifdown-bnep ifdown-routes ifup-eth ifup-ppp network-functions
ifdown-eth ifdown-sit ifup-ib ifup-routes network-functions-ipv6
ifdown-ib ifdown-Team ifup-ippp ifup-sit
ifdown-ippp ifdown-TeamPort ifup-ipv6 ifup-Team
[root@localhost network-scripts]#
PS1='[\u@\h \w]\$
'
[root@localhost /etc/sysconfig/network-scripts]#
cd
[root@localhost ~]#
PS1='/
> ^C
[root@localhost ~]#
PS1='\[\033[01;32m\u@\h\[/003[00m\]:[\033[01;36m\]\2\[\033[00m]\\$'
root@localhost/003[00m:[\2]$
root@localhost/003[00m:[\2]$

 

五周第四次课(1月11日) 8.6 管道符和作业控制 8.7/shell变量 8.8 shell变量 8.9 环境变量配置文件..._第1张图片

五周第四次课(1月11日) 8.6 管道符和作业控制 8.7/shell变量 8.8 shell变量 8.9 环境变量配置文件..._第2张图片

五周第四次课(1月11日) 8.6 管道符和作业控制 8.7/shell变量 8.8 shell变量 8.9 环境变量配置文件..._第3张图片

 

转载于:https://www.cnblogs.com/yikebaicai/p/8271067.html

你可能感兴趣的:(五周第四次课(1月11日) 8.6 管道符和作业控制 8.7/shell变量 8.8 shell变量 8.9 环境变量配置文件...)