“sudo apt-get remove [write]”会破坏我的 Ubuntu 吗?

“sudo apt-get remove [write]”会破坏我的 Ubuntu 吗?

我想删除我的“写入”应用程序,因此我在一个网站上找到了这个:要删除包类型:

sudo apt-get remove [package_name]

于是我输入:

sudo apt-get remove [write]

之后我同意了提示:“是的,按我说的做!”或类似的话。然后瞧!我的 Ubuntu 被删除了!有人能告诉我为什么吗?

答案1

删除名为的包的正确命令write是:

sudo apt remove write

[write]是匹配字符“w”、“r”、“i”、“t”和“e”的字符集,匹配是通过子字符串进行的apt。因此,您运行的命令匹配所有包含以下字符之一的包,当然是很多。引用apt的输出仅列出必要的内容:

WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  apt adduser (due to apt) gpgv (due to apt) ubuntu-keyring (due to apt) libapt-pkg5.0 (due to apt) libc6 (due to apt) libgcc1 (due to apt) libgnutls30 (due to apt) libseccomp2 (due to apt)
  libstdc++6 (due to apt) base-files base-passwd libdebconfclient0 (due to base-passwd) bash libtinfo5 (due to bash) debianutils (due to bash) bsdutils libsystemd0 (due to bsdutils) coreutils
  libacl1 (due to coreutils) libattr1 (due to coreutils) libselinux1 (due to coreutils) dash dpkg (due to dash) diffutils libbz2-1.0 (due to dpkg) liblzma5 (due to dpkg) libzstd1 (due to dpkg)
  zlib1g (due to dpkg) tar (due to dpkg) e2fsprogs libblkid1 (due to e2fsprogs) libcom-err2 (due to e2fsprogs) libext2fs2 (due to e2fsprogs) libss2 (due to e2fsprogs) libuuid1 (due to e2fsprogs) fdisk
  libfdisk1 (due to fdisk) libmount1 (due to fdisk) libncursesw5 (due to fdisk) libsmartcols1 (due to fdisk) findutils grep libpcre3 (due to grep) install-info (due to grep) gzip hostname init
  systemd-sysv (due to init) init-system-helpers (due to init) perl-base (due to init-system-helpers) libc-bin login libaudit1 (due to login) libpam0g (due to login) libpam-runtime (due to login)
  libpam-modules (due to login) mount util-linux (due to mount) ncurses-base ncurses-bin sed sysvinit-utils libudev1 (due to util-linux)
0 upgraded, 0 newly installed, 2503 to remove and 0 not upgraded.
After this operation, 7238 MB disk space will be freed.
You are about to do something potentially harmful.
To continue type in the phrase 'Yes, do as I say!'

多次警告以及逐字输入的必要性

是的,按我说的做!

有安全措施来防止您破坏系统,因为系统的包管理器apt完全有能力做到这一点。任何命令的运行sudo都应谨慎而周到,但不要担心:几乎每个有经验的 Ubuntu 用户都至少破坏过一次他们的系统,事实上,如果你问我,这也是乐趣的一部分。

进一步阅读

答案2

除了其他人所说的内容之外,您还会经常看到博主在其帖子中使用的语法。

在编写有关如何使用命令的文档时,使用的标准非常一致。在每个手册页中,您都会看到几乎相同的结构。

如果某事选修的,它通常在括号中。ls [folder](您不需要给 ls 一个文件夹,但您可以。因此,可选)。

如果某事一份文件或者电子邮件,您通常会在尖括号中看到它。<likeThis.php>

如果你有一个在有限数量的事物之间做出选择(即月份),您会看到它出现在这样的大括号中:{September,October,November,December}

通过其中任何一种,您都可以看到...哪个表示可以给出多个。

最后,如果某件事是绝对必要的,你会看到其文档被列出并且可能带有下划线。例如,man mvmv 的手册中这样写道:

mv [OPTION]... [-T] SOURCE DEST

从技术上讲,包名称 (write) 不是命令的必需部分。试试看。apt-get install或者apt-get remove只会运行并成功退出程序。这就是它可以在该博客中用括号显示的原因之一。

答案3

在执行之前sudo apt-get,最好先进行模拟:

$ apt-get remove [write] -s | wc -l
65280

有近65,280符合移除条件的软件包如果安装在您的系统上。[write]是搜索模式 正则表达式匹配如果每个包包含以下内容,则将其选中:

  • 字母write

输出通过管道传输到字数命令带有| wc -l。 的输出行apt-get被 抑制wc。 该-l开关指示wc仅打印行数,而不打印字数或字符数。

模拟使用标志指定-s。您还可以使用标志--simulate来提高可读性。模拟的另一个优点是您不需要sudo权力,我们许多人都知道,权力有时可能会很危险。

要了解涉及管道输出到less命令的包名称:

$ apt-get remove [write] --simulate | less

NOTE: This is only a simulation!
      apt-get needs root privileges for real execution.
      Also keep in mind that locking is deactivated,
      so don't depend on the relevance to the real current situation!
Reading package lists...
Building dependency tree...
Reading state information...
Package 'libpam-pin' is not installed, so not removed
Package 'activity-log-manager-common' is not installed, so not removed
Package 'libnet-patricial-perl' is not installed, so not removed
Package 'pe' is not installed, so not removed

   (.... Plus 65,269 more packages ....)

相关内容