• 如何在 Linux 中删除超大的(100-200GB)文件


    一、IO调度策略

    1.1、idle

    空闲磁盘调度;该调度策略是在当前系统没有其他进程需要进行磁盘IO时,才能进行磁盘;因此该策略对当前系统的影响基本为0;当然,该调度策略不能带有任何优先级参数;

    1.2、Best effort

    是缺省的磁盘IO调度策略;
        (1)该调度策略可以指定优先级参数(范围是0~7,数值越小,优先级越高);
        (2)针对处于同一优先级的程序将采round-robin方式;
        (3)对于best effort调度策略,8个优先级等级可以说明在给定的一个调度窗口中时间片的大小;
        (4)目前,普调用户(非root用户)是可以使用该调度策略;
        (5)在内核2.6.26之前,没有设置IO优先级的进程会使用“none”作为调度策略,但是这种策略使得进程看起来像是采用了best effort调度策略,因为其优先级是通过关于   cpu nice有关的公式计算得到的:io_priority = (cpu_nice + 20) /5
        (6)在内核2.6.26之后,如果当前系统使用的是CFQ调度器,那么如果进程没有设置IO优先级级别,将采用与内核2.6.26之前版本同样的方式,推到出io优先级级别;

    1.3、Real time

    实时调度策略,如果设置了该磁盘IO调度策略,则立即访问磁盘,不管系统中其他进程是否有IO。因此使用实时调度策略,需要注意的是,该访问策略可能会使得其他进程处于等待状态;

    二、ionice命令-设置排程优先级

    2.1、安装

    1. [root@docker][19:43:12][OK] ~
    2. #yum provides */ionice
    3. Loaded plugins: fastestmirror
    4. Loading mirror speeds from cached hostfile
    5. * base: mirrors.aliyun.com
    6. * epel: mirror.01link.hk
    7. * extras: mirrors.aliyun.com
    8. * updates: mirrors.aliyun.com
    9. epel/x86_64/filelists_db | 12 MB 00:00:08
    10. extras/7/x86_64/filelists_db | 276 kB 00:00:01
    11. updates/7/x86_64/filelists_db | 10 MB 00:00:42
    12. util-linux-2.23.2-65.el7.i686 : A collection of basic system utilities
    13. Repo : base
    14. Matched from:
    15. Filename : /usr/bin/ionice
    16. Filename : /usr/share/bash-completion/completions/ionice
    17. util-linux-2.23.2-65.el7.x86_64 : A collection of basic system utilities
    18. Repo : base
    19. Matched from:
    20. Filename : /usr/bin/ionice
    21. Filename : /usr/share/bash-completion/completions/ionice
    22. util-linux-2.23.2-65.el7_9.1.i686 : A collection of basic system utilities
    23. Repo : updates
    24. Matched from:
    25. Filename : /usr/bin/ionice
    26. Filename : /usr/share/bash-completion/completions/ionice
    27. util-linux-2.23.2-65.el7_9.1.x86_64 : A collection of basic system utilities
    28. Repo : updates
    29. Matched from:
    30. Filename : /usr/bin/ionice
    31. Filename : /usr/share/bash-completion/completions/ionice
    32. util-linux-2.23.2-65.el7.x86_64 : A collection of basic system utilities
    33. Repo : @anaconda
    34. Matched from:
    35. Filename : /usr/bin/ionice
    36. Filename : /usr/share/bash-completion/completions/ionice

    安装

    yum install util-linux-2.23.2-65.el7_9.1.x86_64 -y

    2.2、用法

    1. [root@docker][19:35:01][OK] ~
    2. #ionice --help
    3. ionice - sets or gets process io scheduling class and priority.
    4. Usage:
    5. ionice [OPTION] -p PID [PID...]
    6. ionice [OPTION] COMMAND
    7. Options:
    8. -c, --class <class> scheduling class name or number
    9. 0: none, 1: realtime, 2: best-effort, 3: idle
    10. -n, --classdata <num> scheduling class data
    11. 0-7 for realtime and best-effort classes
    12. -p, --pid=PID view or modify already running process
    13. -t, --ignore ignore failures
    14. -V, --version output version information and exit
    15. -h, --help display this help and exit

    2.3、示例

    1. —- Deleting Huge Files in Linux —–
    2. # ionice -c 3 rm /var/logs/syslog
    3. # ionice -c 3 rm -rf /var/log/apache

    注意:要使用安全的方法删除大档案,我们可以使 shred、wipe 以及 secure-deletion 工具包中的不同工具,而不是 rm 命令。

    三、Shred -覆盖文件以隐藏内容

    3.1、安装软件包

    yum install coreutils-8.22-24.el7_9.2.x86_64 -y

    3.2、命令及参数选项

    1. [root@192_168_209_128 ~]# shred --help
    2. Usage: shred [OPTION]... FILE...
    3. Overwrite the specified FILE(s) repeatedly, in order to make it harder
    4. for even very expensive hardware probing to recover the data.
    5. Mandatory arguments to long options are mandatory for short options too.
    6. -f, --force change permissions to allow writing if necessary
    7. -n, --iterations=N overwrite N times instead of the default (3)
    8. --random-source=FILE get random bytes from FILE
    9. -s, --size=N shred this many bytes (suffixes like K, M, G accepted)
    10. -u, --remove[=HOW] truncate and remove file after overwriting; See below
    11. -v, --verbose show progress
    12. -x, --exact do not round file sizes up to the next full block;
    13. this is the default for non-regular files
    14. -z, --zero add a final overwrite with zeros to hide shredding
    15. --help display this help and exit
    16. --version output version information and exit

    选项说明:

    • -z- 添加一个带有零的最终覆盖以隐藏切碎。
    • -v– 可以显示操作进度。
    • -u- 覆盖后截断和删除文件。
    • -n– 指定覆盖文件内容的次数(默认为 3)。

    3.3、示例

    shred覆盖文件以隐藏其内容,也可以选择删除它。

    1. [root@docker][19:51:03][OK] ~
    2. #shred -zvu -n 5 cuttingLog_bak
    3. shred: cuttingLog_bak: pass 1/6 (random)...
    4. shred: cuttingLog_bak: pass 2/6 (ffffff)...
    5. shred: cuttingLog_bak: pass 3/6 (random)...
    6. shred: cuttingLog_bak: pass 4/6 (000000)...
    7. shred: cuttingLog_bak: pass 5/6 (random)...
    8. shred: cuttingLog_bak: pass 6/6 (000000)...
    9. shred: cuttingLog_bak: removing
    10. shred: cuttingLog_bak: renamed to 00000000000000
    11. shred: 00000000000000: renamed to 0000000000000
    12. shred: 0000000000000: renamed to 000000000000
    13. shred: 000000000000: renamed to 00000000000
    14. shred: 00000000000: renamed to 0000000000
    15. shred: 0000000000: renamed to 000000000
    16. shred: 000000000: renamed to 00000000
    17. shred: 00000000: renamed to 0000000
    18. shred: 0000000: renamed to 000000
    19. shred: 000000: renamed to 00000
    20. shred: 00000: renamed to 0000
    21. shred: 0000: renamed to 000
    22. shred: 000: renamed to 00
    23. shred: 00: renamed to 0
    24. shred: cuttingLog_bak: removed

    四、Wipe —在 Linux 中安全擦除文件

    介绍:Linux wipe命令可以安全地从磁存储器中擦除文件,从而无法恢复。

    4.1、安装软件包

    rpm -ivh wipe-2.2.0-1.2.el7.rf.x86_64.rpm

    4.2、命令及参数选项

    1. [root@docker][19:58:11][OK] ~
    2. #wipe -h
    3. Wipe v2.2.0 - released January 10, 2004
    4. by Tom Vier <nester@users.sf.net>
    5. Usage is wipe [options] [file-list]
    6. Options: Default: wipe -ZdntVAkO -S512 -C4096 -l1 -x8 -p1
    7. -h -- help - display this screen
    8. -u -- usage
    9. -c -- show copyright and license
    10. -w -- show warranty information
    11. -i and -I -- enable (-i) or disable (-I) interaction - overrides force
    12. -f -- force file wiping and override interaction
    13. -r and -R -- recursion - traverse subdirectories
    14. -s -- silent - disable percentage and error reporting
    15. -v -- force verbose - always show percentage
    16. -V -- verbose - show percentage if file is >= 25K
    17. -d and -D -- delete (-d) or keep (-D) after wiping
    18. -n and -N -- delete (-n) or skip (-N) special files
    19. -k and -K -- lock (-k) or don't lock (-K) files
    20. -z -- zero-out file - single pass of zeroes
    21. -Z -- perform normal wipe passes
    22. -t and -T -- enable (-t) or disable (-T) static passes
    23. -a and -A -- write until out of space (-a) or don't (-A)
    24. -o[size] -O -- write to stdout (-o) or use files (-O)
    25. -B(count) -- block device sector count
    26. -S(size) -- block device sector size - default 512 bytes
    27. or stdout write length when used with -A
    28. -C(size) -- chunk size - maximum file buffer size in kilobytes (2^10)
    29. -l[0-2] -- sets wipe secure level
    30. -x[1-32] -X -- sets number of random passes per wipe or disables
    31. -p(1-32) -- wipe file x number of times
    32. -b(0-255) -- overwrite file with this value byte

    4.3、示例

    1. [root@docker][19:59:50][OK] ~
    2. #wipe -fi cuttingLog_bak
    3. wipe: destroy file `cuttingLog_bak'? y

    五、Linux 安全删除工具包

    Secure-delete是一个安全文件删除工具的集合,其中包含srm (secure_deletion) 工具,用于安全删除文件。

    5.1、安装软件包

    yum -y install srm-1.2.15-1.el7.x86_64

    5.2、命令及参数选项

    1. [root@docker][20:05:39][OK] ~
    2. #srm --help
    3. Usage: srm [OPTION]... [FILE]...
    4. Overwrite and remove (unlink) the files. By default use the 35-pass Gutmann
    5. method to overwrite files.
    6. -d, --directory ignored (for compatability with rm(1))
    7. -f, --force ignore nonexistant files, never prompt
    8. -i, --interactive prompt before any removal
    9. -x, --one-file-system do not cross file system boundaries
    10. -s, --simple overwrite with single pass using 0x00 (default)
    11. -P, --openbsd overwrite with three passes like OpenBSD rm
    12. -D, --dod overwrite with 7 US DoD compliant passes
    13. -E, --doe overwrite with 3 US DoE compliant passes
    14. -G, --gutmann overwrite with 35-pass Gutmann method
    15. -C, --rcmp overwrite with Royal Canadian Mounted Police passes
    16. -r, -R, --recursive remove the contents of directories
    17. -v, --verbose explain what is being done
    18. -h, --help display this help and exit
    19. -V, --version display version information and exit

    5.3、示例

    1. #srm -vf cuttingLog_bal
    2. srm: removing cuttingLog_bal
  • 相关阅读:
    Java资深架构师详解java进阶技术体系与主流架构思维(建议入手)
    韩信点兵:求韩信一共有多少兵
    Java中的this关键字
    RAFT 算法简述
    vue3手写一个轮播图
    Redis 哨兵模式的实现详解
    PyQt5快速开发与实战 3.1 Qt Designer快速入门
    2、Jvm类加载器和双亲委派机制
    Javascript【触屏事件、移动端常见特效、移动端常用开发插件、移动端常用开发框架】
    音乐播放
  • 原文地址:https://blog.csdn.net/zfw_666666/article/details/127926011