文件权限与目录配置、文件及目录的操作

1、
身份类型:User、Group、Others
2、root下文件权限与属性: ls -al
例如:
-rw-r- -r- -. 1 root root 1879 5月 11 21:56 initial-setup-ks.cfg
这里写图片描述
(1)文件类型与权限:
这里写图片描述
文件类型:
[ d ]则是目录
[ - ]则是文件,例如上表档名为『initial-setup-ks.cfg』那一行;
[ l ]则表示为连结档(link file);
[ b ]则表示为装置文件里面的可供储存的接口设备(可随机存取装置);
[ c ]则表示为装置文件里面的串行端口设备,例如键盘、鼠标(一次性读取装置)。
(2)连接数:
每个文件都会将他的权限与属性记录到文件系统的 i-node 中。连接数就是有多少不同的档名连结到相同的一个 i-node.
(3)文件容量大小:单位 bytes
(4)修改时间:月 日 时:分
(5)文件名:如果文件名之前多一个 . 则代表这个文件为隐藏文件。
3、
(1)改变群组:
要改变的群组必须在/etc/gruop中存在。
chgrp users initial-setup-ks.cfg
chgrp testing initial-setup-ks.cfg //将users群组改为testing群组
(2)改变拥有者:
用户必须在/etc/passwd中有记录。
chown bin initial-setup-ks.cfg //拥有者变为bin
chown root:root initial-setup-ks.cfg //拥有者和群组变为root
(3)改变权限:
r: 4 w: 2 x:1
chmod 755 test.sh // -rwxr-xr-x
或者:
chmod u=rwx,g=rx,o=r test.sh // -rwxr-xr–
chmod a+w .bashrc //为所有用户增加写的权限
chmod a-w .bashrc //为所有用户去掉写的权限
4、绝对路径和相对路径:
./ : 当前目录
../ :上一级目录
cd :change directory
pwd:显示当前目录
pwd -P : 显示完整路径(尤其是链接文件夹)
5、
建立文件夹:
mkdir test //当前目录下建立文件夹
mkdir -p test1/test2/test3 //建立多层文件夹
mkdir -m 711 test2 //设置目录权限
删除文件夹:
rmdir test1
rmdir -p test1/test2/test3 //删除多级文件夹
rmdir 只能删除空目录
rm -r test //删除目录以及目录下的文件
6、设置系统环境变量:
在任何目录均可执行/root 底下的 ls,那么就将/root 加入 PATH 当中即可。
加入的方法:
PATH=”${PATH}:/root”
7、ls:
ls -al :列出所有文件及目录。
ls -al –full-time :显示完整的时间
8、复制、删除、移动
cp ~/.bashrc /tmp/bashrc //将.bashrc复制到tmp命名为bashrc
cp -a /var/log/wtmp wtmp_2 //将文件和文件属性一起复制
cp -r /etc/ /tmp //复制 /etc/ 这个目录下的所有内容到 /tmp 底下
cp -s bashrc bashrc_slink
cp -l bashrc bashrc_hlink //为bashrc建立链接
cp ~/.bashrc ~/.bash_history /tmp //将home目录的 .bashrc 及 .bash_history 复制到 /tmp 底下
rm text.txt //删除text.txt
rm -r /tmp/etc //删除多个文件及文件夹
mv bashrc mvtest //将某个文件移动到某个目录去
mv mvtest mvtest2 //将mvtest更名为 mvtest2
mv bashrc1 bashrc2 mvtest2 //将所有的数据移动到该目录
9、查看文件内容
文本文档:
cat /etc/issue
cat -n /etc/issue //显示行号,空白行也编号
cat -b /etc/issue //显示行号
tac /etc/issue //由最后一行到第一行反向在屏幕上显示出来
more /etc/man_db.conf //显示一部分内容,只能向后翻
less /etc/man_db.conf //可用pgup、pgdn翻页
head /etc/man_db.conf //默认显示10行
head -n 20 /etc/man_db.conf //显示20行
tail 类似head从后向前显示。
二进制文件以ascII形式展现
od -t c /usr/bin/passwd
10、umask: 要减去的权限
假设umask为:022 (减去group和other的w权限)
建立文件时:(-rw-rw-rw-) - (—–w–w-) ==> -rw-r–r–
建立目录时:(drwxrwxrwx) - (d—-w–w-) ==> drwxr-xr-x
11、chatter:设置隐藏属性
chattr 指令只能在Ext2/Ext3/Ext4 的 Linux 传统文件系统上面完整生效。
chattr +i attrtest //为attrtest设置i属性
chattr -i attrtest ///为attrtest去掉i属性
lsattr attrtest 显示隐藏属性
12、文件特殊权限:
SUID、SGID(s权限的位置不同)
-rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd
s权限:执行passwd的用户暂时有root权限
SUID 权限仅对二进制程序(binary program)有效
-rwx–s–x. 1 root slocate 40496 Jun 10 2014 /usr/bin/locate
SGID 对二进制程序有用
执行者在执行的过程中将会获得该程序群组的支持
SBIT:如果将 A 目录加上了 SBIT 的权限项目时, 则只能够针对自己建立的文件或目录进行删除/更名/移动等动作,而无法删除他人的文件
4 为 SUID
2 为 SGID
1 为 SBIT
添加s权限:
chmod 4755 test //-rwsr-xr-x
chmod 7666 test // -rwSrwSrwT
chmod g+s,o+t test //gruop +s other +s
chmod u=rwxs,go=x test
13、查看文件类型
file /usr/bin/passwd
14、查找文件:
which 预设是找 PATH 内所规范的目录
which ifconfig //显示ifconfig的目录
whereis ifconfig //查找若干目录
locate -l 5 passwd //显示5行,从数据库(/var/lib/mlocate/mlocate.db)中查找
find / -mtime 0 //列出根目录下0~24小时内变动的文件
这里写图片描述
find /var -mtime +4
find / -name passwd  //在根目录下找出passwd

猜你喜欢

转载自blog.csdn.net/misterfm/article/details/80450281
今日推荐