用途说明

Linux内核为了达到最佳的磁盘操作效率,会把需要写入到磁盘的数据现在内存中缓存起来,在合适的时候才真正写入到磁盘中,这在绝大多数情况都是没有任何问题的,而且提高了系统的效率,但是如果系统当机、掉电,就会有些文件内容不会保存下来。在Linux系统关机或者重启时,会自动把缓冲区的内容 自动同步到磁盘中。我们也可以手工去执行sync命令,强制将内存中的文件缓冲内容写到磁盘,这个命令是通过调用sync系统调用来实现的。(flush file system buffersSynchronizedata on disk with memoryForce changed blocks to disk, update the superblock.`sync' writes any data buffered in memory out to disk.  This caninclude (but is not limited to) modified superblocks, modified inodes, anddelayed reads and writes.  This must be implemented by the kernel; The`sync' program does nothing but exercise the `sync' system call.  The kernel keeps data in memory to avoid doing (relatively slow) disk reads andwrites.  This improves performance, but if the computer crashes, data maybe lost or the file system corrupted as a result. The `sync' command ensureseverything in memory is written to disk.)但是,我认为一般情况下我们是没有必要去执行这个命令的,因为Linux内核会尽快让内存中的数据自动同步到磁盘上去,而且,谁又会知道什么 时候会掉电或当机呢?

 

常用方式

格式:sync

强制将内存中的文件缓冲内容写到磁盘。

 

使用示例

示例一

[root@web ~]# sync

[root@web ~]#

 

示例二

问题思考

1. 在以前使用Unix(SCOUnix, SunOS)的时候,那些人教我们使用sync命令,所以记住了它,有些文章也说在关闭或重启系统之前要多次执行sync命令,有的说要2此,有的说最好4次。各位看官,你们怎么看待这个问题,欢迎留言赐教。


GitHub 加速计划 / li / linux-dash
11
2
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 5 年前
5def40a3 Add host customization support for the NodeJS version 5 年前
Logo

新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐