Ask Your Question

Revision history [back]

To prevent the corner case mentioned by skytux, I'd do it like this:

/usr/bin/rpm -q -f /usr/bin/rpm

If the exit code is 0, the system is probably RPM based.

In a C program you could run it with the system function.

To prevent the corner case mentioned by skytux, I'd do it like this:

/usr/bin/rpm -q -f /usr/bin/rpm
/usr/bin/rpm >/dev/null 2>&1

If the exit code is 0, the system is probably RPM based.

In a C program you could run it with the system function.

To prevent the corner case mentioned by skytux, I'd do it like this:

/usr/bin/rpm -q -f /usr/bin/rpm >/dev/null 2>&1

If the exit code is 0, the system is probably RPM based.


In a C program Other usefull commands which you could run it with can try are:

  • /usr/bin/rpm -q -f /usr/bin/dpkg
  • /usr/bin/dpkg --search /usr/bin/dpkg
  • /usr/bin/dpkg --search /usr/bin/rpm

I did tests on:

  • Fedora 20 x86_64

    [joe@fedora20 ~]$ rpm -q dpkg
    dpkg-1.16.15-1.fc20.x86_64
    
  • Ubuntu 14.04

    joe@ubuntu1404 ~$ dpkg --status rpm
    Package: rpm
    Status: install ok installed
    Architecture: amd64
    Version: 4.11.1-3
    

Here are the results of the tests (with truncated error message for brevity):

system    FEDORA 20 x86_64                           ║     UBUNTU 14.04 AMD64
                                               ║
[j@f ~]$ /usr/bin/rpm -q -f /usr/bin/rpm       ║ j@u:~$ /usr/bin/rpm -q -f /usr/bin/rpm
rpm-4.11.2-2.fc20.x86_64                       ║ file /usr/bin/rpm is not owned by ...
[j@f ~]$ echo $?                               ║ j@u:~$ echo $?
0                                              ║ 1
                                               ║
[j@f ~]$ /usr/bin/rpm -q -f /usr/bin/dpkg      ║ j@u ~$ /usr/bin/rpm -q -f /usr/bin/dpkg
dpkg-1.16.15-1.fc20.x86_64                     ║ file /usr/bin/dpkg is not owned by ...
[j@f ~]$ echo $?                               ║ j@u ~$ echo $?
0                                              ║ 1
                                               ║
[j@f ~]$ /usr/bin/dpkg --search /usr/bin/dpkg  ║ j@u ~$ /usr/bin/dpkg --search /usr/bin/dpkg
dpkg-query: no path found matching pattern ... ║ dpkg: /usr/bin/dpkg
[j@f ~]$ echo $?                               ║ j@u ~$ echo $?
1                                              ║ 0
                                               ║
[j@f ~]$ /usr/bin/dpkg --search /usr/bin/rpm   ║ j@u ~$ /usr/bin/dpkg --search /usr/bin/rpm
dpkg-query: no path found matching pattern ... ║ rpm: /usr/bin/rpm
[j@f ~]$ echo $?                               ║ j@u ~$ echo $?
1                                              ║ 0
 function.

To prevent the corner case mentioned by skytux, I'd do it like this:

/usr/bin/rpm -q -f /usr/bin/rpm >/dev/null 2>&1

If the exit code is 0, the system is probably RPM based.


Other usefull commands which you can try are:

  • /usr/bin/rpm -q -f /usr/bin/dpkg
  • /usr/bin/dpkg --search /usr/bin/dpkg
  • /usr/bin/dpkg --search /usr/bin/rpm

I did I've done tests on:

  • Fedora 20 x86_64

    [joe@fedora20 ~]$ rpm -q dpkg
    dpkg-1.16.15-1.fc20.x86_64
    
  • Ubuntu 14.04

    joe@ubuntu1404 ~$ dpkg --status rpm
    Package: rpm
    Status: install ok installed
    Architecture: amd64
    Version: 4.11.1-3
    

Here are the results of the tests (with truncated error message for brevity):

    FEDORA 20 x86_64                           ║     UBUNTU 14.04 AMD64
═══════════════════════════════════════════════╬════════════════════════════════════════════
[j@f ~]$ /usr/bin/rpm -q -f /usr/bin/rpm       ║ j@u:~$ /usr/bin/rpm -q -f /usr/bin/rpm
rpm-4.11.2-2.fc20.x86_64                       ║ file /usr/bin/rpm is not owned by ...
[j@f ~]$ echo $?                               ║ j@u:~$ echo $?
0                                              ║ 1
                                               ║
[j@f ~]$ /usr/bin/rpm -q -f /usr/bin/dpkg      ║ j@u ~$ /usr/bin/rpm -q -f /usr/bin/dpkg
dpkg-1.16.15-1.fc20.x86_64                     ║ file /usr/bin/dpkg is not owned by ...
[j@f ~]$ echo $?                               ║ j@u ~$ echo $?
0                                              ║ 1
                                               ║
[j@f ~]$ /usr/bin/dpkg --search /usr/bin/dpkg  ║ j@u ~$ /usr/bin/dpkg --search /usr/bin/dpkg
dpkg-query: no path found matching pattern ... ║ dpkg: /usr/bin/dpkg
[j@f ~]$ echo $?                               ║ j@u ~$ echo $?
1                                              ║ 0
                                               ║
[j@f ~]$ /usr/bin/dpkg --search /usr/bin/rpm   ║ j@u ~$ /usr/bin/dpkg --search /usr/bin/rpm
dpkg-query: no path found matching pattern ... ║ rpm: /usr/bin/rpm
[j@f ~]$ echo $?                               ║ j@u ~$ echo $?
1                                              ║ 0