###################
####    接 10.系统日志    ####    
###################

####################
[root@localhost Desktop]# timedatectl
      Local time: Thu 2016-10-27 18:00:05 CST
  Universal time: Thu 2016-10-27 10:00:05 UTC
        RTC time: Thu 2016-10-27 10:00:05
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@localhost Desktop]# date 10271111.11
Thu Oct 27 11:11:11 CST 2016
[root@localhost Desktop]# timedatectl
      Local time: Thu 2016-10-27 11:11:27 CST
  Universal time: Thu 2016-10-27 03:11:27 UTC
        RTC time: Thu 2016-10-27 10:01:38
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@localhost Desktop]# clock --help
--------------------------------------------------
参数说明如下:
 -s, --hctosys        set the system time from the hardware clock
 -w, --systohc        set the hardware clock from the current system time
--------------------------------------------------
[root@localhost Desktop]# clock -w
[root@localhost Desktop]# timedatectl
      Local time: Thu 2016-10-27 11:11:50 CST
  Universal time: Thu 2016-10-27 03:11:50 UTC
        RTC time: Thu 2016-10-27 03:11:50        ##"Universal time"写入"RTC time"
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@localhost Desktop]# date 10272222.22
Thu Oct 27 22:22:22 CST 2016
[root@localhost Desktop]# timedatectl
      Local time: Thu 2016-10-27 22:22:23 CST
  Universal time: Thu 2016-10-27 14:22:23 UTC
        RTC time: Thu 2016-10-27 03:12:58
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@localhost Desktop]# clock -s
[root@localhost Desktop]# timedatectl
      Local time: Thu 2016-10-27 11:13:10 CST        ##"RTC time"写入"Universal time"
  Universal time: Thu 2016-10-27 03:13:10 UTC
        RTC time: Thu 2016-10-27 03:13:10
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
注意:如果设置"timedatectl set-local-rtc 1",那么
"clock -w"就是"Local time"写入"RTC time"
"clock -s"就是"RTC time"写入"Local time"

[root@localhost Desktop]# timedatectl set-time 22:22:22
[root@localhost Desktop]# timedatectl
      Local time: Thu 2016-10-27 22:22:23 CST
  Universal time: Thu 2016-10-27 14:22:23 UTC
        RTC time: Thu 2016-10-27 14:22:23
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
使用"timedatectl set-time"命令直接修改"RTC time"
####################

####################
desktop&server:
[root@localhost Desktop]# systemctl stop firewalld.service
desktop:
[root@localhost Desktop]# vim /etc/rsyslog.conf
--------------------------------------------------
 51 *.*                                                     @@172.25.50.200
:wq
--------------------------------------------------
[root@localhost Desktop]# systemctl restart rsyslog.service
server:
[root@localhost Desktop]# vim /etc/rsyslog.conf
--------------------------------------------------
 19 $ModLoad imtcp
 20 $InputTCPServerRun 514
:wq
--------------------------------------------------
[root@localhost Desktop]# systemctl restart rsyslog.service
[root@localhost Desktop]# netstat -antlpe | grep rsyslog
tcp        0      0 0.0.0.0:514             0.0.0.0:*               LISTEN      0          83904      30054/rsyslogd      
tcp6       0      0 :::514                  :::*                    LISTEN      0          83905      30054/rsyslogd     
##注意TCP使用"netstat -antlpe"查看,UDP使用"netstat -anulpe"查看
desktop&server:
[root@localhost Desktop]# > /var/log/messages
desktop:
[root@localhost Desktop]# logger test
[root@localhost Desktop]# logger test
[root@localhost Desktop]# logger test
[root@localhost Desktop]# logger test
[root@localhost Desktop]# cat /var/log/messages
Oct 28 11:09:02 localhost root: test
Oct 28 11:09:03 localhost root: test
Oct 28 11:09:03 localhost root: test
[root@localhost Desktop]# date
Fri Oct 28 11:09:16 CST 2016
server:
[root@localhost Desktop]# cat /var/log/messages
Oct 28 11:09:02 localhost root: test
Oct 28 11:09:03 localhost root: test
Oct 28 11:09:03 localhost root: test
[root@localhost Desktop]# date
Fri Oct 28 11:09:21 CST 2016
=====修改日志发送方的时间=====
desktop:
[root@localhost Desktop]# date 10281000
Fri Oct 28 10:00:00 CST 2016
desktop&server:
[root@localhost Desktop]# > /var/log/messages
desktop:
[root@localhost Desktop]# logger test
[root@localhost Desktop]# logger test
[root@localhost Desktop]# logger test
[root@localhost Desktop]# cat /var/log/messages
Oct 28 10:00:14 localhost root: test
Oct 28 10:00:15 localhost root: test
Oct 28 10:00:15 localhost root: test
[root@localhost Desktop]# date
Fri Oct 28 10:00:39 CST 2016
server:
[root@localhost Desktop]# cat /var/log/messages
Oct 28 10:00:14 localhost root: test
Oct 28 10:00:15 localhost root: test
Oct 28 10:00:15 localhost root: test            ##默认显示日志发送方的时间
[root@localhost Desktop]# date
Fri Oct 28 11:15:30 CST 2016
=====修改日志接收方的采集格式=====
[root@localhost Desktop]# vim /etc/rsyslog.conf
--------------------------------------------------
 45 $template WESTOS, "%timegenerated% %FROMHOST-IP% %syslogtag% %msg%\n"
 46 $ActionfileDefaultTemplate WESTOS

 55 *.info;mail.none;authpriv.none;cron.none                /var/log/messages;WESTOS
:wq
--------------------------------------------------
[root@localhost Desktop]# systemctl restart rsyslog.service
desktop&server:
[root@localhost Desktop]# > /var/log/messages
desktop:
[root@localhost Desktop]# logger test
[root@localhost Desktop]# logger test
[root@localhost Desktop]# logger test
[root@localhost Desktop]# cat /var/log/messages
Oct 28 10:06:26 localhost root: test
Oct 28 10:06:26 localhost root: test
Oct 28 10:06:27 localhost root: test
[root@localhost Desktop]# date
Fri Oct 28 10:06:32 CST 2016
server:
[root@localhost Desktop]# > /var/log/messages
[root@localhost Desktop]# cat /var/log/messages
Oct 28 11:21:22 172.25.50.100 root:  test
Oct 28 11:21:23 172.25.50.100 root:  test
Oct 28 11:21:23 172.25.50.100 root:  test        ##如果日志接收方设定了时间格式,就会显示本地时间
[root@localhost Desktop]# date
Fri Oct 28 11:21:35 CST 2016
####################

####################4.时间同步####################

####################
[root@foundation50 Desktop]# yum whatprovides */chronyd
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
chrony-2.1.1-1.el7.x86_64 : An NTP client/server    ##NTP指网络时间协议(Network Time Protocol)
Repo        : rhel7.2
Matched from:
Filename    : /usr/sbin/chronyd



chrony-2.1.1-1.el7.x86_64 : An NTP client/server
Repo        : @anaconda/7.2
Matched from:
Filename    : /usr/sbin/chronyd
####################
yum install chrony -y        ##安装服务

1.服务端
vim /etc/chrony.conf        ##主配置文件
--------------------------------------------------
 21 # Allow NTP client access from local network.
 22 allow 172.25.50.0/24    ##允许谁去同步我的时间

 28 # Serve time even if not synchronized to any NTP server.
 29 local stratum 10        ##不去同步任何人的时间
:wq
--------------------------------------------------
systemctl restart chronyd.service
systemctl stop firewalld.service

2.客户端
vim /etc/chrony.conf
--------------------------------------------------
  3 server 0.rhel.pool.ntp.org iburst | =====> 3 server 172.25.50.200 iburst
  4 server 1.rhel.pool.ntp.org iburst |
  5 server 2.rhel.pool.ntp.org iburst |
  6 server 3.rhel.pool.ntp.org iburst |
:wq
--------------------------------------------------
systemctl restart chronyd.service
systemctl stop firewalld.service

测试:
[root@desktop ~]# chronyc sources -v
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||                                                /   xxxx = adjusted offset,
||         Log2(Polling interval) -.             |    yyyy = measured offset,
||                                  \            |    zzzz = estimated error.
||                                   |           |                         
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================
^* 172.25.50.200                10   6    17     3  -1778ns[-5000ns] +/-  976us

注意:同步并不是即时同步,一个小时同步一次。要想手动同步可以重启服务

####################5.timedatectl####################
timedatectl    status              ##显示当前时间信息
                     set-time           ##设定当前时间
                     set-timezone    ##设定当前时区
                     set-local-rtc      ##设定是否使用UTC时间

"timedatectl set-local-rtc 1"表示让BIOS时间使用UTC时间
对于使用Linux和Windows双系统的主机来说,可以保持两边的时间一致

####################
[root@localhost Desktop]# timedatectl
      Local time: Fri 2016-10-28 11:54:54 CST
  Universal time: Fri 2016-10-28 03:54:54 UTC
        RTC time: Fri 2016-10-28 03:54:54
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

UTC指世界标准时间(Coordinated Universal Time)
Linux把BIOS时间初始化为UTC时间,再加上时区时差,就等于系统时间

CST = China Standard Time,中国标准时间
EST = Eastern Standard Time,(美国)东部标准时间
RTC = Real Time Clock,实时时钟

[root@localhost Desktop]# man timedatectl
--------------------------------------------------
       set-local-rtc [BOOL]
           Takes a boolean argument. If "0", the system is configured to maintain
           the RTC in universal time. If "1", it will maintain the RTC in local time
           instead. Note that maintaining the RTC in the local timezone is not fully
           supported and will create various problems with time zone changes and
           daylight saving adjustments. If at all possible, keep the RTC in UTC
           mode. Note that invoking this will also synchronize the RTC from the
           system clock, unless --adjust-system-clock is passed (see above). This
           command will change the 3rd line of /etc/adjtime, as documented in
           hwclock(8).
--------------------------------------------------
[root@localhost Desktop]# timedatectl
      Local time: Fri 2016-10-28 12:31:37 CST
  Universal time: Fri 2016-10-28 04:31:37 UTC
        RTC time: Fri 2016-10-28 04:31:38
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@localhost Desktop]# cat /etc/adjtime
0.0 0 0.0
0
UTC    ##RTC使用UTC
[root@localhost Desktop]# timedatectl set-local-rtc 1
[root@localhost Desktop]# timedatectl
      Local time: Fri 2016-10-28 12:31:42 CST
  Universal time: Fri 2016-10-28 04:31:42 UTC
        RTC time: Fri 2016-10-28 12:31:42
        Timezone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: yes
      DST active: n/a

Warning: The RTC is configured to maintain time in the local timezone. This
         mode is not fully supported and will create various problems with time
         zone changes and daylight saving adjustments. If at all possible use
         RTC in UTC, by calling 'timedatectl set-local-rtc 0'.
[root@localhost Desktop]# cat /etc/adjtime
0.0 0 0.0
0
LOCAL    ##RTC使用LOCAL

[root@localhost Desktop]# rpm -qc chrony    ##"rpm -qc"配置文件
/etc/chrony.conf
/etc/chrony.keys
/etc/logrotate.d/chrony
[root@localhost Desktop]# rpm -qd chrony    ##"rpm -qd"帮助文档
/usr/share/doc/chrony-1.29.1/COPYING
/usr/share/doc/chrony-1.29.1/NEWS
/usr/share/doc/chrony-1.29.1/README
/usr/share/doc/chrony-1.29.1/chrony.conf.example
/usr/share/doc/chrony-1.29.1/chrony.conf.example2
/usr/share/doc/chrony-1.29.1/chrony.keys.example
/usr/share/doc/chrony-1.29.1/chrony.txt
/usr/share/doc/chrony-1.29.1/faq.txt
/usr/share/info/chrony.info.gz
/usr/share/man/man1/chrony.1.gz
/usr/share/man/man1/chronyc.1.gz
/usr/share/man/man5/chrony.conf.5.gz
/usr/share/man/man8/chronyd.8.gz
####################

############################
#### 14.Linux中设备的访问    ####    
############################

####################1.设备访问####################
1.设备识别
/dev/xdxn        ##硬盘设备/dev/sda1
/dev/cdrom        ##光驱
/dev/mapper/*        ##虚拟设备

vda
"v"虚拟
"d"硬盘
"a"第一块

SATA
串口硬盘,系统会识别成sda
IDE
并口硬盘,系统会识别成hda

sda1
"1"第一个分区

####################
[root@foundation50 Desktop]# ll /dev/sda
brw-rw----. 1 root disk 8, 0 Oct 28 09:06 /dev/sda
[root@foundation50 Desktop]# ll /dev/sda9
brw-rw----. 1 root disk 8, 9 Oct 28 09:06 /dev/sda9
[root@foundation50 Desktop]# ll /dev/mapper/
total 0
crw-------. 1 root root 10, 236 Oct 28 09:06 control
lrwxrwxrwx. 1 root root       7 Oct 28 09:06 rhel-root -> ../dm-0
lrwxrwxrwx. 1 root root       7 Oct 28 09:06 rhel-swap -> ../dm-1
[root@foundation50 Desktop]# ll /dev/cdrom
lrwxrwxrwx. 1 root root 3 Oct 28 09:06 /dev/cdrom -> sr0
####################

2.设备的使用
1>设备的发现
fdisk -l                        ##查看真实存在的设备,root用户下执行,真实存在不一定被系统识别

cat /porc/partitions    ##系统能够识别的设备
blkid                           ##系统能够挂载使用的设备id
df                               ##查看设备被系统使用的情况

####################
[root@foundation50 Desktop]# man fdisk
--------------------------------------------------
       -l     List the partition tables for the specified devices and then exit.  If
              no devices are given, those mentioned  in  /proc/partitions  (if  that
              exists) are used.
--------------------------------------------------
"-l"列出指定设备的分区表,然后退出。 如果没有给出设备,则使用/proc/partitions(如果存在)中提及的设备。
[root@foundation50 Desktop]# man partprobe
--------------------------------------------------
       partprobe  is a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the  partition table.
--------------------------------------------------
partprobe是一个程序,通过请求操作系统重新读取分区表,通知操作系统内核分区表更改。
[root@foundation50 Desktop]# man df
--------------------------------------------------
       This  manual page documents the GNU version of df.  df displays the amount of
       disk space available on the file system containing each file  name  argument.
       If  no  file name is given, the space available on all currently mounted file
       systems is shown.  Disk space is shown in 1K blocks by  default,  unless  the
       environment  variable  POSIXLY_CORRECT  is set, in which case 512-byte blocks
       are used.

       If an argument is the absolute file name of a disk device node  containing  a
       mounted  file system, df shows the space available on that file system rather
       than on the file system containing the device node.  This version of df  can‐
       not show the space available on unmounted file systems, because on most kinds
       of systems doing so requires very nonportable intimate knowledge of file sys‐
       tem structures.
--------------------------------------------------
    本手册页面记录了df的GNU版本。 df显示包含每个文件名参数的文件系统上可用的磁盘空间量。如果未给出文件名,则显示当前装载的所有文件系统上的可用空间。默认情况下,磁盘空间以1K块显示,除非设置了环境变量POSIXLY_CORRECT,在这种情况下使用512字节块。
    如果参数是包含装入的文件系统的磁盘设备节点的绝对文件名,则df显示该文件系统上的可用空间,而不是包含设备节点的文件系统上的可用空间。此版本的df无法显示卸载的文件系统上可用的空间,因为在大多数类型的系统这样做需要非常不可移植的文件系统结构的内在知识。

[root@foundation50 Desktop]# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x35993598

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63   102944519    51472228+   7  HPFS/NTFS/exFAT
/dev/sda2       102944520   976768064   436911772+   f  W95 Ext'd (LBA)
/dev/sda5       102944583   267867809    82461613+   b  W95 FAT32
/dev/sda6       267867873   432935684    82533906    7  HPFS/NTFS/exFAT
/dev/sda7       432935748   598228469    82646361    b  W95 FAT32
/dev/sda8       598228533   763392734    82582101    b  W95 FAT32
/dev/sda9       763396096   764420095      512000   83  Linux
/dev/sda10      764422144   976766975   106172416   8e  Linux LVM

Disk /dev/mapper/rhel-root: 102.5 GB, 102538149888 bytes, 200269824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/rhel-swap: 6174 MB, 6174015488 bytes, 12058624 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@foundation50 Desktop]# cat /proc/partitions
major minor  #blocks  name

   8        0  488386584 sda
   8        1   51472228 sda1
   8        2          1 sda2
   8        5   82461613 sda5
   8        6   82533906 sda6
   8        7   82646361 sda7
   8        8   82582101 sda8
   8        9     512000 sda9
   8       10  106172416 sda10
  11        0    1048575 sr0
 253        0  100134912 dm-0
 253        1    6029312 dm-1
   7        0    3799040 loop0
   7        1    3948544 loop1
[root@foundation50 Desktop]# blkid
/dev/sda1: UUID="AEDAB036DAAFF92B" TYPE="ntfs"
/dev/sda5: UUID="0137-0138" TYPE="vfat"
/dev/sda6: UUID="760C100D0C0FC6D9" TYPE="ntfs"
/dev/sda7: UUID="0177-0178" TYPE="vfat"
/dev/sda8: UUID="0197-0198" TYPE="vfat"
/dev/sda9: UUID="62cae836-75bf-430e-b221-db31580d7892" TYPE="xfs"
/dev/sda10: UUID="g4Mceu-G2Xo-wZOh-CsgA-7AcT-BR9v-IWI6UT" TYPE="LVM2_member"
/dev/mapper/rhel-root: UUID="c18eadea-b263-4ae7-8ebb-65a21620e361" TYPE="xfs"
/dev/mapper/rhel-swap: UUID="ddd50211-25df-4163-8cb3-06466d19988e" TYPE="swap"
/dev/loop0: UUID="2015-02-19-11-11-02-00" LABEL="RHEL-7.1 Server.x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/loop1: UUID="2015-10-30-11-11-49-00" LABEL="RHEL-7.2 Server.x86_64" TYPE="iso9660" PTTYPE="dos"
[root@foundation50 Desktop]# df
Filesystem            1K-blocks     Used Available Use% Mounted on
/dev/mapper/rhel-root 100086020 49652608  50433412  50% /
devtmpfs                2968976        0   2968976   0% /dev
tmpfs                   2984676      708   2983968   1% /dev/shm
tmpfs                   2984676     9316   2975360   1% /run
tmpfs                   2984676        0   2984676   0% /sys/fs/cgroup
/dev/sda9                508588   144780    363808  29% /boot
/dev/loop0              3798292  3798292         0 100% /var/www/html/rhel7.1
/dev/loop1              3947824  3947824         0 100% /var/www/html/rhel7.2
tmpfs                    596936       36    596900   1% /run/user/0
[root@foundation50 Desktop]# df -h                    ##以1024为单位
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   96G   48G   49G  50% /
devtmpfs               2.9G     0  2.9G   0% /dev
tmpfs                  2.9G  708K  2.9G   1% /dev/shm
tmpfs                  2.9G  9.1M  2.9G   1% /run
tmpfs                  2.9G     0  2.9G   0% /sys/fs/cgroup
/dev/sda9              497M  142M  356M  29% /boot
/dev/loop0             3.7G  3.7G     0 100% /var/www/html/rhel7.1
/dev/loop1             3.8G  3.8G     0 100% /var/www/html/rhel7.2
tmpfs                  583M   36K  583M   1% /run/user/0
[root@foundation50 Desktop]# df -H                    ##以1000为单位
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root  103G   51G   52G  50% /
devtmpfs               3.1G     0  3.1G   0% /dev
tmpfs                  3.1G  725k  3.1G   1% /dev/shm
tmpfs                  3.1G  9.6M  3.1G   1% /run
tmpfs                  3.1G     0  3.1G   0% /sys/fs/cgroup
/dev/sda9              521M  149M  373M  29% /boot
/dev/loop0             3.9G  3.9G     0 100% /var/www/html/rhel7.1
/dev/loop1             4.1G  4.1G     0 100% /var/www/html/rhel7.2
tmpfs                  612M   37k  612M   1% /run/user/0
####################

2>设备的使用
1)设备的挂载
mount        设备        挂载点
mount        /dev/sdb1    /mnt        ##把系统中第二块硬盘的第一个分区挂载到/mnt目录

umount可以接设备,可以接挂载点

如出现以下情况:
[root@foundation0 ~]# umount /dev/sdb1
umount: /home/kiosk/Desktop/photo: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

解决:
fuser -kvm    设备|挂载点
"-k"    ##kill
"-v"    ##显示详细信息
"-m"    ##扫描设备
详细参数,使用"man fuser"查看

####################
在主机上插入一只U盘
[root@foundation50 3802-4BDD]# df
Filesystem            1K-blocks     Used Available Use% Mounted on
/dev/mapper/rhel-root 100086020 49683436  50402584  50% /
devtmpfs                2968976        0   2968976   0% /dev
tmpfs                   2984676      744   2983932   1% /dev/shm
tmpfs                   2984676     9340   2975336   1% /run
tmpfs                   2984676        0   2984676   0% /sys/fs/cgroup
/dev/sda9                508588   144780    363808  29% /boot
/dev/loop0              3798292  3798292         0 100% /var/www/html/rhel7.1
/dev/loop1              3947824  3947824         0 100% /var/www/html/rhel7.2
tmpfs                    596936       32    596904   1% /run/user/0
tmpfs                   2984676        0   2984676   0% /tmp
/dev/sdb4               7812064   319388   7492676   5% /run/media/root/3802-4BDD
[root@foundation50 Desktop]# umount /dev/sdb4
[root@foundation50 Desktop]# df
Filesystem            1K-blocks     Used Available Use% Mounted on
/dev/mapper/rhel-root 100086020 49667544  50418476  50% /
devtmpfs                2968976        0   2968976   0% /dev
tmpfs                   2984676      744   2983932   1% /dev/shm
tmpfs                   2984676     9332   2975344   1% /run
tmpfs                   2984676        0   2984676   0% /sys/fs/cgroup
/dev/sda9                508588   144780    363808  29% /boot
/dev/loop0              3798292  3798292         0 100% /var/www/html/rhel7.1
/dev/loop1              3947824  3947824         0 100% /var/www/html/rhel7.2
tmpfs                    596936       40    596896   1% /run/user/0
tmpfs                   2984676        0   2984676   0% /tmp
[root@foundation50 Desktop]# mount /dev/sdb4 /mnt
[root@foundation50 Desktop]# df
Filesystem            1K-blocks     Used Available Use% Mounted on
/dev/mapper/rhel-root 100086020 49667540  50418480  50% /
devtmpfs                2968976        0   2968976   0% /dev
tmpfs                   2984676      744   2983932   1% /dev/shm
tmpfs                   2984676     9332   2975344   1% /run
tmpfs                   2984676        0   2984676   0% /sys/fs/cgroup
/dev/sda9                508588   144780    363808  29% /boot
/dev/loop0              3798292  3798292         0 100% /var/www/html/rhel7.1
/dev/loop1              3947824  3947824         0 100% /var/www/html/rhel7.2
tmpfs                    596936       40    596896   1% /run/user/0
tmpfs                   2984676       12   2984664   1% /tmp
/dev/sdb4               7812064   319388   7492676   5% /mnt
使用图形进入/mnt目录,打开一个shell
[root@foundation50 Desktop]# umount /mnt
umount: /mnt: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@foundation50 Desktop]# lsof /dev/sdb4
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
bash    19587 root  cwd    DIR   8,20     4096    1 /run/media/root/3802-4BDD
[root@foundation50 Desktop]# fuser -vm /dev/sdb4
                     USER        PID ACCESS COMMAND
/mnt:                root     kernel mount /mnt
                     root      19587 ..c.. bash
[root@foundation50 Desktop]# fuser -kvm /mnt
                     USER        PID ACCESS COMMAND
/mnt:                root     kernel mount /mnt
                     root      19587 ..c.. bash
[root@foundation50 Desktop]# fuser -vm /dev/sdb4
                     USER        PID ACCESS COMMAND
/mnt:                root     kernel mount /mnt
[root@foundation50 Desktop]# umount /mnt
[root@foundation50 Desktop]# df
Filesystem            1K-blocks     Used Available Use% Mounted on
/dev/mapper/rhel-root 100086020 49668408  50417612  50% /
devtmpfs                2968976        0   2968976   0% /dev
tmpfs                   2984676      744   2983932   1% /dev/shm
tmpfs                   2984676     9332   2975344   1% /run
tmpfs                   2984676        0   2984676   0% /sys/fs/cgroup
/dev/sda9                508588   144780    363808  29% /boot
/dev/loop0              3798292  3798292         0 100% /var/www/html/rhel7.1
/dev/loop1              3947824  3947824         0 100% /var/www/html/rhel7.2
tmpfs                    596936       40    596896   1% /run/user/0
tmpfs                   2984676       12   2984664   1% /tmp
成功解除挂载!
####################

####################2.软硬链接####################
ls -i            ##查看文件节点号
ln -s /file /file1    ##软链接
ln /file /file1        ##硬链接

硬链接不能跨越分区,软链接可以跨越分区
软链接多个节点对应一个数据块
硬链接一个节点对应多个数据块

####################
[root@localhost Desktop]# ls -ild /mnt
16818881 drwxr-xr-x. 2 root root 6 Mar 13  2014 /mnt
[root@localhost Desktop]# ls -ild /opt
25166476 drwxr-xr-x. 3 root root 15 Oct 20 13:51 /opt
[root@localhost Desktop]# mount --bind /opt /mnt
[root@localhost Desktop]# ls -id /mnt
25166476 /mnt                        ##文件节点号改变
[root@localhost Desktop]# ls -ild /mnt
25166476 drwxr-xr-x. 3 root root 15 Oct 20 13:51 /mnt
[root@localhost Desktop]# chmod 777 /mnt        ##修改权限
[root@localhost Desktop]# ls -ild /mnt
25166476 drwxrwxrwx. 3 root root 15 Oct 20 13:51 /mnt
[root@localhost Desktop]# umount /mnt
[root@localhost Desktop]# ls -ild /mnt
16818881 drwxr-xr-x. 2 root root 6 Mar 13  2014 /mnt    ##解绑后"/mnt"权限没有变化
[root@localhost Desktop]# ls -ild /opt
25166476 drwxrwxrwx. 3 root root 15 Oct 20 13:51 /opt    ##解绑后"/opt"权限发生变化

[root@localhost Desktop]# cd /mnt
[root@localhost mnt]# touch file
[root@localhost mnt]# ls -li file
20322059 -rw-r--r--. 1 root root 0 Oct 28 18:17 file
[root@localhost mnt]# ln -s file /opt
[root@localhost mnt]# ls -li /opt
total 0
27668355 lrwxrwxrwx. 1 root root 9 Oct 28 18:17 file -> /mnt/file    ##软链接,节点号不一样
20142873 drwxr-xr-x. 2 root root 6 Oct 23  2014 rh
[root@localhost mnt]# rm -fr file
[root@localhost mnt]# ls -li /opt
total 0
27668355 lrwxrwxrwx. 1 root root 9 Oct 28 18:17 file -> /mnt/file
20142873 drwxr-xr-x. 2 root root 6 Oct 23  2014 rh
##"18:17"后面的"file"背景颜色变黑,表示不可用。在这里无法呈现

[root@localhost mnt]# rm -fr /opt/file
[root@localhost mnt]# touch file
[root@localhost mnt]# ln file /opt
[root@localhost mnt]# ll
total 0
-rw-r--r--. 2 root root 0 Oct 28 18:24 file
[root@localhost mnt]# ll /opt
total 0
-rw-r--r--. 2 root root 0 Oct 28 18:24 file
drwxr-xr-x. 2 root root 6 Oct 23  2014 rh
[root@localhost mnt]# ln file /opt/file1
[root@localhost mnt]# ll /opt
total 0
-rw-r--r--. 3 root root 0 Oct 28 18:24 file
-rw-r--r--. 3 root root 0 Oct 28 18:24 file1
drwxr-xr-x. 2 root root 6 Oct 23  2014 rh
[root@localhost mnt]# ls -i /mnt/
20322059 file
[root@localhost mnt]# ls -i /opt
20322059 file  20322059 file1  20142873 rh    ##硬链接,节点号一样
[root@localhost mnt]# rm -fr file
[root@localhost mnt]# ls -il /mnt
total 0
[root@localhost mnt]# ls -il /opt
total 0
20322059 -rw-r--r--. 2 root root 0 Oct 28 18:24 file
20322059 -rw-r--r--. 2 root root 0 Oct 28 18:24 file1
20142873 drwxr-xr-x. 2 root root 6 Oct 23  2014 rh
##删除"/mnt/file",对"/opt"下的"file"和"file1"无影响
####################

####################3.文件查找####################
1.locate filename    ##在文件数据库中搜索filename信息,updatedb更新文件数据库

locate命令不靠谱

####################
[root@foundation50 Desktop]# locate westos
/etc/libvirt/qemu/westos6.5.xml
/etc/libvirt/qemu/westos7.1.xml
/var/lib/AccountsService/users/westos
/var/lib/libvirt/p_w_picpaths/westos6.5.qcow2
/var/lib/libvirt/p_w_picpaths/westos7.1.qcow2
/var/log/libvirt/qemu/westos.log
/var/log/libvirt/qemu/westos6.5.log
/var/log/libvirt/qemu/westos7.0.log
/var/log/libvirt/qemu/westos7.1.log
[root@foundation50 Desktop]# locate westos1
[root@foundation50 Desktop]# updatedb
[root@foundation50 Desktop]# locate westos1
/root/Desktop/westos1
####################

2.find
find    查找位置        -条件    条件值    -exec 动作 {} \;
            -name
            -not    条件
            -user
            -group
            -size
            -perm
            --maxdepth
            --mindepth
            -a
            -o

find:
-a表示and
-o表示or
-a -not 是1,不是2

find /mnt -user student
find /mnt -group linux
find /mnt -user student -a -group linux
find /mnt -user student -o -group linux
find /mnt -user student -a -not -group linux

dd if=/dev/zero of=/mnt/file1 bs=1024 count=10
dd if=/dev/zero of=/mnt/file2 bs=1024 count=20
dd if=/dev/zero of=/mnt/file3 bs=1024 count=30

dd表示截取
if=inputfile
of=outputfile

find /mnt -size 10k
find /mnt -size -10k
find /mnt -size +10k

####################
[root@localhost mnt]# cd /mnt
[root@localhost mnt]# touch file{1..5}
[root@localhost mnt]# useradd student
[root@localhost mnt]# useradd linux
[root@localhost mnt]# useradd test
[root@localhost mnt]# chown student.westos file1
[root@localhost mnt]# chown student.linux file2
[root@localhost mnt]# chown test.linux file3
[root@localhost mnt]# chown westos.westos file4
[root@localhost mnt]# ll
total 0
-rw-r--r--. 1 student westos 0 Oct 28 18:40 file1
-rw-r--r--. 1 student linux  0 Oct 28 18:40 file2
-rw-r--r--. 1 test    linux  0 Oct 28 18:40 file3
-rw-r--r--. 1 westos  westos 0 Oct 28 18:40 file4
-rw-r--r--. 1 root    root   0 Oct 28 18:40 file5
[root@localhost mnt]# find /mnt -user student
/mnt/file1
/mnt/file2
[root@localhost mnt]# find /mnt -group linux
/mnt/file2
/mnt/file3
[root@localhost mnt]# find /mnt -user student -a -group linux
/mnt/file2
[root@localhost mnt]# find /mnt -user student -o -group linux
/mnt/file1
/mnt/file2
/mnt/file3
[root@localhost mnt]# find /mnt -user student -a -not -group linux
/mnt/file1

[root@localhost mnt]# dd if=/dev/zero of=/mnt/file1 bs=1024 count=10
10+0 records in
10+0 records out
10240 bytes (10 kB) copied, 0.000194748 s, 52.6 MB/s
[root@localhost mnt]# dd if=/dev/zero of=/mnt/file2 bs=1024 count=20
20+0 records in
20+0 records out
20480 bytes (20 kB) copied, 0.00052485 s, 39.0 MB/s
[root@localhost mnt]# dd if=/dev/zero of=/mnt/file3 bs=1024 count=30
30+0 records in
30+0 records out
30720 bytes (31 kB) copied, 0.000222283 s, 138 MB/s
[root@localhost mnt]# ll
total 64
-rw-r--r--. 1 student westos 10240 Oct 28 18:48 file1
-rw-r--r--. 1 student linux  20480 Oct 28 18:48 file2
-rw-r--r--. 1 test    linux  30720 Oct 28 18:48 file3
-rw-r--r--. 1 westos  westos     0 Oct 28 18:40 file4
-rw-r--r--. 1 root    root       0 Oct 28 18:40 file5
[root@localhost mnt]# find /mnt -size 10k
/mnt/file1
[root@localhost mnt]# find /mnt -size -10k
/mnt
/mnt/file4
/mnt/file5
[root@localhost mnt]# find /mnt -size +10k
/mnt/file2
/mnt/file3
####################