【CentOS 7笔记33】,管道符和做业控制#

shallow丿ove测试


管道符

[root@localhost ~]# cat 1.txt
	ls: cannot access 111.txt: No such file or directory
	111:
	ls: cannot access 111.txt: No such file or directory
	111:
	ls: cannot access 111.txt: No such file or directory
	111:
[root@localhost ~]# cat 1.txt | wc -l
	6
[root@localhost ~]# cat 1.txt | grep '111'
	ls: cannot access 111.txt: No such file or directory
	111:
	ls: cannot access 111.txt: No such file or directory
	111:
	ls: cannot access 111.txt: No such file or directory
	111:

做业控制

crrk+z暂停一个任务code

[root@localhost ~]# sleep 1000
	^Z
	[1]+  Stopped                 sleep 1000

jobs查看后台的任务进程

[root@localhost ~]# jobs
	[1]+  Stopped                 sleep 1000
[root@localhost ~]# sleep 2000
	^Z
	[2]+  Stopped                 sleep 2000
[root@localhost ~]# jobs
	[1]-  Stopped                 sleep 1000
	[2]+  Stopped                 sleep 2000

bg[id]把任务调到后台后台

[root@localhost ~]# bg 2
	[2]+ sleep 2000 &
[root@localhost ~]# jobs
	[1]+  Stopped                 sleep 1000
	[2]-  Running                 sleep 2000 &

fg[id]把任务调到前台file

[root@localhost ~]# fg
	sleep 1000
	^Z
	[1]+  Stopped                 sleep 1000
[root@localhost ~]# jobs
	[1]+  Stopped                 sleep 1000
	[2]-  Running                 sleep 2000 &
[root@localhost ~]# fg 2
	sleep 2000
	^Z
	[2]+  Stopped                 sleep 2000
[root@localhost ~]# jobs
	[1]-  Stopped                 sleep 1000
	[2]+  Stopped                 sleep 2000

命令后面加&直接丢到后台终端

[root@localhost ~]# bg 1
	[1]- sleep 1000 &
[root@localhost ~]# jobs
	[1]-  Running                 sleep 1000 &
	[2]+  Stopped                 sleep 2000
[root@localhost ~]# fg
	sleep 2000
	^C
[root@localhost ~]# fg
	sleep 1000
	^C
[root@localhost ~]# jobs
[root@localhost ~]# sleep 100 &
	[1] 3785
[root@localhost ~]# jobs
	[1]+  Running                 sleep 100 &

打开另外一个终端测试,jobs命令却没有显示任何东西,能够经过查看进程找到后台运行grep

[root@localhost ~]# jobs
[root@localhost ~]# ps aux | grep sleep
	root       3785  0.0  0.0 107908   612 pts/0    S    14:55   0:00 sleep 100
	root       3787  0.0  0.0 112656   976 pts/0    S+   14:56   0:00 grep --color=auto sleep
相关文章
相关标签/搜索