对 Linux 中级用户非常有用的 20 个命令(1)(4)
27. 命令: service
‘service‘命令控制服务的启动、停止和重启,它让你能够不重启整个系统就可以让配置生效以开启、停止或者重启某个服务。
在Ubuntu上启动apache2 server:
- root@tecmint:~# service apache2 start
- * Starting web server apache2
- apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
- httpd (pid 1285) already running [ OK ]
重启apache2 server:
- root@tecmint:~# service apache2 restart
- * Restarting web server apache2
- apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
- ... waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [ OK ]
停止apache2 server:
- root@tecmint:~# service apache2 stop
- * Stopping web server apache2
- apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
- ... waiting [ OK ]
注意:要想使用service命令,进程的脚本必须放在‘/etc/init.d‘,并且路径必须在指定的位置。
如果要运行“service apache2 start”实际上实在执行“service /etc/init.d/apache2 start”.
28. 命令: alias
alias是一个系统自建的shell命令,允许你为名字比较长的或者经常使用的命令指定别名。
我经常用‘ls -l‘命令,它有五个字符包括空格)。于是我为它创建了一个别名‘l'。
- root@tecmint:~# alias l='ls -l'
试试它是否能用:
- root@tecmint:~# l
- total 36
- drwxr-xr-x 3 tecmint tecmint 4096 May 10 11:14 Binary
- drwxr-xr-x 3 tecmint tecmint 4096 May 21 11:21 Desktop
- drwxr-xr-x 2 tecmint tecmint 4096 May 21 15:23 Documents
- drwxr-xr-x 8 tecmint tecmint 4096 May 20 14:56 Downloads
- drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Music
- drwxr-xr-x 2 tecmint tecmint 4096 May 20 16:17 Pictures
- drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Public
- drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Templates
- drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Videos
去掉’l'别名,要使用unalias命令:
- root@tecmint:~# unalias l
再试试:
- root@tecmint:~# l
- bash: l: command not found
开个玩笑,把一个重要命令的别名指定为另一个重要命令:
- alias cd='ls -l' (set alias of ls -l to cd)
- alias su='pwd' (set alias of pwd to su)
- ....
- (You can create your own)
- ....
想想多么有趣,现在如果你的朋友敲入‘cd'命令,当他看到的是目录文件列表而不是改变目录;当他试图用’su‘命令时,他会进入当前目录。你可以随后去掉别名,向他解释以上情况。
评论暂时关闭