Andromeda Computer - Displaying items by tag: linux mint
Thursday, 13 June 2019 20:57

Learn how to: Add a user to a group in Linux

BANNERGnulinuxrocks

 

Users are arranged into different groups on all Linux-based systems. The whole idea behind this is that it makes the administration of the system easier, as the users can be arranged into different groups, and can be granted different permissions as required by the system administrator. The same user can be included in different groups, and the same file can be given different permissions based on the groups.

 

This article is about how to add a user to a group.

The instructions will work well on most Linux distros, including Ubuntu, CentOS, Debian, Fedora, Linux Mint, etc.

 

Different scenarios when adding a user to a group

 

Adding a user to a group has many factors to consider. Some are:

  • Existence of the user – The commands are usually different depending on whether the user already exists on the system,
  • Group category – The main group that the user belongs to is called the primary group. Generally, this group has the same name as that of the user. The other groups that the user belongs to are called the secondary groups. There are other groups too, that a user is not a part of, at all.
  • User permissions – This is a major factor, as only the super users can add any user to any given group. This permission limits the users in terms of which groups and which users they can edit.

Keeping all these factors in mind, we are only presenting two commands in order to add users to groups. But this is being shown considering that the user entering these commands is a super user/root (can perform sudo). These are the commands:

To add new users to groups

First, and the only exception, to add new users to groups:

sudo useradd -G <group_name> <new_user_username>

The id command shows basic information about a user on the system. Therefore, to prove that the user doesn’t exist at first:

[email protected]:~$ id testuser
id: ‘testuser’: no such user
[email protected]:~$

Now we add a new user to an existing group:

[email protected]:~$ sudo useradd -G pulkit testuser
[email protected]:~$ id testuser
uid=1004(testuser) gid=1004(testuser) groups=1004(testuser),1000(pulkit)
[email protected]:~$

All the remaining scenarios – when a user already exists

Now the only condition is that the user should already exist on the system. All the remaining scenarios can be worked out with this command:

sudo gpasswd -a <user_name> <group_name>

If you want to remember this command, then you can create a new user before adding the user to the system. This can be done with:

sudo adduser <user_name>

Sample:

[email protected]:~$ sudo adduser testuser
Adding user `testuser' ...
Adding new group `testuser' (1001) ...
Adding new user `testuser' (1001) with group `testuser' ...
Creating home directory `/home/testuser' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for testuser
Enter the new value, or press ENTER for the default
        Full Name []: 
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is the information correct? [Y/n] y
[email protected]:~$ sudo gpasswd -a testuser pulkit
Adding user testuser to group pulkit
[email protected]:~$

Now checking if this worked:

[email protected]:~$ id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),1000(pulkit)
[email protected]:~$

Removing users from a group

This is not a part of adding users to groups, obviously, but an essential command to know if you’re managing groups. The command uses the same format as seen with the gpasswd command:

sudo gpasswd -d <user_name> <group_name>

Sample:

[email protected]:~$ sudo gpasswd -d testuser pulkit
[sudo] password for pulkit: 
Removing user testuser from group pulkit
[email protected]:~$ id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser)
[email protected]:~$

 

This removes the user from the given group, as shown.

 

You can test these commands out on a Linux server at Vultr.

 

Conclusion

Adding users to groups on Linux is an easy task, if you know what commands to use. You can essentially do everything using just one command, as long as you know how to use it. The gpasswd command is the simplest command to use for the task. The useradd or usermodcommands can be used as well, but they have a comparatively more complex syntax, and therefore not recommended for beginners.

We hope this article served its purpose. Let us know if you have any questions in the comments below.

BannerFinalGNULINUZROCKS

Published in GNU/Linux Rules!

linux-icon-t.jpg

We all know that we use cd command to move from one directory to another. To return back to the previous directory, we use “cd ..” or “cd <location_of_previous_directory>” commands. This is how I mostly navigate between directories until I found these trio commands, namely pushdpopd, and dirs. These three commands provides a way faster navigation between directories. Unlike cd command, pushd and popd commands are used to manage a stack of directories. Just enter into a directory and do something you want to do, and “pop” back to the previous directory quickly without having to type the long path name. dirs command is used to show the current directory stack, just like “ls” command. These trio commands are extremely useful when you’re working in a deep directory structure and scripts.

Still confused? No worries! I am going to explain these commands in layman terms with some practical examples.

Use Pushd, Popd And Dirs For Faster Navigation Between Directories

Pushd, popd ,and dirs commands are comes pre-installed, so let us just forget about the installation, and go ahead to see how to use them in real time.

Right now, I am in /tmp directory.

1.png

I am going to create ten directories, namely test1test2, …. test10 in /tmp directory.

As may already know, We can easily create multiple directories at once using mkdir command as shown below.

mkdir test1 test2 test3 test4 test5 test6 test7 test8 test9 test10

Or,

mkdir test{1,2,3,4,5,6,7,8,9,10}

Now, let us move to test3 directory. To do so, just type:

pushd test3

2.png

To know where you are now, just type:

dirs

Sample output:

/tmp/test3 /tmp /tmp

3.png

As you see in the above output, dirs command shows we have two directories in the stack now. Do something you wish to do in this directory. Once done, you can go back to your previous working directory using command:

popd

4.png

No need to mention the full path of previous directory. If you use cd command, you should type “cd ..” or “cd <full_path_name>” to go back to the /tmp directory. But, using popd command we can instantly move back to the previous working directory. It’s simple as that.

Let us go again to test8 directory. To do so, run:

pushd test8

Sample output:

/tmp/test8 /tmp /tmp

5.png

Let us go deep in the stack.

pushd /tmp/test10

Sample output:

/tmp/test10 /tmp/test8 /tmp /tmp

6.png

We’re now in test10 directory, and we have totally 3 directories (test10, test8 and tmp) in our stack. Did you also notice the direction? Each new directory is getting added to the left. When we start poping directories off, they will come from the left as well.

Now, if you want to move to the previous working directory i.e test8 using cd command, the command would be like below.

cd /tmp/test8

But it is not necessary though. We can do it more quickly by running the popd command.

popd

Sample output:

/tmp/test8 /tmp /tmp

7.png

As you see in the above output, we moved to the previous working directory without having to type full path (i.e /tmp/test8).

Now, let us pop again?

popd

Sample output:

/tmp /tmp

8.png

Finally, We came back to the directory where we started.

In this example, I have used just ten directories. So, It may seem it is no big deal. Think about twenty or more directories? Would you type “cd <path_name>” or “cd ..” each time to move between directories? Nope. It would be time consuming. Just use pushd command to change to any directory in the stack and move back to your previous working directory using popd command. Also, you can use dirs command at any time to show the current directory stack at any time. You can add a series of paths onto your stack and then navigate to them in the reverse order. This will save you lot of time when you are navigating around stack of directories.


Also read:


You know now how to effectively navigate between directories without using cd command. These commands comes in handy when you’re working with large directory stack. You can quickly move back and forth through x amount of directories, and these commands are much useful working with scripts too.

That’s all for now. If you know any other methods, feel free to share them in the comment section below. I will be here with another interesting guide soon.

Marielle Price

Published in GNU/Linux Rules!

This article explains how to list all the packages available in an Ubuntu, Linux Mint or Debian repository (installed and available for install), be it an official repository or a third-party source like a PPA, and so on.

Below you'll find 2 ways of listing packages from a repository: using a GUI or from the command line.

List all packages in a Debian, Ubuntu or Linux Mint repository using a GUI


If you want to list all the packages in a repository on your desktop, you can use Synaptic Package Manager. 

Synaptic is a graphical package management application for APT (APT being the main command line package manager for Debian and its derivatives).

If you don't have Synaptic installed, you can install it on Debian, Ubuntu, and any Debian or Ubuntu based Linux distribution, including elementary OS, Linux Mint and so on, by using this command:

sudo apt install synaptic


To list all the packages in a particular software repository using Synaptic, launch the application and click on Origin in the bottom left-hand side of its window. Next, select the repository for which you want to list all available packages (both installed and available for installation) from the list that's displayed in the left-hand side of Synaptic Package Manager.

For example, here's Synaptic showing all the packages available in the Google repository, listing Google Chrome stable, beta and unstable, as well as Google Earth Pro and EC:

Synaptic list all packages in a repository on Ubuntu or Debian


As you can see, all the software sources are listed here, including the official repositories. 

Launchpad PPA repositories are supported as well. Their name begins with LP-PPA, followed by the actual PPA name. Synaptic lists 2 entries for each PPA - make sure you select the PPA entry ending with /ubuntu-codename, for example /bionic/cosmic, etc. The entry ending in /now doesn't list all the available packages in the PPA.

This is a screenshot showing all the packages available in the Ubuntu Graphics Drivers PPA (for Ubuntu 18.10 Cosmic Cuttlefish, since that's what I'm using), including showing which are installed on my system:

Synaptic list all packages in a repository


I'm not sure why, but some packages are listed multiple times for PPA sources (and only for PPA repositories). That only a display thing, and it doesn't break any functionality.

List all packages in a repository in Ubuntu, Debian or Linux Mint from the command line


Listing all packages in a repository from the command line in Ubuntu, Debian or Linux Mint is a bit tricky, but still quite easy to do.

There are multiple ways of doing this from the command, but I'll only list one. The command to list all packages available in repository-name is the one that follows:

grep ^Package /var/lib/apt/lists/repository-name*_Packages | awk '{print $2}' | sort -u


I'll explain later on how to find out the repository name from /var/list/apt/lists and how to use it. Before that I'll explain what this command does:

  • grep ^Package ... searches for lines beginning with ^Package in the /var/lib/apt/lists/*_Packagesfile
  • awk '{print $2}' prints the second column for each line (so it filters out everything but the package name)
  • sort -u sorts the lines and outputs only unique lines (removes duplicates)


The first thing you need to do is find the name of the repository *_Packages file from /var/lib/apt/lists/. You can list all the repository _Packages files available in /var/lib/apt/lists/ by using a simple ls:

ls /var/lib/apt/lists/*_Packages


Since the results may be very long, you can run the command output through more for easier reading:

ls /var/lib/apt/lists/*_Packages | more


If you know part of the repository name (I'm using KEYWORD in the command below as the name), you can filter the ls results using grep, like this:

ls /var/lib/apt/lists/*_Packages | grep KEYWORD


For example, let's say you want to list all the packages in the official Tor repository, and you know the repository name must contain tor. In this case, you'd use this command to find out the _Packages filename from /var/lib/apt/lists/

ls /var/lib/apt/lists/*_Packages | grep tor


For short queries, some unrelated repositories might be displayed, but it's still easier to see what you're looking for using grep than listing all the repositories _Packages files.

Now that you know the _Packages filename, you can list all the packages available in that repository by issuing this command:

grep ^Package /var/lib/apt/lists/some-repository-amd64_Packages | awk '{print $2}' | sort -u


Use the file containing the architecture for which you want to list all available packages in that repository. The example above is for 64bit (amd64), but you could use i386 for 32bit, etc.

You don't need the complete repository _Packages filename. Back to my Tor repository example, the _Packages filename for Tor is deb.torproject.org_torproject.org_dists_cosmic_main_binary-amd64_Packages. In this case, you could use deb.torproject followed by *_Packages to simplify things, like this:

grep ^Package /var/lib/apt/lists/deb.torproject*_Packages | awk '{print $2}' | sort -u


Which outputs the following:

deb.torproject.org-keyring
tor
tor-geoipdb


Another example. Let's say you want to see all packages available in the Linux Uprising Oracle Java 11 PPA(ppa:linuxuprising/java). You can list them by using:

grep ^Package /var/lib/apt/lists/ppa.launchpad.net_linuxuprising_java*_Packages | awk '{print $2}' | sort -u


Which outputs this:

oracle-java11-installer
oracle-java11-set-default


To use this with other PPA repositories, replace linuxuprising with the first part of the PPA name, and java with the second part of the PPA name, and the command will list all the packages from that PPA (both installed and not installed).

You can also list all the packages available in all the PPA repositories you have added on your system, by using:

grep ^Package /var/lib/apt/lists/ppa.launchpad.net*_Packages | awk '{print $2}' | sort -u


For easy access, you could bookmark this command using Marker commands bookmark manager (while used primarily for searching, HSTR can bookmark commands as well).

Published in GNU/Linux Rules!

There are multiple ways of searching for packages available in the Debian, Ubuntu or Linux Mint from the command line, and in this article I'll cover aptapt-cache and aptitude. Use this to search in both package names and package descriptions, useful if either you're looking for a specific package but you don't know the exact package name, or if you need a tool for a particular purpose / task but you don't know the available options.

The major differences between using aptapt-cache and aptitude to search for available packages is their output and the sort order, as you'll see in the examples below. Also, aptitude may not be installed by default on your Debian-based Linux distribution.

I personally prefer apt-cache because of the easier to read output (and I don't need extra info usually - to see installed/available versions I can use apt-cache policy package-name); it also tends to display the results I'm looking for near the top.

Another thing to note is that apt and apt-cache search the apt software package cache, so they return both packages available in the repositories as well as DEB packages installed manually (not available in the repos), while aptitude only returns packages that are available in the repositories.

I. Search available packages using aptitude

aptitude is a Ncurses-based front-end for apt. This tool is usually not installed by default but you can install it in Debian, Ubuntu, Linux Mint and other Debian-based Linux distributions using this command:

sudo apt install aptitude


You can use aptitude to search for packages from the command line, like this:

aptitude search KEYWORD


Example:

$ aptitude search openssh

p   libconfig-model-openssh-perl                           - configuration editor for OpenSsh                                
p   libghc-crypto-pubkey-openssh-dev                       - OpenSSH key codec  
p   libghc-crypto-pubkey-openssh-dev:i386                  - OpenSSH key codec  
v   libghc-crypto-pubkey-openssh-dev-0.2.7-6af0a           -                    
v   libghc-crypto-pubkey-openssh-dev-0.2.7-6af0a:i386      -                    
p   libghc-crypto-pubkey-openssh-doc                       - OpenSSH key codec; documentation                                
p   libghc-crypto-pubkey-openssh-prof                      - OpenSSH key codec; profiling libraries                          
p   libghc-crypto-pubkey-openssh-prof:i386                 - OpenSSH key codec; profiling libraries                          
v   libghc-crypto-pubkey-openssh-prof-0.2.7-6af0a          -                    
v   libghc-crypto-pubkey-openssh-prof-0.2.7-6af0a:i386     -                    
p   libnet-openssh-compat-perl                             - collection of compatibility modules for Net::OpenSSH            
p   libnet-openssh-parallel-perl                           - run SSH jobs in parallel                                        
p   libnet-openssh-perl                                    - Perl SSH client package implemented on top of OpenSSH           
p   lxqt-openssh-askpass                                   - OpenSSH user/password GUI dialog for LXQt                       
p   lxqt-openssh-askpass:i386                              - OpenSSH user/password GUI dialog for LXQt                       
p   lxqt-openssh-askpass-l10n                              - Language package for lxqt-openssh-askpass                       
v   lxqt-openssh-askpass-l10n:i386                         -                    
i   openssh-client                                         - secure shell (SSH) client, for secure access to remote machines 
p   openssh-client:i386                                    - secure shell (SSH) client, for secure access to remote machines 
p   openssh-client-ssh1                                    - secure shell (SSH) client for legacy SSH1 protocol              
p   openssh-client-ssh1:i386                               - secure shell (SSH) client for legacy SSH1 protocol              
p   openssh-known-hosts                                    - download, filter and merge known_hosts for OpenSSH
p   openssh-server                                         - secure shell (SSH) server, for secure access from remote machines
p   openssh-server:i386                                    - secure shell (SSH) server, for secure access from remote machines 
p   openssh-sftp-server                                    - secure shell (SSH) sftp server module, for SFTP access from remote machines
p   openssh-sftp-server:i386                               - secure shell (SSH) sftp server module, for SFTP access from remote machines


You can also use the aptitude Ncurses UI if you wish. Type aptitude to start it:

Aptitude ncurses interface


You can search packages by pressing / and then start typing the keyword.

II. Search available packages using apt-cache

Use apt-cache to to search for packages available in the Debian, Ubuntu or Linux Mint repositories (and installed DEB packages that aren't in the repositories) like this:

apt-cache search KEYWORD


Example:

$ apt-cache search openssh

openssh-client - secure shell (SSH) client, for secure access to remote machines
openssh-server - secure shell (SSH) server, for secure access from remote machines
openssh-sftp-server - secure shell (SSH) sftp server module, for SFTP access from remote machines
python-setproctitle - Setproctitle implementation for Python 2
python3-setproctitle - Setproctitle implementation for Python 3
ssh - secure shell client and server (metapackage)
agent-transfer - copy a secret key from GnuPG's gpg-agent to OpenSSH's ssh-agent

...

ssh-askpass-gnome - interactive X program to prompt users for a passphrase for ssh-add
ssh-audit - tool for ssh server auditing
sshpass - Non-interactive ssh password authentication


I removed some of the output because it can get very long. The visible results order was not changed though.

III. Search available packages using apt

Using apt you can search for available packages from the command line as follows:

apt search KEYWORD


Replace KEYWORD with the keyword you want to search for (you can add multiple keywords in quotes).

Here is an example search for "openssh" together with its output:

$ apt search openssh

Sorting... Done
Full Text Search... Done
agent-transfer/bionic 0.41-1ubuntu1 amd64
  copy a secret key from GnuPG's gpg-agent to OpenSSH's ssh-agent

cme/bionic,bionic 1.026-1 all
  Check or edit configuration data with Config::Model

connect-proxy/bionic 1.105-1 amd64
  Establish TCP connection using SOCKS4/5 or HTTP tunnel

...

openssh-client/bionic,now 1:7.6p1-4 amd64 [installed]
  secure shell (SSH) client, for secure access to remote machines

openssh-client-ssh1/bionic 1:7.5p1-10 amd64
  secure shell (SSH) client for legacy SSH1 protocol

openssh-known-hosts/bionic,bionic 0.6.2-1 all
  download, filter and merge known_hosts for OpenSSH

openssh-server/bionic 1:7.6p1-4 amd64
  secure shell (SSH) server, for secure access from remote machines

openssh-sftp-server/bionic 1:7.6p1-4 amd64
  secure shell (SSH) sftp server module, for SFTP access from remote machines

putty-tools/bionic 0.70-4 amd64
  command-line tools for SSH, SCP, and SFTP

python-scp/bionic,bionic 0.10.2-1 all
  scp module for paramiko


Once again, I removed some of the results because the results list is quite long. The results order was not changed though.


For all three, the search results may be very long. In such cases, you can run them through more, for easier reading, like this:

apt-cache search KEYWORD | more


You can also exclude results that don't include a particular keyword (KEYWORD2 in this example) by using grep:

apt-cache search KEYWORD | grep KEYWORD2


grep is case sensitive by default. Add -i (grep -i KEYWORD2) to ignore case.

Published in GNU/Linux Rules!

There are multiple ways of preventing a package from updating in Debian, Ubuntu, Linux Mint, elementary OS and other Debian/Ubuntu-based Linux distributions. This article presents 3 ways of excluding repository packages from being upgraded.

Why prevent a package from being updated? Let's say you install a package that's older than the version available in Debian, Ubuntu or Linux Mint repositories, or you know some update is causing issues, and you want to upgrade all packages minus one (or two, three...).

Here's an example. I'm using Chromium browser with hardware accelerationpatches from the Saiarcot895-dev PPA, in Ubuntu 18.10. To get hardware acceleration to work with Nvidia drivers, a patched vdpau-va-driver package is needed, and this is not yet available in this PPA for the latest Ubuntu 18.10. Luckily, the Ubuntu 18.04 package can be installed in Ubuntu 18.10, but any upgrade through "apt upgrade" or using the Software Updater will upgrade this package, which I don't want. So in this case, holding this package from upgrades would allow me to upgrade all other packages without having to worry about it.

It should be noted that preventing a package from future upgrades may cause issues in some situations, if the package you're holding is used as a dependency for another package that can be upgraded. So try not to prevent too many packages from upgrades, especially libraries.


Here are 3 ways of preventing a package from updating in Debian, Ubuntu, Linux Mint.

1. Prevent package updates using a GUI: Synaptic Package Manager

Synaptic Package Manager, a Gtk graphical package management program for apt, can lock packages which prevents them from being updated.

It's important to note that using Synaptic to lock packages won't keep them from being updated from the command line - running apt upgrade or apt-get upgrade will still upgrade a package locked in Synaptic. Locking packages in Synaptic will prevent package upgrades using Ubuntu's Software Updater app, and possibly other graphical package managers. It will not prevent updating packages using the Linux Mint Update Manager application though. As a result, I recommend using apt-mark or dpkg (see below) to keep packages from updating.

You can install Synaptic Package Manager using this command:

sudo apt install synaptic


To prevent a package from updating using Synaptic, search for it, select the package and from the Synaptic menu click Package -> Lock Version:

Synaptic lock package version


In the same way you can unlock the package too.

To see all locked packages in Synaptic, click Status in the bottom left-hand side, then click on Pinned above the Status section:

Synaptic show locked (pinned) packages


2. Keep a package from updating using apt-mark

Holding packages from updating with apt-mark should prevent them from updating using Ubuntu's Software Updater, as well as command line upgrades (apt upgrade / apt-get upgrade).

You can hold a package from future upgrades (and from being automatically removed) with apt-mark by using this command:

sudo apt-mark hold PACKAGE


Replacing PACKAGE with the package you want to hold from updating.

You can check which packages marked as hold by using:

apt-mark showhold


To remove a hold (so the package can be updated), use:

sudo apt-mark unhold PACKAGE


For both hold and unhold you can specify multiple packages, just like when installing software with apt (separate the packages by a space).

3. Prevent package updates with dpkg

A while back there were some graphical package managers that ignored the apt-mark hold status. I'm not sure if that's still the case, but just to be safe (and in case you're using an old Debian / Ubuntu / Linux Mint version), here's another way of preventing package updates in Ubuntu, Linux Mint or Debian: dpkg.

To prevent a package from upgrades using dpkg, use:

echo "PACKAGE hold" | sudo dpkg --set-selections


You can see all package holds using this command:

dpkg --get-selections | grep hold


To remove the hold (allow the package to be upgraded), use:

echo "PACKAGE install" | sudo dpkg --set-selections


Unlike apt-mark, this solution doesn't allow specifying multiple packages at once.

Published in GNU/Linux Rules!

There are multiple ways of finding out to which package a particular file belongs to, on Ubuntu, Debian or Linux Mint. This article presents two ways of achieving this, both from the command line.

1. Using apt-file to find the package that provides a file (for repository packages, either installed or not installed)


apt-file indexes the contents of all packages available in your repositories, and allows you to search for files in all these packages. 

That means you can use apt-file to search for files inside DEB packages that are installed on your system, as well as packages that are not installed on your Debian (and Debian-based Linux distributions, like Ubuntu) machine, but are available to install from the repositories. This is useful in case you want to find what package contains a file that you need to compile some program, etc.

apt-file cannot find the package that provides a file in case you downloaded a DEB package and installed it, without using a repository. The package needs to be available in the repositories for apt-file to be able to find it.

apt-file may not be installed on your system. To install it in Debian, Ubuntu, Linux Mint and other Debian-based or Ubuntu-based Linux distributions, use this command:

sudo apt install apt-file


This tool find the files belonging to a package by using a database, which needs to be updated in order to be able to use it. To update the apt-file database, use:

sudo apt-file update


Now you can use apt-file to find the DEB package that provides a file, be it a package you've installed from the repositories, or a package available in the repositories, but not installed on your Debian / Ubuntu / Linux Mint system. To do this, run:

apt-file search filename


Replacing filename with the name of the file you want to find.

This command will list all occurrences of filename found in various packages. If you know the exact file path and filename, you can get the search results to only list the package that includes that exact file, like this:

apt-file search /path/to/filename


For example, running only apt-file search cairo.h will list a large list search results:

$ apt-file search cairo.h
fltk1.3-doc: /usr/share/doc/fltk1.3-doc/HTML/group__group__cairo.html
ggobi: /usr/include/ggobi/ggobi-renderer-cairo.h
glabels-dev: /usr/include/libglbarcode-3.0/libglbarcode/lgl-barcode-render-to-cairo.h
glabels-dev: /usr/share/gtk-doc/html/libglbarcode-3.0/libglbarcode-3.0-lgl-barcode-render-to-cairo.html
gstreamer1.0-plugins-good-doc: /usr/share/gtk-doc/html/gst-plugins-good-plugins-1.0/gst-plugins-good-plugins-plugin-cairo.html
guile-cairo-dev: /usr/include/guile-cairo/guile-cairo.h
guitarix-doc: /usr/share/doc/guitarix-doc/namespacegx__cairo.html
ipe: /usr/share/ipe/7.2.7/doc/group__cairo.html
libcairo-ocaml-dev: /usr/share/doc/libcairo-ocaml-dev/html/Pango_cairo.html
libcairo-ocaml-dev: /usr/share/doc/libcairo-ocaml-dev/html/type_Pango_cairo.html
libcairo2-dev: /usr/include/cairo/cairo.h
...


However, if you know the file path, e.g. you want to find out to which package the file /usr/include/cairo/cairo.h belongs to, run:

apt-file search /usr/include/cairo/cairo.h


This only lists the package that contains this file:

$ apt-file search /usr/include/cairo/cairo.h
libcairo2-dev: /usr/include/cairo/cairo.h


In this example, the package that includes the file I searched for (/usr/include/cairo/cairo.h) is libcairo2-dev.

apt-file may also be used to list all the files included in a package (apt-file list packagename), perform regex search, and more. Consult its man page (man apt-file) and help for more information (apt-file --help).

2. Using dpkg to find the package that provides a file (only for installed DEB packages - from any source)


dpkg can also be used to find out to which package a file belongs to. It can be faster to use than apt-file, because you don't need to install anything, and there's no database to update. 

However, dpkg can only search for files belonging to installed packages, so if you're searching for a file in a package that's not installed on your system, use apt-file. On the other hand, dpkg can be used to find files belonging to packages that were installed without using a repository, a feature that's not available for apt-file.

To use dpkg to find the installed DEB package that provides a file, run it with the -S (or --search) flag, followed by the filename (or pattern) you want to see to which package it belongs, like this:

dpkg -S filename


For example, to find out to which package the cairo.h file belongs to, use dpkg -S cairo.h:

$ dpkg -S cairo.h
libgtk2.0-dev:amd64: /usr/include/gtk-2.0/gdk/gdkcairo.h
libcairo2-dev:amd64: /usr/include/cairo/cairo.h
libpango1.0-dev: /usr/include/pango-1.0/pango/pangocairo.h
libgtk-3-dev:amd64: /usr/include/gtk-3.0/gdk/gdkcairo.h


Just like for apt-file, this may show multiple packages that have files containing the filename you're looking for. You can enter the full path of the file to get only the package that contains that specific file. Example:

$ dpkg -S /usr/include/cairo/cairo.h
libcairo2-dev:amd64: /usr/include/cairo/cairo.h


In this example, the Debian package that includes the file I searched for (/usr/include/cairo/cairo.h) is libcairo2-dev.


Other notable ways of finding the package a file belongs to is using the online search provided by Ubuntu and Debian:


For both, you'll also find options to find the packages that contain files named exactly like your input keyword, packages ending with the keyword, or packages that contains files whose names contain the keyword.

The Linux Mint package search website doesn't include an option to search for files inside packages, but you can use the Ubuntu or Debian online package search for packages that Linux Mint imports from Debian / Ubuntu.

Published in GNU/Linux Rules!

This article explains how to show a history of recently installed, upgraded or removed packages, on Debian, Ubuntu or Linux Mint, from the command line.

To be able to get a complete history list of package changes, including installed, upgraded or removed DEB packages, and show the date on which a particular action was performed, in Debian or Ubuntu, one can read the dpkg (the low-level infrastructure for handling the installation and removal of Debian software packages) log available at /var/log/dpkg.log. You can use grep to parse this file from the command line and only display installed, upgraded or removed packages, depending on what you need.

This works for DEB packages installed in any way, be it using a graphical tool such as Synaptic, Gnome Software, Update Manager, or a command line tool like aptapt-getaptitude or dpkg. It does not work for other packages, like Flatpak or Snap, or for software installed from source, and so on.

Some alternative ways of showing the package manager history on Debian, Ubuntu or Linux Mint, do not display a complete log. For example, Synaptic Package Manager (File -> History) can only show a history of installed, upgraded or removed software packages for which Synaptic itself was used to perform those actions, but you won't see any packages installed, updated or removed from the command line (using aptapt-getdpkg), using the Software Updater, or the Software application. Similarly, the /var/log/apt/history.log APT log file only lists actions performed using apt/apt-get.

Show a history of recently installed packages, their version number, and the date / time they were installed on Debian, Ubuntu or Linux Mint:

grep "install " /var/log/dpkg.log


This is how it looks:

$ grep "install " /var/log/dpkg.log
2019-01-08 13:22:15 install automathemely:all <none> 1.3
2019-01-08 13:22:29 install python3-astral:all <none> 1.6.1-1
2019-01-08 13:22:29 install python3-tzlocal:all <none> 1.5.1-1
2019-01-08 13:22:29 install python3-schedule:all <none> 0.3.2-1

...

2019-01-09 17:19:49 install libwebkit2-sharp-4.0-cil:amd64 <none> 2.10.9+git20160917-1.1
2019-01-09 17:19:49 install sparkleshare:all <none> 3.28-1
2019-01-15 15:58:20 install ffsend:amd64 <none> 0.1.2

Show a list of recently upgraded packages, the date / time they were upgraded, as well as the old and new package version, on Debian, Ubuntu or Linux Mint:

grep "upgrade " /var/log/dpkg.log


Sample output:

$ grep "upgrade " /var/log/dpkg.log
2019-01-07 11:14:10 upgrade tzdata:all 2018g-0ubuntu0.18.10 2018i-0ubuntu0.18.10
2019-01-07 11:35:14 upgrade davinci-resolve:amd64 15.2-2 15.2.2-1
2019-01-07 12:31:04 upgrade chromium-chromedriver:amd64 72.0.3626.17-0ubuntu1~ppa1~18.10.1 72.0.3626.28-0ubuntu1~ppa1~18.10.1
2019-01-07 12:31:04 upgrade chromium-browser-l10n:all 72.0.3626.17-0ubuntu1~ppa1~18.10.1 72.0.3626.28-0ubuntu1~ppa1~18.10.1
2019-01-07 12:31:08 upgrade chromium-browser:amd64 72.0.3626.17-0ubuntu1~ppa1~18.10.1 72.0.3626.28-0ubuntu1~ppa1~18.10.1
2019-01-07 12:31:12 upgrade chromium-codecs-ffmpeg-extra:amd64 72.0.3626.17-0ubuntu1~ppa1~18.10.1 72.0.3626.28-0ubuntu1~ppa1~18.10.1

...

2019-01-15 15:51:31 upgrade vlc-plugin-bittorrent:amd64 2.5-1~cosmic 2.6-1~cosmic
2019-01-15 17:30:44 upgrade virtualbox-6.0:amd64 6.0.0-127566~Ubuntu~bionic 6.0.2-128162~Ubuntu~bionic
2019-01-15 17:34:33 upgrade libarchive13:amd64 3.2.2-5 3.2.2-5ubuntu0.1
2019-01-16 12:32:43 upgrade oracle-java11-installer:amd64 11.0.1-2~linuxuprising1 11.0.2-1~linuxuprising0
2019-01-16 12:42:20 upgrade nvidiux:amd64 2.0.4 2.1
2019-01-16 13:41:05 upgrade plata-theme:all 0.4.1-0ubuntu1~cosmic1 0.5.4-0ubuntu1~cosmic1



Show a history of recently removed packages and the date / time they were removed, on Debian, Ubuntu or Linux Mint:

grep "remove " /var/log/dpkg.log


Example:

$ grep "remove " /var/log/dpkg.log
2019-01-10 12:30:55 remove automathemely:all 1.3 <none>
2019-01-11 13:16:38 remove persepolis:all 3.1.0.0 <none>
2019-01-11 13:38:52 remove python3-astral:all 1.6.1-1 <none>
2019-01-11 13:38:52 remove python3-psutil:amd64 5.4.6-1build1 <none>
2019-01-11 13:38:52 remove python3-pyxattr:amd64 0.6.0-2build3 <none>
2019-01-11 13:38:52 remove python3-schedule:all 0.3.2-1 <none>
2019-01-11 13:38:53 remove python3-tzlocal:all 1.5.1-1 <none>


/var/log/dpkg.log contains the package install, update and remove history for the current monthFor the previous month, read the /var/log/dpkg.log.1log file. For example to see the package installation history for the previous month, use:

grep "install " /var/log/dpkg.log.1


Want to go back even more in the dpkg history? Use zgrep instead of grep, and read /var/log/dpkg.log.2.gz/var/log/dpkg.log.3.gz/var/log/dpkg.log.4.gz and so on, which go back two, three and respectively four months.

Example:

zgrep "upgrade " /var/log/dpkg.log.2.gz


This is because by default on Debian, Ubuntu and Linux Mint, the dpkg log is set to rotate once a month, keeping 12 old logs (so for 12 months), and compress rotated files by using gzip (.gz). You can check the Debian/Ubuntu Logrotate configuration for dpkg by using cat /etc/logrotate.d/dpkg.

Published in GNU/Linux Rules!

This article explains how to downgrade a package to a specific version using apt, in Debian, Ubuntu or Linux Mint (from the command line).

Sometimes you may encounter issues with a recently upgraded package, and you want to downgrade it. To be able to downgrade a package in Debian, Ubuntu or Linux Mint (and other Debian/Ubuntu-based Linux distributions), the package version to which you want to downgrade must be available in a repository.

From the same series:


To downgrade a package to a specific version, you'll need to append =version after the package name in the installation command, with version being the version to which you want to downgrade the package:

sudo apt install <package>=<version>


Example 1.

Let's look at a simple example. I currently have Firefox 65 installed in Ubuntu 18.10, and I want to downgrade it using apt. The first thing to do is to look at the available versions, by running apt policy firefox (apt-cache policy works as well):

$ apt policy firefox
firefox:
  Installed: 65.0+build2-0ubuntu0.18.10.1
  Candidate: 65.0+build2-0ubuntu0.18.10.1
  Version table:
 *** 65.0+build2-0ubuntu0.18.10.1 500
        500 http://security.ubuntu.com/ubuntu cosmic-security/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu cosmic-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     63.0+build1-0ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu cosmic/main amd64 Packages


This apt command shows that the Firefox version installed on my system is 65.0+build2-0ubuntu0.18.10.1, and it's available in the cosmic-security and cosmic-updates repositories. There is an older version, 63.0+build1-0ubuntu1, available in the main repository, so Firefox can be downgraded to this version.

To downgrade Firefox from the installed 65.0+build2-0ubuntu0.18.10.1 version, to the 63.0+build1-0ubuntu1 version from the main repository, the command would be:

sudo apt install firefox=63.0+build1-0ubuntu1


This command downgrades Firefox without having to downgrade any other packages, because Firefox doesn't depend on any strict package versions:

$ sudo apt install firefox=63.0+build1-0ubuntu1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be DOWNGRADED:
  firefox
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 51 not upgraded.
Need to get 46.1 MB of archives.
After this operation, 4,243 kB disk space will be freed.
Do you want to continue? [Y/n]


There are cases in which you must resolve some dependencies to be able to downgrade the package though, and we'll look at an example like that below.

Example 2.

Let's look at a more complicated example - a package that can't be directly downgraded using apt without also downgrading some of its dependencies.

$ apt policy chromium-browser
chromium-browser:
  Installed: 72.0.3626.81-0ubuntu1~ppa2~18.10.1
  Candidate: 72.0.3626.81-0ubuntu1~ppa2~18.10.1
  Version table:
 *** 72.0.3626.81-0ubuntu1~ppa2~18.10.1 500
        500 http://ppa.launchpad.net/saiarcot895/chromium-beta/ubuntu cosmic/main amd64 Packages
        100 /var/lib/dpkg/status
     71.0.3578.98-0ubuntu0.18.10.1 500
        500 http://security.ubuntu.com/ubuntu cosmic-security/universe amd64 Packages
        500 http://archive.ubuntu.com/ubuntu cosmic-updates/universe amd64 Packages
     69.0.3497.100-0ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu cosmic/universe amd64 Packages


The apt policy command above shows that I currently have Chromium browser beta (version 72) installed from the Saiarcot Chromium Beta PPA, with two older versions being available in the Ubuntu security/updates and main repositories.

Let's try to downgrade chromium browser from version 72.0.3626.81-0ubuntu1~ppa2~18.10.1 to version 71.0.3578.98-0ubuntu0.18.10.1 (from the security/updates repositories) using apt and see what happens:

$ sudo apt install chromium-browser=71.0.3578.98-0ubuntu0.18.10.1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 chromium-browser : Depends: chromium-codecs-ffmpeg-extra (= 71.0.3578.98-0ubuntu0.18.10.1) but 72.0.3626.81-0ubuntu1~ppa2~18.10.1 is to be installed or
                             chromium-codecs-ffmpeg (= 71.0.3578.98-0ubuntu0.18.10.1) but it is not going to be installed
                    Recommends: chromium-browser-l10n but it is not going to be installed
E: Unable to correct problems, you have held broken packages.


Downgrading Chromium browser doesn't work because it depends on chromium-codecs-ffmpeg-extra or chromium-codecs-ffmpeg, with the exact same version as the chromium-browser package itself. In this case, let's also downgrade the chromium-codecs-ffmpeg-extra package to the same version:

$ sudo apt install chromium-browser=71.0.3578.98-0ubuntu0.18.10.1 chromium-codecs-ffmpeg-extra=71.0.3578.98-0ubuntu0.18.10.1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  webaccounts-chromium-extension unity-chromium-extension adobe-flashplugin
Recommended packages:
  chromium-browser-l10n
The following packages will be REMOVED:
  chromium-browser-l10n chromium-chromedriver
The following packages will be DOWNGRADED:
  chromium-browser chromium-codecs-ffmpeg-extra
0 upgraded, 0 newly installed, 2 downgraded, 2 to remove and 51 not upgraded.
Need to get 58.8 MB of archives.
After this operation, 61.5 MB disk space will be freed.
Do you want to continue? [Y/n]


The apt downgrade command output shows that chromium-browser can now be downgraded, but the command wants to remove 2 packages. Those are recommended packages that were automatically installed when chromium-browser was installed (and they too need to be the exact same version as the chromium-browser package), and while they are not required by chromium-browser, you may still need them. So it's a good idea to downgrade those as well, so they are not removed.

In this case, the apt downgrade command becomes:

sudo apt install chromium-browser=71.0.3578.98-0ubuntu0.18.10.1 chromium-codecs-ffmpeg-extra=71.0.3578.98-0ubuntu0.18.10.1 chromium-browser-l10n=71.0.3578.98-0ubuntu0.18.10.1 chromium-chromedriver=71.0.3578.98-0ubuntu0.18.10.1


Let's look at what happens when we use it:

$ sudo apt install chromium-browser=71.0.3578.98-0ubuntu0.18.10.1 chromium-codecs-ffmpeg-extra=71.0.3578.98-0ubuntu0.18.10.1 chromium-browser-l10n=71.0.3578.98-0ubuntu0.18.10.1 chromium-chromedriver=71.0.3578.98-0ubuntu0.18.10.1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  webaccounts-chromium-extension unity-chromium-extension adobe-flashplugin
The following packages will be DOWNGRADED:
  chromium-browser chromium-browser-l10n chromium-chromedriver chromium-codecs-ffmpeg-extra
0 upgraded, 0 newly installed, 4 downgraded, 0 to remove and 51 not upgraded.
Need to get 64.9 MB of archives.
After this operation, 35.8 MB disk space will be freed.
Do you want to continue? [Y/n]


As you can see, the downgrade can be performed, and no packages are about to be removed. Since it all looks good now, we can proceed with the downgrade.

Published in GNU/Linux Rules!
DMC Firewall is a Joomla Security extension!