• Linux目录说明

目录

 

/bin

存放二进制可执行文件(ls,cat,mkdir等),常用命令一般都在这里。

/etc

存放系统管理和配置文件

/home

存放所有用户文件的根目录,是用户主目录的基点,比如用户user的主目录就是/home/user,可以用~user表示

 

/usr

用于存放系统应用程序,比较重要的目录/usr/local 本地系统管理员软件安装目录(安装系统级的应用)。这是最庞大的目录,要用到的应用程序和文件几乎都在这个目录。

/usr/x11r6 存放x window的目录

/usr/bin 众多的应用程序  

/usr/sbin 超级用户的一些管理程序  

/usr/doc linux文档  

/usr/include linux下开发和编译应用程序所需要的头文件  

/usr/lib 常用的动态链接库和软件包的配置文件  

/usr/man 帮助文档  

/usr/src 源代码,linux内核的源代码就放在/usr/src/linux里  

/usr/local/bin 本地增加的命令  

/usr/local/lib 本地增加的库

/opt

额外安装的可选应用程序包所放置的位置。一般情况下,我们可以把tomcat等都安装到这里。

/proc

虚拟文件系统目录,是系统内存的映射。可直接访问这个目录来获取系统信息。

/root

超级用户(系统管理员)的主目录(特权阶级^o^)

/sbin

存放二进制可执行文件,只有root才能访问。这里存放的是系统管理员使用的系统级别的管理命令和程序。如ifconfig等。

/dev

用于存放设备文件。

/mnt

系统管理员安装临时文件系统的安装点,系统提供这个目录是让用户临时挂载其他的文件系统。

/boot

存放用于系统引导时使用的各种文件

/lib

存放跟文件系统中的程序运行所需要的共享库及内核模块。共享库又叫动态链接共享库,作用类似windows里的.dll文件,存放了根文件系统程序运行所需的共享文件。

/tmp

用于存放各种临时文件,是公用的临时文件存储点。

/var

用于存放运行时需要改变数据的文件,也是某些大文件的溢出区,比方说各种服务的日志文件(系统启动日志等。)等。

/lost+found

这个目录平时是空的,系统非正常关机而留下“无家可归”的文件(windows下叫什么.chk)就在这里

 

Linux目录和Windows目录有着很大的不同,Linux目录类似一个树,最顶层是其根目录,如下图:

centos7将磁盘剩余空间分配给分区 centos怎么分配磁盘空间_centos7将磁盘剩余空间分配给分区

 

/bin 二进制可执行命令

/dev 设备特殊文件
/etc 系统管理和配置文件
/etc/rc.d 启动的配置文件和脚本
/home 用户主目录的基点,比如用户user的主目录就是/home/user,可以用~user表示
/lib 标准程序设计库,又叫动态链接共享库,作用类似windows里的.dll文件
/sbin 超级管理命令,这里存放的是系统管理员使用的管理程序
/tmp 公共的临时文件存储点
/root 系统管理员的主目录
/mnt 系统提供这个目录是让用户临时挂载其他的文件系统
/lost+found这个目录平时是空的,系统非正常关机而留下“无家可归”的文件(windows下叫什么.chk)就在这里
/proc 虚拟的目录,是系统内存的映射。可直接访问这个目录来获取系统信息。
/var 某些大文件的溢出区,比方说各种服务的日志文件
/usr 最庞大的目录,要用到的应用程序和文件几乎都在这个目录,其中包含:

/usr/x11R6 存放x window的目录
/usr/bin 众多的应用程序
/usr/sbin 超级用户的一些管理程序
/usr/doc linux文档
/usr/include linux下开发和编译应用程序所需要的头文件
/usr/lib 常用的动态链接库和软件包的配置文件
/usr/man 帮助文档
/usr/src 源代码,linux内核的源代码就放在/usr/src/linux里
/usr/local/bin 本地增加的命令

  • 物理设备命名规则

主分区或拓展分区的编号从1开始,到4结束;

逻辑分区编号从5开始

centos7将磁盘剩余空间分配给分区 centos怎么分配磁盘空间_linux_02

  • 存储格式
  • Ext3:能够在系统异常宕机时避免文件系统资料丢失,并能自动修复数据的不一致与错误。然而当硬盘容量较大时,需要的修复时间也会很长,也不能够保证百分百的保证数据不丢失;
  • Ext4:Ext3的改进版,支持存储容量1EB(1,073,731,824GB),而且有无限多的子目录,能够批量分配block块,从而极大的提高了读写效率;
  • XFS:发生宕机时优势很明显,可以快速回复可能被破坏的文件,且消耗计算与存储性能极低,最大容量可支持18EB;
  • mount挂载硬件设备,格式:mount 【文件系统】 【挂载目录】,例如:mount /dev/sdb2 /backup ,只是暂时挂载,重启后挂载关系失效

参数

作用

-a

挂载所有在 /etc/fstab 中定义的文件系统

-t

指定文件系统类型 

 

持久挂载需要配置 /etc/fstab 文件

/dev/fdo     /mnt/flopy      ext3        noauto       0 0
/dev/cdrom   /mnt/cdrom      iso9660     noauto,ro  0 0
/dev/sdb2    /mnt/cdrom      ext4        defaults  0 0
  • umount 撤销已经挂载的设备文件,格式:umount 【设备文件或者挂载目录(其中之一即可)】,例如:umount /dev/sdb2

 

  • fdisk 磁盘分区,格式:fdisk 【磁盘名称】,例如:fdisk /dev/sdb2
  • fdisk -l 查看系统分区详细信息
[root@test4 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2610    20860402+  8e  Linux LVM
  • fdisk 对磁盘进行分区
[root@test4 ~]# fdisk /dev/sda  //对sda磁盘进行分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 2597.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
    (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m          //输出帮助信息
 Command action
    a   toggle a bootable flag    //设置启动分区
    b   edit bsd disklabel        //编辑分区标签
    c   toggle the dos compatibility flag
    d   delete a partition        //删除一个分区
    l   list known partition types  //列出分区类型
    m   print this menu           //输出帮助信息
    n   add a new partition       //建立一个新的分区
    o   create a new empty DOS partition table //创建一个新的空白DOS分区表
    p   print the partition table    //打印分区表
    q   quit without saving changes  //退出不保存设置
    s   create a new empty Sun disklabel
    t   change a partition's system id  //改变分区的ID
    u   change display/entry units    //改变显示的单位
    v   verify the partition table    //检查验证分区表
    w   write table to disk and exit  //保存分区表
    x   extra functionality (experts only)
Command (m for help):n     
Command action
   e   extended                 //e是扩展分区
   p   primary partition (1-4)  //p是主分区
p
Partition number (1-4): 1       //定义分区数量   --主分区最多只能有四个
First cylinder (1-2597, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-2597, default 2597): +100M

Command (m for help): w          //保存刚才的配置信息。
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: 无效的参数.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

[root@test6 ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
First cylinder (1710-2610, default 1710): 
Using default value 1710
Last cylinder or +size or +sizeM or +sizeK (1710-2610, default 2610): +100M     

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@test6 ~]# partprobe /dev/sda //对硬盘进行更新
[root@test6 ~]# fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes
heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         274     2096482+  82  Linux swap / Solaris
/dev/sda3             275         404     1044225   8e  Linux LVM
/dev/sda4             405        2610    17719695    5  Extended
/dev/sda5             405        1709    10482381   83  Linux
/dev/sda6            1710        1722      104391   83  Linux
[root@test6 ~]# mkfs.ext3 /dev/sda6  //需要先进行格式化,才能使用 。mkfs -t ext3 /dev/sda5 (mkfs.ext3 一样效果 -t 指定类型 -b 指定block大小·)
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
inodes, 104388 blocks
blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
block groups
blocks per group, 8192 fragments per group
inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or
days, whichever comes first.  Use tune2fs -c or -i to override.

[root@test6 ~]# mount /dev/sda6 /mnt/sda7/  //进行挂载使用
anaconda-ks.cfg  install.log  install.log.syslog
[root@test6 ~]# df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/sda5             9.7G  1.1G  8.1G  12% /
/dev/sda1              99M   12M   83M  13% /boot
tmpfs                 252M     0  252M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /mnt/cdrom
/dev/sda6              99M  5.6M   89M   6% /mnt/sda7
  • 磁盘管理常用命令
  • ls -i 文件名 查看文件存储在哪个innode中
[root@test6 ~]# ls -i lstest 
 1179659 lstest
  • ls -id 文件夹名 查看文件夹存储在哪个innode中
[root@test6 ~]# ls -id lstest1
1179661 lstest1
  • filefrag -v 文件名 查看文件存储block具体位置
[root@test6 ~]# filefrag -v lstest
Checking lstest
Filesystem type is: ef53
Filesystem cylinder groups is approximately 78
Blocksize of file lstest is 4096
File size of lstest is 5 (1 blocks)
First block: 1183744
Last block: 1183744
lstest: 1 extent found
  • mkfs,敲击两次tab键,会提示格式化后缀,选择对应的后缀名格式化,例如:mkfs.xfs /dev/sbd2
  • df -h 查看挂载状态与磁盘使用量信息
  • du 文件数据占用量,格式:du 【选项】 文件,例如:du -sh xxx.txt

 

  • mkswap 添加交换分区:通过在硬盘中预先划分一定的空间,然后将把内存中暂时不常用的数据临时存放到硬盘中,以便腾出物理内存空间让更活跃的程序服务来使用的技术。只有真实的物理内存耗尽后才会调用交换分区的资源,mkswap为其专用的格式化命令,例如:mkswap /dev/sdb2
  • xfs_quota 磁盘配额,格式:xfs_quota 【参数】 ‘【配额】 【用户】’ 【文件系统】,一个专门针对xfs文件系统来管理quota磁盘容量配额服务而设计的;
  • 例如:xfs_quota -x -c 'limit bsoft=3m bhard=6m usoft=3 ihard=6 tom' /boot ,解释:为tom用户限制磁盘使用额度,软限制为3m或3个文件,硬限制为6m或6个文件
  • 软限制:当达到软限制时会提示用户,但是允许用户在设定的额度内计需使用;
  • 硬限制:当达到软限制时会提示用户,且强制终止用户操作;
  • edquota 编辑用户配额,格式: edquota 【参数】 【用户】,例如:edquota -u tom
  • ln链接方式
  • 软连接:好比windows中的快捷方式,源文件删除后软链接失效;
  • 硬链接:硬链接与原文件其实是同一个文件,只是名字不同。每添加一个硬链接,该文件的inode连接数都会增加1,只有inode连接数为0时才可以彻底删除,实际上硬链接是原文件inode的指针,即使原文件被删除,让然可以通过硬链接访问,需要注意的是,不能跨分区对目录文件进行链接;

参数

作用

-s

创建“符号链接(软链接)”,不带 -s 参数默认创建的为硬链接

-f

强制创建文件或目录的链接

-i

覆盖前,先询问

-v

显示创建链接的过程