第1章 软硬链接

1.1 硬链接

1.1.1 含义

多个文件拥有相同的inode号码

硬链接即文件的多个入口

1.1.2 作用

防止你误删除文件

1.1.3 如何创建硬链接

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

1.2 软连接

1.2.1 含义

为了快捷,省事,方便使用

软连接中存放的是源文件的位置

1.2.2 创建软连接

使用ln -s 命令创建软连接

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

查看软硬链接的inode号不相同

但是同时指向的是同一文件

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

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

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

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

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

1.3 软连接与硬链接的区别

1.3.1 含义

软链接:

软连接相当于快捷方式

里面存放的是源文件的位置

硬链接:

在同一个分区中,多个文件拥有相同的inode号

1.3.2 创建方式不同

ln 创建硬链接

ln -s 软连接

1.3.3 不同的特点

1)软连接可以随意创建

2)不能对目录创建硬链接

3)对文件创建硬链接可以防止文件被误删除

1.3.4 如何删除

1)删除文件的硬链接,文件可以继续使用

2)只有把这个文件的所有硬链接都删除才可

3)只删除源文件软连接无法使用

4)只删除软连接对文件没有影响

第2章 文件删除原理

2.1 彻底删除一个文件

1.硬链接数为0 与这个文件有关的所有硬链接都被删除。

a)       使用rm目录进行删除

2.     进程调用数为0,没有人在使用这个文件才能释放磁盘空间。

a)       使用lsof 查看谁在使用这文件

b)      重启对应的软件/服务就能释放磁盘

2.2 查看某个文件是否总有人在用

使用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

2.3 重启对应的软件/服务

找到软件对应的管理地址,让软件重启,释放空间。

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

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

2.4 磁盘空间满了(三种情况)

inode满了……查找出系统目录比较大(1M)

block满了……使用du -sh /* 一层一层找,把较大的文件删除

硬链接数为0,进程调用数不为0

使用  lsof |grep delete 查看占用的文件

2.5 故障案例

没有被彻底删除-硬链接数为0,进程调用数不为零

2.5.1 环境

向 /var/log/message中放入大量数据

seq 100000000 >>/var/log/messages

2.5.2 查看此时此刻磁盘使用情况

[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

2.5.3 删除文件

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

2.5.4 检查空间没有被释放

[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

2.5.5 查看被删除(硬链接数为0)但是还被进程调用的文件

[root@znix apache]# lsof |grep delete

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

2.5.6 重启对应的服务

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

Shutting down system logger:                               [  OK  ]

Starting system logger:                                    [  OK  ]

查看磁盘空间

[root@znix apache]# df -h

Filesystem      Size  Used Avail Use% Mounted on

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

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

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

第3章 找出某个文件的其他的硬链接

使用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

第4章 三种时间戳

4.1 含义

Modify   mtime修改时间 (最常用) 文件的内容 增加 删除 修改改变

Change   ctime属性变更时间        文件属性发生改变时更改

Access   atime访问时间            查看文件的时间 (只有文件内容有修改时才会改变)

4.2 使用stat命令查看文件的信息

[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

4.3 修改mtime&change

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

[root@znix ~]# stat oldboy.txt

File: `oldboy.txt'

Size: 241         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-30 11:40:57.384368932 +0800

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

4.4 修改ctime (属性变更时间)

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

[root@znix ~]# stat oldboy.txt

File: `oldboy.txt'

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

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

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

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

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

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

4.5 atime修改

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

123

[root@znix ~]# stat oldboy.txt

File: `oldboy.txt'

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

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

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

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

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

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

第5章 chkconfig命令相关

chkconfig命令实际上控制的是/etc/rc3.d/(3运行模式下)下的软连接。通过不通的软连接,实现不通的控制。实际受/etc/init.d/下脚本的关系。

5.1 执行chkconfig iptables on & chkconfig iptables off之后发生了什么?

执行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

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

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

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

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

iptables 开机自启动    软连接   S开头

iptables 开机不自启动 软连接   K开头

5.2 让一个软件开机自启动

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

2)通过chkconfig 管理命令或脚本,让他开机自启动

5.3 如何让一个服务或命令通过chkconfig管理

5.3.1 脚本必须放在/etc/init.d/目录下面

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

5.3.2 必须写出chkconfig格式

写出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

5.3.3 给这个脚本添加上执行的权限

使用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

5.3.4 添加脚本到chkconfig管理

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

5.3.5 查看状态

改为开机自启动

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

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

5.3.6 查看/etc/rc3.d/目录生成相对应的软连接

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

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

软硬链接、文件删除原理、linux中的三种时间、chkconfig优化的更多相关文章

  1. linux中的三种时间

    mtime [修改时间] 文件/目录的修改时间 ctime  [属性修改时间] 文件目录的属性的修改时间 atime  [访问时间]文件/目录的访问时间 stat 123.txt   File: `1 ...

  2. Linux 下的三种时间介绍

    Linux 下的三种时间介绍: Access Time:简写为atime,表示文件访问的时间,当文件内容被访问时,更新atime时间 Modify Time:简写为mtime,表示文件内容修改的时间, ...

  3. Linux 文件删除原理_009

    ***了解Linux文件删除原理先了解一下文件inode索引节点,每个文件在Linux系统里都有唯一的索引节点(身份证号) inode.如果文件存在硬链接,那这个文件和这个文件的硬链接的inode是相 ...

  4. 在Linux中,没有文件创建时间的概念。只有文件的访问时间、修改时间、状态改变时间

    在Linux中,没有文件创建时间的概念.只有文件的访问时间.修改时间.状态改变时间.也就是说不能知道文件的创建时间.但如果文件创建后就没有修改过,修改时间=创建时间:如果文件创建后,状态就没有改变过, ...

  5. 【Linux】windows下编写的脚本文件,放到Linux中无法识别格式

    注意:我启动的时候遇到脚本错误 » sh startup.sh -m standalone tanghuang@bogon : command not found : command not foun ...

  6. Linux中的两种守护进程stand alone和xinetd

    Linux中的两种守护进程stand alone和xinetd --http://www.cnblogs.com/itech/archive/2010/12/27/1914846.html#top 一 ...

  7. Linux下文件的三种时间标记(atime ctime mtime)

    在windows下,一个文件有:创建时间.修改时间.访问时间. 在Linux下,一个文件有:状态改动时间.修改时间.访问时间. 1)查看文件(或文件夹)的三种时间标记 (stat 命令) Access ...

  8. 命令stat anaconda-ks.cfg会显示出文件的三种时间状态(已加粗):Access、Modify、Change。这三种时间的区别将在下面的touch命令中详细详解:

    7.stat命令 stat命令用于查看文件的具体存储信息和时间等信息,格式为"stat 文件名称". stat命令可以用于查看文件的存储信息和时间等信息,命令stat anacon ...

  9. Linux下文件的三种时间标记:访问时间、修改时间、状态改动时间 (转载)

    在windows下,一个文件有:创建时间.修改时间.访问时间. 而在Linux下,一个文件也有三种时间,分别是:访问时间.修改时间.状态改动时间. 两者有此不同,在Linux下没有创建时间的概念,也就 ...

随机推荐

  1. python django 使用 haystack:全文检索的框架

    haystack:全文检索的框架whoosh:纯Python编写的全文搜索引擎jieba:一款免费的中文分词包 首先安装这三个包 pip install django-haystackpip inst ...

  2. Ubuntu 安装 SQL Server

    SQL Server现在可以在Linux上运行了!正如微软CEO Satya Nadella说的,"Microsoft Loves Linux",既Windows 10内置的Lin ...

  3. Linux入门之常用命令(13) date

    在linux shell编程中,经常用到日期的加减运算 以前都是自己通过expr函数计算,很麻烦 其实date命令本身提供了日期的加减运算 非常方便.例如:得到昨天的时间date +%Y%m%d -- ...

  4. U盘中毒无限蓝屏重启的解决办法

    开门见山,这个帖子只针对U盘中毒导致的以下两种症状: 1.win10系统无法进入并且要求初始化,卸载所有第三方应用 2.win7系统无限蓝屏重启): 其他的硬件故障不在本次讨论范围之内. 说明以下.上 ...

  5. POJ 3923 Ugly Windows(——考察思维缜密性的模拟题)

    题目链接: http://poj.org/problem?id=3923 题意描述: 输入一个n*m的屏幕 该屏幕内有至少一个对话框(每个对话框都有对应的字母表示) 判断并输出该屏幕内处于最表层的对话 ...

  6. PHP连接SQL Server数据库

    服务环境:apache2.2 + PHP5.2 + Sql Server 2008 R2 一.所需库和工具1.SQLSRV20.EXE (php5.2版本对应的的Sql Server扩展库)注释:ph ...

  7. 苹果手机使用替代onkeyup的方法

    今天项目有这个问题,苹果手机就不行   使用keyup事件检测文本框内容:  $('#keyup_i').bind('keyup', function(){         $('#keyup_s') ...

  8. HDU1142 A Walk Through the Forest(最短路+DAG)

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...

  9. 基于java的后台截图功能的实现

    Java后台截图功能的实现 背景介绍: 在近期开发的可视化二期项目中的邮件项目中,邮件中的正文中含有图片.该图片的产生是将一些html网页转为图片格式,刚开始考虑使用第三方组件库html2image和 ...

  10. c# 多线程传递参数以及任务

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...