59

I wanted to remove my 'write' app, so I found this on a site: To remove a package type:

sudo apt-get remove [package_name]

So I typed:

sudo apt-get remove [write]

And afterwards I agreed on the prompt: 'yes, do what I say!' or something like that. And voila! My Ubuntu was deleting! Can anybody tell me why?

5
  • 30
    A teachable moment about reading the complete output. Many of us have done something similar...once.
    – user535733
    May 9, 2019 at 17:25
  • 7
    A good tip if you are not sure what will happen is to use the flag --simulate or -s under apt or apt-get first - Example: sudo apt -s remove php7.2-pspell doesn't actually remove that. Just shows you what would get removed/affected (if installed). Same for 'install'.
    – B. Shea
    May 9, 2019 at 21:51
  • touch w first to save yourself some grief ;-). May 10, 2019 at 16:34
  • @B.Tanner I’m glad to hear that my answer does actually help instead of just polarizing. You’re always welcome in the AU general chat room in case you have further (or other) questions or just want to say hello!
    – dessert
    May 10, 2019 at 17:38
  • Also a good lesson about the notation conventions in man pages. May 12, 2019 at 3:35

3 Answers 3

92

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

1
  • 1
    Comments are not for extended discussion; this conversation has been moved to chat.
    – Thomas Ward
    May 10, 2019 at 21:31
15

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.

9

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 or r or i or t or e

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 ....)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .