软硬链接、文件删除原理、linux中的三种时间、chkconfig优化
第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优化的更多相关文章
- linux中的三种时间
mtime [修改时间] 文件/目录的修改时间 ctime [属性修改时间] 文件目录的属性的修改时间 atime [访问时间]文件/目录的访问时间 stat 123.txt File: `1 ...
- Linux 下的三种时间介绍
Linux 下的三种时间介绍: Access Time:简写为atime,表示文件访问的时间,当文件内容被访问时,更新atime时间 Modify Time:简写为mtime,表示文件内容修改的时间, ...
- Linux 文件删除原理_009
***了解Linux文件删除原理先了解一下文件inode索引节点,每个文件在Linux系统里都有唯一的索引节点(身份证号) inode.如果文件存在硬链接,那这个文件和这个文件的硬链接的inode是相 ...
- 在Linux中,没有文件创建时间的概念。只有文件的访问时间、修改时间、状态改变时间
在Linux中,没有文件创建时间的概念.只有文件的访问时间.修改时间.状态改变时间.也就是说不能知道文件的创建时间.但如果文件创建后就没有修改过,修改时间=创建时间:如果文件创建后,状态就没有改变过, ...
- 【Linux】windows下编写的脚本文件,放到Linux中无法识别格式
注意:我启动的时候遇到脚本错误 » sh startup.sh -m standalone tanghuang@bogon : command not found : command not foun ...
- Linux中的两种守护进程stand alone和xinetd
Linux中的两种守护进程stand alone和xinetd --http://www.cnblogs.com/itech/archive/2010/12/27/1914846.html#top 一 ...
- Linux下文件的三种时间标记(atime ctime mtime)
在windows下,一个文件有:创建时间.修改时间.访问时间. 在Linux下,一个文件有:状态改动时间.修改时间.访问时间. 1)查看文件(或文件夹)的三种时间标记 (stat 命令) Access ...
- 命令stat anaconda-ks.cfg会显示出文件的三种时间状态(已加粗):Access、Modify、Change。这三种时间的区别将在下面的touch命令中详细详解:
7.stat命令 stat命令用于查看文件的具体存储信息和时间等信息,格式为"stat 文件名称". stat命令可以用于查看文件的存储信息和时间等信息,命令stat anacon ...
- Linux下文件的三种时间标记:访问时间、修改时间、状态改动时间 (转载)
在windows下,一个文件有:创建时间.修改时间.访问时间. 而在Linux下,一个文件也有三种时间,分别是:访问时间.修改时间.状态改动时间. 两者有此不同,在Linux下没有创建时间的概念,也就 ...
随机推荐
- 为什么自学java的人99%都学不会?
在学习java这条路上,有一类自学的学员,总让我感慨良多.这类学员,往往每天表现非常勤奋的学习,但学会的人却很少.他们极期勤奋,那么努力的学,也很认真,为什么就是学不会java呢? 通过小橙子我的大量 ...
- 初次就这么给了你(Django-rest-framework)
Django-Rest-Framework Django-Rest框架是构建Web API强大而灵活的工具包. 简单粗暴,直奔主题. pip install django pip install dj ...
- JAVA 反射(1)
getDeclaredField是可以获取一个类的所有字段. getField只能获取类的public 字段.
- SQL语句表名或者字段名和保留字冲突解决方法
最近开发遇到一个很奇葩的问题,简单做一下笔记 select * from Add ... 以上SQL语句会报错. 原因Add是表名,SQL语句保留字中又有Add 解决方法: select * from ...
- vs 或 Sql server2012连接Sql server时出现的问题:已成功与服务器建立连接,但在登陆过程中发生错误
以前连接是正常的,就这两天连不上了.(没有耐心的直接看末尾解决办法) 错误消息如下: 1.尝试读取或写入受保护的内存.这通常指示其他内存已损坏.(System.Data) 2.已成功与服务器建立连接, ...
- C# 使用Parallel并行开发Parallel.For、Parallel.Foreach实例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...
- python使用装饰器@函数式化django开发
django是一个python web开发的框架.作为一个框架MVC的架构已经实现起来了.但是编码的时候你经常要进行进一步的抽象. AOP是一种称为面向切面的开发思想,意思是将部分功能代码在运行时动态 ...
- 一款好用的软件easyUI
easyui是一种基于jQuery的用户界面插件集合. easyui为创建现代化,互动,JavaScript应用程序,提供必要的功能. 使用easyui你不需要写很多代码,你只需要通过编写一些简单HT ...
- 语音识别完成诗句的查询功能,iOS AVSpeechSynthesis语音输出结果的诗歌APP
前言 当前的APP的查询都是使用手动输入,不仅效率低,而且查询的语句的限制比较大,不能够方便的扩展. 如果能方便的扩展查询语句,那么APP的使用就会有很大的灵活性.可以设计各种问句和语句,可以方便的和 ...
- win10 uwp 获得缩略图
有时候需要获得文件或视频的缩略图. 本文提供两个方法,用于获得文件的缩略图和截取视频指定时间的显示图片. 文件缩略图 如果有一个文件需要获得缩略图,可以使用 GetThumbnailAsync 或 G ...