1,记录命令历史,
history能查找最近一千条的linux命令,这些命令存储在用户的家目录的./bash_history文件夹中,可以通过!n,表示执行历史的第n条命令,如下图的!369表示执行历史中的第369条命令,用户也可以直接使用上下键查看执行过的命令。
[root@master hadoop]# history
1 ls
2 pwd
3 shutdown now
4 su /home/
5 ls
...........................
367 ll
368 cd /home/hadoop/
369 ll
370 history
[root@master hadoop]#
[root@master hadoop]# !369
ll
total 680712
-rw-rw-r--. 1 hadoop ke 424555111 Sep 11 15:37 hadoop-2.8.1.tar.gz
-rw-rw-r--. 1 hadoop ke 173271626 Sep 11 15:37 jdk-8u45-linux-x64.gz
drwxrwxr-x. 3 hadoop hadoop 4096 Sep 17 16:07 mongodb-linux-x86_64-amazon-3.6.2
-rw-rw-r--. 1 hadoop ke 99202414 Sep 11 15:21 mongodb-linux-x86_64-amazon-3.6.2.gz
-rw-rw-r--. 1 hadoop hadoop 37 Sep 13 22:34 words
[root@master hadoop]#
2,使用help命令获取内部命令帮助
首先我们可以通过type判断命令为内部命令还是外部命令,如果是内部命令可以通过help帮助命令查看,
[root@master hadoop]# rm --help
Usage: rm [OPTION]... FILE...
Remove (unlink) the FILE(s).
-f, --force ignore nonexistent files, never prompt
-i prompt before every removal
-I prompt once before removing more than three files, or
when removing recursively. Less intrusive than -i,
while still giving protection against most mistakes
--interactive[=WHEN] prompt according to WHEN: never, once (-I), or
always (-i). Without WHEN, prompt always
--one-file-system when removing a hierarchy recursively, skip any
directory that is on a file system different from
that of the corresponding command line argument
--no-preserve-root do not treat `/' specially
--preserve-root do not remove `/' (default)
-r, -R, --recursive remove directories and their contents recursively
像这样就是可以查看rm命令的可用参数有哪些,当你忘记命令的规则时就可以查看帮助啦。
3,ps -ef | grep 命令
ps命令将某个进程显示出来
grep命令是查找
大概就是查找某个进程,可以通过grep过滤到你需要的进程上去。
[root@master hadoop]# ps -ef | grep /usr/libexec/
root 1666 1 0 20:51 ? 00:00:00 /usr/libexec/postfix/master
root 1764 1729 0 20:51 ? 00:00:00 /usr/libexec/gdm-simple-slave --display-id /org/gnome/DisplayManager/Display1 --force-active-vt
root 1859 1 0 20:51 ? 00:00:00 /usr/libexec/devkit-power-daemon
gdm 1864 1 0 20:51 ? 00:00:00 /usr/libexec/gconfd-2
gdm 1878 1856 0 20:51 ? 00:00:00 /usr/libexec/at-spi-registryd
gdm 1882 1 0 20:51 ? 00:00:00 /usr/libexec/gnome-settings-daemon --gconf-prefix=/apps/gdm/simple-greeter/settings-manager-plugins
gdm 1884 1 0 20:51 ? 00:00:00 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=12
gdm 1892 1 0 20:51 ? 00:00:00 /usr/libexec/gvfsd
gdm 1895 1856 0 20:51 ? 00:00:00 /usr/libexec/gdm-simple-greeter
gdm 1898 1856 0 20:51 ? 00:00:00 /usr/libexec/polkit-gnome-authentication-agent-1
root 1907 1 0 20:51 ? 00:00:00 /usr/libexec/polkit-1/polkitd
rtkit 1911 1 0 20:51 ? 00:00:00 /usr/libexec/rtkit-daemon
root 2342 2016 0 23:29 pts/0 00:00:00 grep /usr/libexec/
[root@master hadoop]#
杀死一个进程 kill -9 pid
杀死匹配的所有进程kill -9 $(pgrp -f /usr/libexec/)
[root@master hadoop]# pgrep -f /usr/libexec/
1666
1764
1859
1864
1878
1882
1884
1892
1895
1898
1907
1911
查看所有在 /usr/libexec/的进程号。