1环境变量PATH
1 环境变量
Linux 的变量可分为两类:环境变量和本地变量
环境变量,或者称为全局变量,存在与所有的shell 中,在你登陆系统的时候就已经有了相应的系统定义的环境变量了。Linux 的环境变量具有继承性,即子shell 会继承父shell 的环境变量。\
本地变量,当前shell 中的变量,很显然本地变量中肯定包含环境变量。Linux 的本地变量的非环境变量不具备继承性。
小案例如下:
1 2 3 4 5 | 1、[root@chy chenhaiying] # echo $PATH (echo=显示,打印出。$符表示后面跟的是变量) /usr/local/sbin : /usr/local/bin : /usr/sbin : /usr/bin : /root/bin \ 2、[root@chy ~] # PATH=$PATH:/tmp/ (增加变量,临时) [root@chy ~] # vi /etc/profile (要想永久使用在这个配置文件里加入想要增加的变量) |
2 CP 命令
1 2 3 4 5 6 7 | 1、 cp = copy 2、 cp -a source destination ( cp -a 常用 ) 3、 cp -i (若目标文件存在,覆盖时会提示是否覆盖 常用) 4、 cp -r 复制目录时注意需要加/ 5、 cp -p (复制时连文件的属性一起复制,备份时常用) 6、tree !$上条命令的最后一个参数 |
小试验:
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@chy tmp] # cp /root/1.txt . 拷贝文件到本地后面要加点. [root@chy ~] # cp -a /etc/passwd/ /tmp/chypasswd (复制时属性与权限不会改变) [root@chy ~] # cp -r /tmp/chylinux/ /tmp/chy1/ 拷贝目录需要加/ [root@chy ~] # cp -r /tmp/chylinux/ /tmp/chy1/ (拷贝目录时当目标目录存在是会将源目录放在目标目录下去) [root@chy ~] # tree !$ tree /tmp/chy1/ /tmp/chy1/ ├── 1.txt ├── 2.txt └── chylinux ├── 1.txt └── 2.txt 5 directories, 0 files |
3 mv 命令
1 2 3 4 5 6 7 8 9 10 11 12 | [root@chy ~] # mv 1.txt chy.txt (在一个目录下mv是更改名字) [root@chy ~] # mv /root/chy/ /tmp/chy/ (将目录移动到另一个目录下, 如果没有目录则是改名字后在移动,如果有同样的目录,将原目录移动到目标目录下) [root@chy ~] # mv /root/1.txt /root/2.txt /root/3.txt /tmp/ (移动一串目录) [root@chy ~] # mv -v *.txt /tmp/ (mv -v 打印移动的信息)"a.txt" -> "/tmp/a.txt" "c.txt" -> "/tmp/c.txt" "d.txt" -> "/tmp/d.txt" mv -uv *.txt /tmp/ ( mv -u 当源文件比目标文件新时就可以更新) [root@chy ~] # /usr/bin/mv -bv *.txt /tmp/ (mv -bv 是备份的意思—) "a.txt" -> "/tmp/a.txt" (备份: "/tmp/a.txt~" ) "b.txt" -> "/tmp/b.txt" (备份: "/tmp/b.txt~" ) "c.txt" -> "/tmp/c.txt" (备份: "/tmp/c.txt~" ) |
4、文档查看cat_more_less_head_tail
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [root@chy tmp] # cat chy.txt 查看文件 [root@chy tmp] # tac passwd (倒叙查看,常用) [root@chy ~] # cat -A 3.txt 111$ 222$ (-A:显示不可打印字符,行尾显示“$”;) [root@chy tmp] # cat -n passwd(cat -n 显示行号) 1 root:x:0:0:root: /root : /bin/bash 2 bin:x:1:1:bin: /bin : /sbin/nologin 3 daemon:x:2:2:daemon: /sbin : /sbin/nologin [root@chy tmp] # more passwd (一屏一屏的看 回车往下看 ctrl+b 上屏看) [root@chy tmp] # less passwd( 支持方向键查看,ctrl+b 上看,ctrl+f 向下 退出 /后加想查的可以高亮显示,按n向下会寻找是否在有查看的内容,N向上查看是否有查看的内容) ?区别是与/放向不同 G定位行尾 g定位行首 [root@chy tmp] # head -n 2 passwd 查看前两行 [root@chy tmp] # tail -n 2 passwd (查看后两行) [root@chy tmp] # tail -f passwd (查看动态的文件,看日志用的比较多) |
5 文件或目录权限chmod
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@chy ~] # ls -l 查看式列的权限 总用量 12 -rw-------. 1 root root 1695 5月 26 03:22 anaconda-ks.cfg -rw-r--r-- 1 root root 0 6月 7 06:01 a.tbt rwx代表的意思是r=可读 w=可写 x=可执行 从第二位开始每三个分开分三段,第一段属于所属主,第二段分为所属组,第三段分其它 [root@chy ~] # r=4 w=2 x=1 权限也可用数字表示 [root@chy ~] # chmod =change mode 更改权限 [root@chy ~] # mkdir 123 新创建的文件查看权限后发现后面有点,这个点是受制与selinux的 ,当selinux关闭后在创建时就不会有点。 [root@chy ~] # ls -l [root@chy ~] # chmod -R 744 chy chmod -R 批量的创建权限,会将目录及以下的子目录都给相同的权限。 [root@chy ~] # chmod u=rw,g=r,o=r chy (另一种更改权限的方法) [root@chy ~] # chmod a+x chy (a+x {a-x} 将所有者,所属组,其它人都增加{减少}x的权限。同理可得u,g,o都可增加或减少权限) |
6 更改所有者和所属组chown
[root@chy ~]# change owner 更改所有者
[root@chy ~]# chown chy chy 更改chy的所有者
[root@chy ~]# chgrp =change group 更改所属组)
[root@chy ~]# chown chy:chy chy 更改所有者与所属组
[root@chy ~]# chown -R chy:chy /tmp/ (-R递归的意思。就是这个目录下的所有者与所属组都有相同的权限)
7 umask
1 2 3 4 | [root@chy ~] # umask 0022 [root@chy ~] # umask 目录算发=(rwxrwxrwx - rwx-w--w-)=---r-xr-x(用777-去umask权限等于应有的权限,目录必须有执行权限) [root@chy ~] # umask 文件算法=(rw-rw-rw - ----w-r--)=rw-r--r--(用666减去umask权限等于应有的文件权限) |
8 隐藏权限lsattr_chattr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@chy ~] # chattr +i 1.txt 设置一个权限的隐藏权限。(设置了隐藏文件后,不能删除,不能修改,不能移动,但是可以copy,copy过去后没有i权限) [root@chy ~] # lsattr 2.txt 查看权限是否有隐藏权限。 [root@chy ~] # chattr -i 1.txt (减去i权限) [root@chy ~] # chattr +a 1.txt (追加后,也可 touch 这个文件,但不能删除,不能移动可以copy但是copy过去后没有i权限) [root@chy ~] # chattr -a 1.txt [root@chy ~] # lsattr -R /tmp (查看 /tmp 所有的) [root@chy ~] # lsattr -d /tmp (-d查看文件的本身) [root@chy ~] # lsattr -a /tmp (-a会列出隐藏文件) chattr选项解释:i:不得任意更动文件或目录。 a:让文件或目录仅供附加用途(让某个文件只能往里面追加数据,但不能删除) |