Linux档案与目录管理

pwd -P 显示绝对路径,而非link路径

mkidr -m 预设权限,忽略umask值,如

[root@localhost ~]# rm -rf test/
[root@localhost ~]# mkdir test -m 700
[root@localhost ~]# ll
总用量 8
-rw-------. 1 root root 1382 11月 13 20:14 anaconda-ks.cfg
-rw-r--r--. 1 root root 1433 11月 13 12:15 initial-setup-ks.cfg
drwx------. 2 root root    6 5月  13 16:58 test


-p递归创建,且指定预设权限,预设的权限只对最某一个目录生效

[root@localhost ~]# mkdir -pvm 500 test/test1/test2
mkdir: 已创建目录 "test"
mkdir: 已创建目录 "test/test1"
mkdir: 已创建目录 "test/test1/test2"
[root@localhost ~]# ll
总用量 8
-rw-------. 1 root root 1382 11月 13 20:14 anaconda-ks.cfg
-rw-r--r--. 1 root root 1433 11月 13 12:15 initial-setup-ks.cfg
drwxr-xr-x. 3 root root   18 5月  13 17:01 test
[root@localhost ~]# cd test/
[root@localhost test]# ll
总用量 0
drwxr-xr-x. 3 root root 18 5月  13 17:01 test1
[root@localhost test]# cd test1/
[root@localhost test1]# ll
总用量 0
dr-x------. 2 root root 6 5月  13 17:01 test2

ls: 参数

-a比-A多.和..

-d目录本身,不列目录内容

-f直接列出,不按字母等排序,速度快

-F附加数据结构,在某些无颜色显示的终端有用

-h更易读懂数据大小,humanreadable

-i列出inode号

-l长格式

-n把user,group信息转化为UID,GID

-r反向输出

-R递归

-S以文件档案大小排序

-t以时间排序

--color=never,always,auto颜色显示设置

--full-time完整时间

--time(atime,ctime,mtime)

cp:

-a 相当于-Pdr (其中P为大P)

-d 复制的如果是链接文件,那么仍然复制链接文件

-f强制,目标以存在且无法打开,则移除后在试一次

-i交互,如果目标存在,则询问,默认通过alias带有

-l复制为硬链接

-p小p连同属性一起复制,如果拷贝的是链接文件,则拷贝源文件,且inode不同,独立的两份文件

lrwxrwxrwx.  1 root      root        11 5月  13 17:56 file1 -> /root/file1
drwx------. 18 Gandefeng Gandefeng 4096 5月  13 18:03 Gandefeng
drwx------.  6 jerry     jerry     4096 5月  10 17:07 jerry
[root@localhost home]# cp -p file1 file2
[root@localhost home]# ll
总用量 12
lrwxrwxrwx.  1 root      root        11 5月  13 17:56 file1 -> /root/file1
-rw-r--r--.  1 root      root      1354 5月  13 18:00 file2
drwx------. 18 Gandefeng Gandefeng 4096 5月  13 18:03 Gandefeng
drwx------.  6 jerry     jerry     4096 5月  10 17:07 jerry
[root@localhost home]# 
[root@localhost home]# ll -i ./    ~/
./:
总用量 12
37326466 lrwxrwxrwx.  1 root      root        11 5月  13 17:56 file1 -> /root/file1
37326492 -rw-r--r--.  1 root      root      1354 5月  13 18:00 file2
71042883 drwx------. 18 Gandefeng Gandefeng 4096 5月  13 18:03 Gandefeng
71689916 drwx------.  6 jerry     jerry     4096 5月  10 17:07 jerry

/root/:
总用量 16
69135647 -rw-------. 1 root root 1382 11月 13 20:14 anaconda-ks.cfg
71836130 drwxr-xr-x. 2 root root   18 5月  13 17:48 directory1
71836120 -rw-r--r--. 1 root root 1354 5月  13 18:00 file1
71836127 -rw-r--r--. 1 root root    0 5月  13 17:40 file2
71836132 -rw-r--r--. 1 root root   18 5月  13 17:42 file3
71020069 -rw-r--r--. 1 root root 1433 11月 13 12:15 initial-setup-ks.cfg

-P大P,如果被复制的是链接文件,则拷贝链接文件,仍然指向被拷贝的链接文件指向的文件

[root@localhost home]# cp -P file1 file2
[root@localhost home]# ll -i
总用量 8
37326466 lrwxrwxrwx.  1 root      root        11 5月  13 17:56 file1 -> /root/file1
37326492 lrwxrwxrwx.  1 root      root        11 5月  13 18:08 file2 -> /root/file1
71042883 drwx------. 18 Gandefeng Gandefeng 4096 5月  13 18:03 Gandefeng
71689916 drwx------.  6 jerry     jerry     4096 5月  10 17:07 jerry

-r或-R递归复制

-s复制为符号链接,创建符号链接只能到符号链接最终所处的目录中才能创建

[root@localhost ~]# ls
anaconda-ks.cfg  directory1  file1  file2  file3  initial-setup-ks.cfg
[root@localhost ~]# cp -s file1 /home/
cp: "/home/file1":只能于当前目录中创建相对的符号链接
[root@localhost ~]# cd /home/
[root@localhost home]# cp -s /root/file1 ./
[root@localhost home]# ll
总用量 8
lrwxrwxrwx.  1 root      root        11 5月  13 17:56 file1 -> /root/file1
drwx------. 18 Gandefeng Gandefeng 4096 11月 13 14:34 Gandefeng
drwx------.  6 jerry     jerry     4096 5月  10 17:07 jerry

-u意为update,目标比源新才复制

-L和大P相反,和小p类似

cat: (tac逆显)

-A 相当于-vET

-b对非空白行显示行号,空白行不显示

-n空白行也显示行号

-E显示断行字符$

-T显示制表符号[tab]以^I显示出来

-v显示一些看不出来的特殊字符

nl:

-b指定行号显示的方式a表示无论是否为空,同样列出行号,类似cat -n,而t如果有空行则不现实空行行号,默认值

-n : ln行号在屏幕最左,rn行号在字段的最右显示,不加0,rz行号在字段的最右显示,加0

-w 行号占用位数

[root@localhost ~]# nl -b a -n rz -w 5 /etc/fstab 
00001    
00002    #
00003    # /etc/fstab
00004    # Created by anaconda on Sun Nov 13 12:08:01 2016
00005    #
00006    # Accessible filesystems, by reference, are maintained under '/dev/disk'
00007    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
00008    #
00009    UUID=728c3dfc-efde-4212-8bc9-fb4419e5f9a0 /                       xfs     defaults        1 1
00010    UUID=c434bbf0-040f-451c-9644-74d204cd01bf /boot                   xfs     defaults        1 2
00011    UUID=a6fafb81-3c1a-4e18-b65a-3da35a7f987e swap                    swap    defaults        0 0

权限: 文件的隐藏属性

chattr:

+,-,=增加,移除,设置-定

A 存取此档案时,访问时间atime不变

S 同步写入磁盘,一般是异步的,即有时候需要内存中将还未sync入磁盘的写入,加S则同步写入

a 只能增加数据,不能更改或者删除,只有root可设

c 将文件自动压缩,读取时解压缩

d 在dump时跳过

i 不能删除,改名,设置链接,更新,即完全固定文件,只有root可设置

s 删除时立即删除,无法恢复

u 和s相反

lsattr 查看chattr设置的属性 -a 列出隐藏属性,-d 对目录 -R递归

SUID SGID SBIT

SUID

1 只对二进制程序有效,不能设置在shell scripts上,对目录也无效

2 执行者对该程序有执行权限

3 本权限仅在执行程序过程中有效

4 执行者将有该程序拥有者的权限

SGI

1 对二进制程序有用,对目录也有用

2 程序执行者对该程序来说具有执行权限

3 执行过程中将获得该程序群组的权限

SBIT

1 只对目录有效

2 当用户对此目录具有wx权限时,该用户在此目录下建立的文件或者目录,中有自己和root可以删除

原文地址:https://www.cnblogs.com/gandefeng/p/6849935.html