What does leading tilde mean in this argument to apt?

I found this snippet from the ROS installation tutorial.

https://docs.ros.org/en/iron/Installation/Ubuntu-Install-Debians.html

At the bottom, it says to remove all packages, executing the following code snippet:

sudo apt remove ~nros-iron-* && sudo apt autoremove

I want to know what the leading tilde and n signify. I ran apt search ~nros expecting ~n to function as an escape character equivalent to newline, but this did not happen (it also listed packages where ros was in the middle of the package name). Maybe apt search and apt remove parse text differently; I am unsure.

Asked By: diomed

||

Since version 2.0, apt has supported a search syntax inspired by that of the Debian aptitude tool, and described in the apt-patterns manual page. Specifically ~nname is the short-form of ?name(name)

   ?name(REGEX), ~nREGEX
       Selects packages where the name matches the given regular expression.
Answered By: steeldriver

The leading tilde (~) in the command sudo apt remove ~nros-iron-* && sudo apt autoremove is used as a shorthand for the apt search command. Specifically, ~nname is the short-form of ?name(name) ?name(REGEX), ~nREGEX Selects packages where the name matches the given regular expression.

So, in this case, ~nros-iron-* selects all packages whose name contains "ros-iron".

The apt remove command uninstalls the specified packages, but not their configuration files or data files. If you want to remove everything related to the package, you can use the apt purge command instead.

The apt autoremove command removes orphaned packages, i.e. installed packages that used to be installed as an dependency, but aren’t any longer.

Answered By: Baft Tabaku