学习Linux要知道的知识点总结

1 如何查看Linux的user和hostname?

(1)打开终端查看

终端左侧的root@zlkj:~$ ,前面的root为user - 用户名,后面的zlkj为hostname - 主机名。

(2)命令查看

user查看命令为whoami,hostname查看命令为hostname,如下所示:

root@zlkj:/home/zlkj# whoami 
root
root@zlkj:/home/zlkj# hostname
zlkj

2 Ubuntu为软件运行添加符号连接

例如为sublime_text添加符号连接,运行:

# ln -s ~/opt/sublime_text /bin/sublime

将主目录下的opt文件夹下面的sublime_text可执行文件在/bin文件夹中创建符号连接,命名为sublime,这样在任何目录下运行sublime即可打开sublime_text可执行文件。


3 Ubuntu 设置开机启动脚本

方法一:将脚本添加到文件/etc/rc.local

/etc/rc.local脚本是一个ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令,该文件需要root权限才能修改。该脚本具体格式如下:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
 
exit 0

方法二:将脚本文件放在/etc/init.d/目录下

要注意的是,/etc/init.d/目录下的脚本的内容是有格式要求的,不能随便写。

(1)新建个脚本文件new_service.sh

#!/bin/bash
# command content
 
exit 0

(2)设置权限

sudo chmod 755 new_service.sh

(3)把脚本放置到启动目录下

sudo mv new_service.sh /etc/init.d/

(4)将脚本添加到启动脚本

cd /etc/init.d/
sudo update-rc.d new_service.sh defaults 90

移除Ubuntu开机脚本

sudo update-rc.d -f new_service.sh remove

参考:

Ubuntu14.04设置开机启动脚本(转)


posted @ 2019-07-04 11:54  fengMisaka  阅读(583)  评论(0编辑  收藏  举报