天天看點

軟硬連結、檔案删除原理、linux中的三種時間、chkconfig優化第1章 軟硬連結第2章 檔案删除原理第3章 找出某個檔案的其他的硬連結 第4章 三種時間戳第5章 chkconfig指令相關

多個檔案擁有相同的inode号碼

硬連結即檔案的多個入口

防止你誤删除檔案

ln 指令,前面是源檔案 後面是建立的連結檔案

[root@znix oldboy]# ln oldboyedu.txt oldboyedu.txt-hard

檢視兩檔案的inode号相同。

[root@znix oldboy]# ls -lhi oldboyedu.txt oldboyedu.txt-hard

151273 -rw-r--r-- 2 root root 607 Aug 30 09:13 oldboyedu.txt

151273 -rw-r--r-- 2 root root 607 Aug 30 09:13 oldboyedu.txt-hard

為了快捷,省事,友善使用

軟連接配接中存放的是源檔案的位置

使用ln -s 指令建立軟連接配接

[root@znix oldboy]# ln -s oldboyedu.txt oldboyedu.txt-soft

檢視軟硬連結的inode号不相同

但是同時指向的是同一檔案

[root@znix oldboy]# ll -i oldboyedu*

132910 -rw-r--r-- 1 root root 607 Aug 30 09:14 oldboyedu.txt.bak

132951 lrwxrwxrwx 1 root root  13 Aug 30 09:22 oldboyedu.txt-soft -> oldboyedu.txt

軟連結:

軟連接配接相當于快捷方式

裡面存放的是源檔案的位置

硬連結:

在同一個分區中,多個檔案擁有相同的inode号

              ln 建立硬連結

              ln -s 軟連接配接

1)軟連接配接可以随意建立

2)不能對目錄建立硬連結

3)對檔案建立硬連結可以防止檔案被誤删除

1)删除檔案的硬連結,檔案可以繼續使用

   2)隻有把這個檔案的所有硬連結都删除才可

3)隻删除源檔案軟連接配接無法使用

   4)隻删除軟連接配接對檔案沒有影響

1.硬連結數為0 與這個檔案有關的所有硬連結都被删除。

a) 使用rm目錄進行删除

2. 程序調用數為0,沒有人在使用這個檔案才能釋放磁盤空間。

a) 使用lsof 檢視誰在使用這檔案

b) 重新開機對應的軟體/服務就能釋放磁盤

使用lsof指令可以列出所有正在使用的檔案和相應的程序

[root@znix ~]# lsof /var/log/secure

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME

rsyslogd 1262 root    4w   REG    8,3     1927 270856 /var/log/secure

[root@znix ~]# lsof |grep message

rsyslogd  1262      root    1w      REG                8,3     1044     270855 /var/log/messages

找到軟體對應的管理位址,讓軟體重新開機,釋放空間。

[root@znix ~]# /etc/init.d/rsyslog

Usage: /etc/init.d/rsyslog {start|stop|restart|condrestart|try-restart|reload|force-reload|status}

       inode滿了……查找出系統目錄比較大(1M)

       block滿了……使用du -sh /* 一層一層找,把較大的檔案删除

硬連結數為0,程序調用數不為0

使用  lsof |grep delete 檢視占用的檔案

沒有被徹底删除-硬連結數為0,程序調用數不為零

向 /var/log/message中放入大量資料

seq 100000000 >>/var/log/messages

[root@znix apache]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3       8.8G  3.9G  3.7G  59% /

tmpfs           238M     0  238M   0% /dev/shm

/dev/sda1       190M   40M  141M  22% /boot

[root@znix apache]# \rm -f /var/log/messages

tmpfs           238M     0  238M   0% /dev/shm

[root@znix apache]# lsof |grep delete

rsyslogd  1168      root    1w      REG                8,3 889335632     259962 /var/log/messages (deleted)

[root@znix apache]# /etc/init.d/rsyslog restart

Shutting down system logger:                               [  OK  ]

Starting system logger:                                    [  OK  ]

檢視磁盤空間

/dev/sda3       8.8G  1.5G  6.9G  18% /

使用find指令 -inum參數找inode号碼,找到相同的inode 互為硬連結。

[root@znix ~]# ls -lhi  test.txt

260141 -rw-r--r--. 2 root root 265 Aug 29 19:16 test.txt

[root@znix ~]# find /* -type f -inum 260141

/root/test.txt

/root/test.txt-hard

Modify   mtime修改時間 (最常用) 檔案的内容 增加 删除 修改改變

Change   ctime屬性變更時間 檔案屬性發生改變時更改

Access   atime通路時間 檢視檔案的時間 (隻有檔案内容有修改時才會改變)

[root@znix ~]# stat oldboy.txt

  File: `oldboy.txt'

  Size: 237         Blocks: 8          IO Block: 4096   regular file

Device: 803h/2051d  Inode: 16976       Links: 2

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2017-08-28 11:45:26.734849384 +0800

Modify: 2017-08-28 11:45:26.734849384 +0800

Change: 2017-08-30 11:30:27.783364422 +0800

[root@znix ~]# echo "123">>oldboy.txt

  Size: 241         Blocks: 8          IO Block: 4096   regular file

Modify: 2017-08-30 11:40:57.384368932 +0800

Change: 2017-08-30 11:40:57.384368932 +0800

[root@znix ~]# ln oldboy.txt  oldboy.txt-hard

Device: 803h/2051d  Inode: 16976       Links: 3

Change: 2017-08-30 11:42:32.981364780 +0800

[root@znix ~]# tail -1 oldboy.txt

123

Access: 2017-08-30 11:43:15.288357930 +0800

chkconfig指令實際上控制的是/etc/rc3.d/(3運作模式下)下的軟連接配接。通過不通的軟連接配接,實作不通的控制。實際受/etc/init.d/下腳本的關系。

執行chkconfig iptables on後/etc/rc3.d/下的/etc/init.d/iptables改為S08iptables

[root@znix rc3.d]# chkconfig iptables on

[root@znix rc3.d]# chkconfig |grep ipt

iptables       0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@znix rc3.d]# ls -l /etc/rc3.d/ |grep ipt

lrwxrwxrwx  1 root root 18 Aug 30 12:03 S08iptables -> ../init.d/iptables

執行chkconfig iptables off /etc/rc3.d/下的/etc/init.d/iptables軟連接配接改為K92iptables

[root@znix rc3.d]# chkconfig iptables off

iptables       0:off   1:off   2:off   3:off   4:off   5:off   6:off

lrwxrwxrwx  1 root root 18 Aug 30 12:04 K92iptables -> ../init.d/iptables

iptables 開機自啟動 軟連接配接   S開頭

iptables 開機不自啟動 軟連接配接   K開頭

1)把腳本放入/etc/rc.local

2)通過chkconfig 管理指令或腳本,讓他開機自啟動

[root@znix rc3.d]# echo "hostname" > /etc/init.d/oldboyd

寫出chkconfig 才能被chkconfig管理

hkconfig:         2345       99       99

預設在哪幾個運作級别啟動 開機順序 關機順序

自己建立的開機順序一般寫99 ,99為最後一個

[root@znix rc3.d]# cat /etc/init.d/oldboyd

#!/bin/sh

#

# chkconfig: 2345 99 99

# description: print hostname

hostname

使用chmod指令修改檔案權限

需要有可執行的權限,不然無法執行

[root@znix rc3.d]# chmod +x /etc/init.d/oldboyd

[root@znix rc3.d]# ll /etc/init.d/oldboyd

-rwxr-xr-x 1 root root 9 Aug 30 12:22 /etc/init.d/oldboyd

[root@znix rc3.d]# chkconfig --add oldboyd

改為開機自啟動

[root@znix rc3.d]# chkconfig |grep old

oldboyd        0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@znix rc3.d]# ls -l /etc/rc3.d/ |grep old

lrwxrwxrwx  1 root root 17 Aug 30 12:38 S99oldboyd -> ../init.d/oldboyd