[root@localhost ~]# ls
111 123 1.txt 234 2.txt 2.txt.bak 3.txt anaconda-ks.cfg
[root@localhost ~]# ls | wc -l
8[root@localhost ~]# find ./ -type f
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./anaconda-ks.cfg
./.bash_history
./.viminfo
./1.txt
./2.txt
./3.txt
./2.txt.bak
[root@localhost ~]# find ./ -type f |wc -l 计算当前目录下,有多少个文件
12[root@localhost ~]# vim 1.txt
[1]+ 已停止 vim 1.txt
[root@localhost ~]# fg
vim 1.txt
[1]+ 已停止 vim 1.txt
[root@localhost ~]# jobs
[1]+ 已停止 vim 1.txt
[root@localhost ~]# vim 2.txt
[2]+ 已停止 vim 2.txt
[root@localhost ~]# jobs
[1]- 已停止 vim 1.txt
[2]+ 已停止 vim 2.txt
[root@localhost ~]# [root@localhost ~]# fg 1[root@localhost ~]# bg 1
[1]+ vim 1.txt &运行一条命令,可以将它丢到后台(前台)去运行 在结束任务的时候,必须是在前台才能结束——>(否则在后台是无法结束任务的)
[root@localhost ~]# sleep 1000
^Z
[1]+ 已停止 sleep 1000
[root@localhost ~]# jobs
[1]+ 已停止 sleep 1000
[root@localhost ~]# sleep 200
^Z
[2]+ 已停止 sleep 200
[root@localhost ~]# jobs
[1]- 已停止 sleep 1000
[2]+ 已停止 sleep 200
[root@localhost ~]# fg
sleep 200
^Z
[2]+ 已停止 sleep 200在调到前后台运行的时候,不指定id号,就是默认最后一条执行命令[root@localhost ~]# sleep 100 &
[3] 2239
[root@localhost ~]# jobs
[1] 运行中 sleep 100 &
[root@localhost ~]# 在打开另一终端,jobs命令,是查看不到执行当前终端的任务
但是在另一个终端,可以查看到进程ps aux |grep sleep
```
[root@localhost ~]# ps aux |grep sleep
root 2235 0.0 0.0 107892 624 pts/0 T 23:20 0:00 sleep 1000
root 2236 0.0 0.0 107892 620 pts/0 T 23:20 0:00 sleep 200
root 2264 0.0 0.0 112656 984 pts/1 R+ 23:31 0:00 grep --color=auto slee
[root@localhost ~]#
```[root@localhost ~]# a=111
[root@localhost ~]# echo $a
111
[root@localhost ~]# set |grep 111
_=111
a=111
[root@localhost ~]# [root@localhost ~]#
[root@localhost ~]# a1=3
[root@localhost ~]# echo $a1
3
[root@localhost ~]# a_1=2
[root@localhost ~]# echo $a_1
2
[root@localhost ~]# _a1=4
[root@localhost ~]# echo $_a1
4
[root@localhost ~]# 1aa=2 变量名首位不能为数字
-bash: 1aa=2: 未找到命令
[root@localhost ~]# [root@localhost ~]# a='a b c'
[root@localhost ~]# echo $a
a b c
[root@localhost ~]# a="a b c"
[root@localhost ~]# echo $a
a b c这里可以使用 单引号'' 或 双引号"",但使用 单引号 更加好用——>方便脱义[root@hf-01 ~]# a="a$bc" //会发现使用双引号,赋值变量得不到想要的结果
[root@hf-01 ~]# echo $a
a
[root@hf-01 ~]# a='a$bc' //使用单引号会发现正常赋值
[root@hf-01 ~]# echo $a
a$bc[root@hf-01 ~]# a=1
[root@hf-01 ~]# b=2
[root@hf-01 ~]# echo $a$b //变量$a=1,变量$b=2
12
[root@hf-01 ~]# a='a$bc'
[root@hf-01 ~]# echo $a$b //变量$a=a$bc,变量$b=2
a$bc2
[root@hf-01 ~]# c="a$bc"
[root@hf-01 ~]# echo $c //变量$bc为赋值,所以为空,最后输出的值为a
a
[root@hf-01 ~]# c="a$b"c
[root@hf-01 ~]# echo $c //变量$b=2,,所以输出为a2c
a2c以下例子中,$bc为整体,而我又没有给它赋值,所以为空当变量或表达式较为复杂的时候,变量叠加的时候,可以使用双引号将它们标记起来
[root@hf-01 ~]# w
05:34:28 up 4:05, 3 users, load average: 0.00, 0.01, 0.05
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
root tty1 01:29 4:04m 0.03s 0.03s -bash
root pts/0 01:30 4.00s 0.07s 0.03s w
root pts/1 05:34 5.00s 0.02s 0.02s -bash[root@hf-01 ~]# echo $SSH_TTY //当前是在/dev/pts/0下
/dev/pts/0- 在终端2下执行命令 echo $SSH_TTY[root@hf-01 ~]# echo $SSH_TTY
/dev/pts/1[root@hf-01 ~]# hanfeng=linux
[root@hf-01 ~]# echo $hanfeng
linux[root@hf-01 ~]# echo $hanfeng //会发现变量为 空
[root@hf-01 ~]# [root@hf-01 ~]# bash
[root@hf-01 ~]# [root@hf-01 ~]# pstree
systemd─┬─NetworkManager───3*[{NetworkManager}]
├─auditd───{auditd}
├─avahi-daemon───avahi-daemon
├─crond
├─dbus-daemon───{dbus-daemon}
├─firewalld───{firewalld}
├─iprdump
├─iprinit
├─iprupdate
├─login───bash
├─lvmetad
├─master─┬─pickup
│ └─qmgr
├─mysqld_safe───mysqld───20*[{mysqld}]
├─polkitd───5*[{polkitd}]
├─rsyslogd───2*[{rsyslogd}]
├─sshd───sshd─┬─bash───bash───pstree
│ └─bash
├─systemd-journal
├─systemd-logind
├─systemd-udevd
└─tuned───4*[{tuned}]
[root@hf-01 ~]# [root@hf-01 ~]# echo $hanfeng
[root@hf-01 ~]# 这是因为这个变量仅仅在上一个shell中[root@hf-01 ~]# exit
exit
[root@hf-01 ~]# pstree
systemd─┬─NetworkManager───3*[{NetworkManager}]
├─auditd───{auditd}
├─avahi-daemon───avahi-daemon
├─crond
├─dbus-daemon───{dbus-daemon}
├─firewalld───{firewalld}
├─iprdump
├─iprinit
├─iprupdate
├─login───bash
├─lvmetad
├─master─┬─pickup
│ └─qmgr
├─mysqld_safe───mysqld───20*[{mysqld}]
├─polkitd───5*[{polkitd}]
├─rsyslogd───2*[{rsyslogd}]
├─sshd───sshd─┬─bash───pstree
│ └─bash
├─systemd-journal
├─systemd-logind
├─systemd-udevd
└─tuned───4*[{tuned}]
[root@hf-01 ~]# 这时会看到缺少了一个bash,因为刚exit退出了一个bash[root@hf-01 ~]# echo $hanfeng
linux这种定义一个变量叫做非全局,或者叫做本地的变量(仅仅在你终端下生效)
[root@hf-01 ~]# export hanfeng=linux
[root@hf-01 ~]# echo $hanfeng
linux
[root@hf-01 ~]# bash
[root@hf-01 ~]# echo $hanfeng
linux
[root@hf-01 ~]# 全局环境变量,在终端1下,在打开shell之后,只要执行export 命令 ,在这下面所有的子shell 都会变量值,但在终端2下,变量依旧是不会生效
全局变量是向下的,在这个shell的基础上生成子shell,子子shell,子子子shell,而不会向上生效[root@hf-01 ~]# hanfeng=linux
[root@hf-01 ~]# echo $hanfeng
linux
[root@hf-01 ~]# unset hanfeng
[root@hf-01 ~]# echo $hanfeng
[root@hf-01 ~]# [root@hf-01 ~]# echo $PS1
[\u@\h \W]\$[root@hf-01 ~]# cd /etc/sysconfig/network-scripts/
[root@hf-01 network-scripts]# PS1='[\u@\h \w]\$'
[root@hf-01 /etc/sysconfig/network-scripts]#
[root@hf-01 ~]# cd 123/
[root@hf-01 ~/123]# cd /tmp/
[root@hf-01 /tmp]# 这是一个全局路径[root@hf-01 /tmp]# PS1='\u@\h \w\$'
root@hf-01 /tmp# root@hf-01 /tmp# PS1='<\u@\h \w> \$'
<root@hf-01 /tmp> # 普通用户是 $号,root用户是# 号PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '