---
title: "文件系统"
author: "elihe2011"
date: "2013-08-18T21:26:39Z"
tags: []
categories: ["操作系统"]
slug: "untitled"
draft: false
lastmod: "2013-08-18T21:26:39Z"
id: 1891634
url: "https://elihe2011.iteye.com/blog/1891634"
---

文件系统:

ext2/ext3: Linux适用的文件系统。ext3比ext2多了日志记录

physical volume(LVM): 用来弹性调整文件系统容量的一种机制，可以动态控制文件系统大小而不改变原有文件数据

software RAID: 磁盘阵列

swap: 虚拟内存，大小是物理内存的1.5~2倍，物理内存达到4G，可以不使用

vfat: 同时被Linux和Windows系统支持的文件系统

 

 

SELinux: Security Enhanced Linux，Linux系统访问控制(Access Control)的细节设置，控制程序对系统文件访问权限限制

 

 

RAID: /dev/md\[0-15]

 

 

关机/重启系统

数据同步：sync

关机指令：shutdown

重启关机: reboot, halt, poweroff

 

shutdown -h now

shutdown -h 20:10

shutdown -h +10  # shutdown after 10 minutes

shutdown -r now  # reboot immediately

shutdown -r +30 'The system will reboot'

shutdown -k now 'The system will reboot'  # frighten you

 

 

Linux run level:

init 0: shutdown

init 3: command line mode

init 5: x-window

init 6: reboot

 

175

 

ext2/ext3文件系统，文件名长度最大255个字符，完整文件名(带路径)长度最大4096个字符

 

文件属性和权限控制

chgrp \[-R] new\_group FILE

chown \[-R] new\_owner FILE

chown \[-R] new\_owner:new\_group FILE

chmod \[-R] u=rwx,g=rx,o=r FILE

 

 

Linux文件类型

1\. 常规文件(regular file)

纯文本(ASCII)

二进制文件(binary)

数据文件(data)，某些程序运行过程中读取的特定格式文件。/var/log/wtmp 可使用last读出

2\. 目录 \[d]

3\. 连接(link) \[l]

4\. 设备(device)

块设备(block)，可随机读写 ls -l /dev/sda \[b]

字符设备(character)，串口设备，一次性读取，鼠标键盘  \[c]

5\. 数据接口文件(sockets)，网络上数据传输使用。 /var/run \[s]

6\. 数据传输文件(FIFO,pipe)，\[p]

 

 

FSH: Filesystem Hierarchy Standard

 

 

/bin   开机及单人模式下使用的命令

/boot  开机配置文件, vmlinuz, grub

/usr   unix software resource

/usr/bin  软件命令

/dev

/etc   配置文件

       /etc/init.d/  所有服务的预设启动，系统开机时执行的脚本

  /etc/xinetd.d/  super daemon管理的各项服务的配置文件目录

  /etc/X11  X Window

/opt   第三方软件

/sbin  供管理员执行的开机及单人模式下使用的命令

 

/lost+found   ext2/ext3文件系统格式下的目录，当系统发生错误时，将一些遗失片段存入该目录

/proc   虚拟文件系统(virtual filesystem)，该目录下的数据都在内存中，不占硬盘空间

/sys    同上

 

 

特殊目录标示：

.     当前目录

..    上级目录

\-     前一个工作目录

~         家目录

~account  用户account的家目录

 

 

nl: number lines of files

-b, --body-numbering=STYLE    use STYLE for numbering body lines

STYLE is one of:

a      number all lines

t      number only nonempty lines

n      number no lines

 

eg:

nl -b a myfile &lt;=&gt; cat -n myfile

nl -b t myfile &lt;=&gt; cat -b myfile

 

-n, --number-format=FORMAT    insert line numbers according to FORMAT

FORMAT is one of:

ln     left justified, no leading zeros

rn     right justified, no leading zeros

rz     right justified, leading zeros

 

 

-w, --number-width=NUMBER     use NUMBER columns for line numbers

 

eg:

nl -b a -n rz -w 3 /etc/issue

001

002     Welcome to SUSE Linux Enterprise Server 10 SP1 (x86\_64) - Kernel \\r (\\l).

003

004

 

 

文件修改时间：

modification time (mtime): 文件内容变更时改变

status time (ctime): 文件状态(即权限)变更时改变

access time (atime): 被读取后变更

 

 

touch

-a     change only the access time

-c, --no-create      do not create any files

-d, --date=STRING    parse STRING and use it instead of current time

-m     change only the modification time

-r, --reference=FILE    use this file's times instead of current time

-t STAMP    use \[\[CC]YY]MMDDhhmm\[.ss] instead of current time

 

eg:

touch -d "3 days ago" myfile     # -rw-r----- 1 bmpscp sms 307891 2013-06-17 14:27 myfile

 

touch -t 0709101347 myfile       # -rw-r----- 1 bmpscp sms 307891 2007-09-10 13:47 myfile

 

chattr    change file attributes on a Linux second extended file system

lsattr    list file attributes on a Linux second extended file system

 

 

\# append only

chattr +a myfile 

 

\# immutable

chattr +i myfile

 

 

SUID、SGID、SBIT

\# ls -ld /tmp ; ls -l /usr/bin/passwd

drwxrwxrwt 66 root root 12288 Jun 20 14:55 /tmp

-rwsr-xr-x 1 root shadow 79336 May  4  2007 /usr/bin/passwd

 

Set UID:

1\. 只对二进制执行文件有效

2\. 执行者具有执行权限x

3\. 本执行权限仅在运行时(run-time)有效

4\. 执行者拥有该程序所有者(owner)的权限

 

Set GID:

1\. 只对二进制执行文件有效

2\. 执行者具有执行权限x

3\. 执行者拥有该程序属组(group)的权限

 

Sticky Bit:

1\. 只对目录有效

2\. 当用户对于此目录具有w,x权限，也有了写入权限

3\. 当用户在该目录下创建文件或目录，只有所有者或者root用户可删除

 

\# add SUID

chmod 4755 myfile

chmod u+s myfile

 

\# add GUID

chmod 2755 myfile

chmod g+s myfile

 

\# add sticky bit

chmod 1755 myfile

chmod o+t myfile

 

软链接和硬链接

硬连接指向的是节点(inode), 而软连接指向的是路径(path)

 

硬链接文件有两个限制:

1、目录不能创建硬链接 

2、只有在同一文件系统中的文件才能创建链接

 

对硬链接文件进行读写和删除操作时候，结果和软链接相同。但如果删除硬链接文件的源文件，硬链接文件仍然存在，且保留了原有的内容。此时，系统将该文件当成一个普通文件。