Can 'sudo apt-get remove [write]' destroy my Ubuntu?
The correct command to remove a package named write
is:
sudo apt remove write
[write]
is a character set matching the characters “w”, “r”, “i”, “t” and “e” and as matching is done by substring by apt
. The command you ran thus matched all packages with one of these characters in it, which of course are a lot. To quote apt
’s output listing just the essential ones:
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!'
The multiple warnings as well as the necessity to literally type
Yes, do as I say!
are security means in place to keep you from destroying your system, as the system’s package manager apt
is perfectly capable of doing that. Any command run with sudo
should be run carefully and thoughtfully, but don’t fret: Nearly every experienced user of Ubuntu broke their system at least once, in fact that’s part of the fun if you ask me.
Further reading
- this detailed answer to apt-get remove with wildcard removed way more than expected. why?
To add to what other people have said, you will see the syntax that the blogger used in their post quite often.
There are pretty consistent standards that are used when writing documentation on how to use commands. In every manual page, you'll see pretty much the same structure.
If something is optional, it is usually in brackets. ls [folder]
(you don't need to give ls a folder, but you can. Thus, optional).
If something is a file or email, you will usually see it in angle brackets. <likeThis.php>
If you have an choice between a finite number of things (i.e Months), you'll see it in braces like this: {September,October,November,December}
With any one of these, you may see ...
which denotes that multiple of this can be given.
And finally, if something is absolutely mandatory, you'll see its documentation listed out and probably underlined. For instance, man mv
, mv's manual, says this:
mv [OPTION]... [-T] SOURCE DEST
Technically speaking, the package name (write) isn't a required part of the command. Try it. apt-get install
or apt-get remove
will just run and exit the program successfully. That's one reason it could be presented in brackets on that blog.
Before doing an sudo apt-get
, it is wise to do a simulation:
$ apt-get remove [write] -s | wc -l
65280
There are nearly 65,280 packages that qualify for removal if installed on your system. [write]
is a search pattern for Regex matching causing every package to be selected if it contains:
- The letter
w
orr
ori
ort
ore
Output is piped to the Word Count command with | wc -l
. Output lines from apt-get
are suppressed by wc
. The -l
switch instructs wc
to only print count of lines and not word count or character count.
Simulation is specified with the -s
flag. You can also use the --simulate
flag for greater readability. Another advantage of a simulation is you don't need sudo
powers which many of us have learned can be dangerous at times.
To get an idea of the package names involved pipe output to the less
command:
$ 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 ....)