hellopasswd
管道符
[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暂停一个任务
[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]把任务调到前台
[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命令却没有显示任何东西,可以通过查看进程找到后台运行
[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
修改于171116