Linux+CentOS7
Linux文件操作
- 目录操作
1 | pwd #查看当前目录路径 |
1 | mkdir -p example/example2/example3 #创建出路径上的所有目录,不带-p参数则在当前目录创建 |
1 | cp -rf example example2 #将example目录复制到example2下,如若example2不存在则新建example2,内容与example相同。 |
- 文件操作
1 | tar -cvf example.tar example1,example2,example3 #将三个目录归档到example.tar |
- 软链接
1 | ln -s example example2 #创建example的快捷方式,命名为example2 |
Linux用户操作
1 | su #进入当前用户的root模式 |
1 | groupadd group #创建组 |
Linux文件权限
- 查看权限
ls -l
可以查看文件的权限。如下
drwxrwxr-x. 3 theo theo 17 3月 3 18:52 file -rw-rw-r--. 1 theo theo 11 3月 3 20:18 text.txt
d
:文件夹
r
:可读;w
:可写;x
:可执行;-
:没有相应性质分区概念:
-|---|---|---
对应着不同区所拥有的不同权限,-|自己|同组|陌生人
。权限也可在文件>属性>权限
查看
- 修改权限
1 | chmod o+w text.txt #作用对象 +/- 权限 |
o
:其他人;u
:用户本人;a
:所有用户。w/r/x
对应不同权限。
如果省去o/u/a
,默认作用对象为本用户和本组。
Linux脚本
- 环境变量
1 | export JAVA_HOME=/opt/jdk1.8 #设置环境变量,当时该设置的环境变量只在该终端上有效。退出终端将消失 |
用户环境变量
1 | gedit ~/.bash_profile #文本编辑器打开环境变量设置,在末行添加export JAVA_HOME=/opt/jdk1.8,只对本用户有效。 |
系统环境变量
1 | gedit etc/profile.d/group.sh #先在profile.d下编写脚本group.sh,实现export ...,这种方法对所有用户有效 |
PATH环境变量(root权限)
执行脚本时一般使用./example.sh
,使用example.sh
却提示找不到命令。这是因为后者将会去PATH寻找该脚本,找不到就无法执行。
1 | gedit etc/profile.d/group.sh |
先在profile.d下编写脚本group.sh。实现export PATH=$PATH:/home/theo
,这样就会添加一条脚本搜索路径/home/theo/example.sh
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!