dpkg 删除了哪些目录?

dpkg 删除了哪些目录?

在浏览文件系统时,我遇到了一个名为的文件.placeholder/etc/cron.d/文件中写入以下内容:

#DO NOT EDIT OR REMOVE
#This file is a simple placeholder to keep dpkg from removing this directory

所以我想知道,它会dpkg随意删除目录吗?或者更准确地说,它会dpkg删除哪些类型的目录?

答案1

dpkg删除空目录,清理您删除的软件包1.placeholder 。您在各个相关目录中看到的这些文件cron归软件包所有cron。当然,软件包cron不会向这些目录添加任何作业。因此,它们本身就是空目录。但是,其他软件包可以将文件放入这些目录中以激活 cron 作业,无论是直接还是通过脚本。

当您清除所有已安装的添加 cron 作业的软件包时会发生什么?然后dpkg将尝试删除这些现在为空的目录以进行清理。为了防止这种情况,cron添加.placeholder文件。sudo将 a 添加README/etc/sudoers.d

相应地,dpkg不会删除非空目录。如果:

  1. 某个目录归某个包所有,并且
  2. 你手动添加了一个文件,或者某个包添加了一个生成的文件到该目录,然后,
  3. 删除了第一个包,

dpkg会警告你它不会删除该非空目录。例如:

$ dpkg -S /etc/php5
php5-cli, php5-json: /etc/php5
$ sudo apt-get remove --purge php5-cli
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED
  php5-cli*
0 to upgrade, 0 to newly install, 1 to remove and 8 not to upgrade.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 
(Reading database ... 479105 files and directories currently installed.)
Removing php5-cli (5.6.11+dfsg-1+deb.sury.org~trusty+1) ...
Purging configuration files for php5-cli (5.6.11+dfsg-1+deb.sury.org~trusty+1) ...
$ sudo apt-get remove --purge php5-json      
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED
  php5-json*
0 to upgrade, 0 to newly install, 1 to remove and 8 not to upgrade.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 
(Reading database ... 479104 files and directories currently installed.)
Removing php5-json (1.3.7-1+deb.sury.org~trusty+1) ...
Purging configuration files for php5-json (1.3.7-1+deb.sury.org~trusty+1) ...
WARN: php5-common has been removed, you need to cleanup /etc/php5 yourself.
dpkg: warning: while removing php5-json, directory '/etc/php5/mods-available' not empty so not removed

各种 PHP 模块已通过编程将文件添加到/etc/php5,因此dpkg并没有删除该目录,尽管似乎拥有该目录的最后一个包正在被清除。

为了对比,我重新安装了php5-json,它带来了一个更新版本,php5-common现在也拥有/etc/php5,以前它以编程方式添加了文件:

$ dpkg -S /etc/php5                      
php5-json, php5-common: /etc/php5
$ sudo apt-get purge php5-{readline,common,mysql} 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'php5-mysql' is not installed, so not removed
The following packages will be REMOVED
  php5-common* php5-json* php5-readline*
0 to upgrade, 0 to newly install, 3 to remove and 8 not to upgrade.
After this operation, 1,336 kB disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 479151 files and directories currently installed.)
Removing php5-json (1.3.7-1+deb.sury.org~trusty+1) ...
Purging configuration files for php5-json (1.3.7-1+deb.sury.org~trusty+1) ...
Removing php5-readline (5.6.11+dfsg-1+deb.sury.org~trusty+1) ...
Purging configuration files for php5-readline (5.6.11+dfsg-1+deb.sury.org~trusty+1) ...
Removing php5-common (5.6.13+dfsg-1+deb.sury.org~trusty+3) ...
Purging configuration files for php5-common (5.6.13+dfsg-1+deb.sury.org~trusty+3) ...
$ ls /etc/php5
ls: cannot access /etc/php5: No such file or directory

1对于 中的文件的情况/etc,当您清除包时会发生这种情况。

相关内容