linux中单引号和双引号的区别
- 定义变量
- [root@mihaoyu128 ~]# name="mhy"
-
- 变量取值 $
- [root@mihaoyu128 ~]# echo $name
- mhy
-
- 双引号""字符串中,$符会取出变量的值
- [root@mihaoyu128 ~]# echo "hello, $name good luck."
- hello, mhy good luck.
-
- 单引号''也表示字符串,单引号中$不会进行转译
- [root@mihaoyu128 ~]# echo 'hello, $name good luck.'
- hello, $name good luck.
-
- 用反单引号``包含的内容,系统会默认先执行``里面的指令,将结果进行输出
- [root@mihaoyu128 ~]# echo `ls /opt/soft/`
- mysql shell
-
- 双引号""中包含反单引号``
- [root@mihaoyu128 ~]# echo "hello `date`"
- hello Tue Oct 26 10:07:21 CST 2021
方法一(借助xargs,在查找出来的文件中 grep 过滤出字符串):
- [xiaoming@ data]$find -name '*.h' | wc -l
- 57
-
- [xiaoming@ data]$find -name '*.h' | xargs grep -R -n haha | wc -l
- 120
-
- [xiaoming@ data]$find -name '*.h' | xargs grep -R -n haha123 | wc -l
- 100
方法二:
想获取mysqld的进程状态,使用下面的命令
Linux命令 写道
root@simen-laptop:/tmp# pidof mysqld
1395
root@simen-laptop:/tmp# top -n 1 -p 1395
top - 17:20:03 up 9:14, 3 users, load average: 0.89, 0.40, 0.26
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 34.7%us, 12.4%sy, 0.7%ni, 51.0%id, 0.9%wa, 0.1%hi, 0.2%si, 0.0%st
Mem: 4060300k total, 3985748k used, 74552k free, 334216k buffers
Swap: 7815580k total, 31412k used, 7784168k free, 801048k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1395 mysql 20 0 239m 10m 4148 S 0 0.3 0:15.35 mysqld
其实可以合并到一起
Linux命令 写道
root@simen-laptop:/tmp# top -p `pidof mysqld`,`pidof firefox`
top - 17:23:47 up 9:17, 3 users, load average: 0.21, 0.31, 0.26
Tasks: 2 total, 0 running, 2 sleeping, 0 stopped, 0 zombie
Cpu(s): 34.7%us, 12.4%sy, 0.7%ni, 50.9%id, 0.9%wa, 0.1%hi, 0.2%si, 0.0%st
Mem: 4060300k total, 3978188k used, 82112k free, 331988k buffers
Swap: 7815580k total, 31412k used, 7784168k free, 798820k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3489 root 20 0 1138m 221m 42m S 6 5.6 50:08.32 firefox
1395 mysql 20 0 239m 10m 4148 S 0 0.3 0:15.42 mysqld
注意的是`pidof mysqld`,`pidof firefox`不是引号,而是“上分割符”,就是Esc下面的按键