Created
October 17, 2024 16:49
-
-
Save ychaouche/69b67652e2858fe68d9381f080a81e27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Got a list of helpful bash scripts/functions/aliases to deal with packages | |
/**************************/ | |
/* 1. all package.* utils */ | |
/**************************/ | |
11:11:28 ~ -1- $ package. | |
package.count package.list.all | |
package.describe package.list.installed | |
package.describe2 package.list.updatable | |
package.files.extract.all package.needed.for | |
package.files.extract.one package.needs | |
package.files.list package.remove | |
package.install package.search | |
package.installed.by package.search.byfile | |
package.install.last.list package.search.byname | |
package.install.last.undo package.version | |
package.is.installed package.whatprovides | |
11:11:28 ~ -1- $ package. | |
/*******************/ | |
/* 2. accounting */ | |
/*******************/ | |
1. package.count | |
Counts the number of packages APT knows about | |
(packages in /var/lib/dpkg/info/) | |
11:44:03 ~ -1- $ package.count | |
3653 | |
11:44:07 ~ -1- $ | |
alias package.count='package.list.all | wc -l' | |
/***************/ | |
/* 3. listing */ | |
/***************/ | |
2. package.list.all | |
Lists all the packages APT knows about | |
(packages in /var/lib/dpkg/info/) | |
11:54:55 ~ -1- $ package.list.all | head | |
a2ps | |
aac-enc | |
accountsservice | |
acl | |
acpid | |
acpi-support | |
adduser | |
adobe-flashplugin | |
afpfs-ng | |
afpfs-ng-utils | |
11:56:16 ~ -1- $ package.list.all | tail | |
xtrans-dev | |
xz-utils | |
yelp | |
yelp-xsl | |
zenity-common | |
zenity | |
zip | |
zlib1g:amd64 | |
zlib1g-dev:amd64 | |
zlib1g:i386 | |
11:56:22 ~ -1- $ | |
alias package.list.all='for file in /var/lib/dpkg/info/*.list; do file="${file#/var/lib/dpkg/info/}"; file="${file%.list}"; echo $file; done' | |
3. package.list.installed | |
outputs only installed packages | |
17:32:26 ~ -1- $ package.list.installed | head | |
Desired=Unknown/Install/Remove/Purge/Hold | |
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend | |
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) | |
||/ Name Version Architecture Description | |
+++-=================================================-====================================================-============-===================================================================================================================== | |
ii a2ps 1:4.14-1.3 amd64 GNU a2ps - 'Anything to PostScript' converter and pretty-printer | |
ii aac-enc 0.1.2-1 amd64 Fraunhofer FDK AAC Codec Library - frontend binary | |
ii accountsservice 0.6.35-0ubuntu7.3 amd64 query and manipulate user account information | |
ii acl 2.2.52-1 amd64 Access control list utilities | |
ii acpi-support 0.142 amd64 scripts for handling many ACPI events | |
17:32:29 ~ -1- $ | |
17:33:12 ~ -1- $ type package.list.installed | |
package.list.installed is aliased to `dpkg -l' | |
17:33:13 ~ -1- $ | |
4. package.list.updatable | |
list the packages that can be updated. | |
root@messagerie-recup[10.10.10.20] ~ # package.list.updatable | |
libgcc-s1 [10.2.1-6] -> 12.2.0-14 | |
libapt-pkg6.0 [2.2.4] -> 2.6.1 | |
apt [2.2.4] -> 2.6.1 | |
apt-utils [2.2.4] -> 2.6.1 | |
rsync [3.2.3-4+deb11u1] -> 3.2.7-1 | |
libp11-kit0 [0.23.22-1] -> 0.24.1-2 | |
kmod [28-1] -> 30+20221128-1 | |
libkmod2 [28-1] -> 30+20221128-1 | |
exim4-daemon-light [4.94.2-7+deb11u2] -> 4.96-15+deb12u4 | |
exim4-base [4.94.2-7+deb11u2] -> 4.96-15+deb12u4 | |
guile-2.2-libs [2.2.7+1-6] -> 2.2.7+1-9 | |
libcryptsetup12 [2:2.3.7-1+deb11u1] -> 2:2.6.1-4~deb12u1 | |
libgssapi-krb5-2 [1.18.3-6+deb11u4] -> 1.20.1-2+deb12u1 | |
libkrb5-3 [1.18.3-6+deb11u4] -> 1.20.1-2+deb12u1 | |
libk5crypto3 [1.18.3-6+deb11u4] -> 1.20.1-2+deb12u1 | |
libkrb5support0 [1.18.3-6+deb11u4] -> 1.20.1-2+deb12u1 | |
libmariadb3 [1:10.5.21-0+deb11u1] -> 1:10.11.4-1~deb12u1 | |
libsasl2-modules [2.1.27+dfsg-2.1+deb11u1] -> 2.1.28+dfsg-10 | |
libssh2-1 [1.9.0-2] -> 1.10.0-3+b1 | |
libxml2 [2.9.10+dfsg-6.7+deb11u4] -> 2.9.14+dfsg-1.3~deb12u1 | |
openssl [1.1.1w-0+deb11u1] -> 3.0.11-1~deb12u2 | |
root@messagerie-recup[10.10.10.20] ~ # | |
root@messagerie-recup[10.10.10.20] ~ # type package.list.updatable | |
package.list.updatable is aliased to `apt-get --just-print upgrade | awk "/^Inst/ {print \$2,\$3,\"->\",substr(\$4,2)}"' | |
root@messagerie-recup[10.10.10.20] ~ # | |
5. package.files.list | |
Lists the file of a package, | |
either by name, | |
or using a .deb file | |
requires the apt-file package | |
12:12:47 ~ -1- $ package.files.list a2ps | tail | |
/usr/bin/composeglyphs | |
/usr/bin/a2ps-lpr-wrapper | |
/usr/bin/ogonkify | |
/usr/bin/texi2dvi4a2ps | |
/usr/bin/card | |
/usr/bin/psmandup | |
/usr/bin/fixps | |
/usr/bin/a2ps | |
/usr/bin/pdiff | |
/usr/bin/fixnt | |
12:12:54 ~ -1- $ | |
package.files.list is a function | |
package.files.list () | |
{ | |
local package; | |
package="$1"; | |
if [[ "$package" =~ ".deb" ]]; then | |
case $(ar t "$package") in | |
*data.tar.gz*) | |
ar fp "$package" data.tar.gz | tar zvt | |
;; | |
*data.tar.xz*) | |
ar fp "$package" data.tar.xz | tar Jvt | |
;; | |
esac; | |
else | |
dpkg -L "$package" 2> /dev/null || apt-file list "$package"; | |
fi | |
} | |
/****************/ | |
/* 4. informing */ | |
/****************/ | |
6. package.describe | |
Prints the description of a package | |
(needs grep-dctrl which is provided by dctrl-tools) | |
11:58:34 ~ -1- $ package.describe a2ps | |
Description-en: GNU a2ps - 'Anything to PostScript' converter and pretty-printer | |
GNU a2ps converts files into PostScript for printing or viewing. It uses a | |
nice default format, usually two pages on each physical page, borders | |
surrounding pages, headers with useful information (page number, printing | |
date, file name or supplied header), line numbering, symbol substitution | |
as well as pretty printing for a wide range of programming languages. | |
. | |
Historically, a2ps started as a text to PostScript converter, but thanks | |
to powerful delegations it is able to let you use it for any kind of files, | |
ie it can also digest manual pages, dvi files, texinfo, .... | |
. | |
Among the other most noticeable features of a2ps are: | |
- various encodings (all the Latins and others), | |
- various fonts (automatic font downloading), | |
- various medias, | |
- various printer interfaces, | |
- various output styles, | |
- various programming languages, | |
- various helping applications, | |
- and various spoken languages. | |
11:58:39 ~ -1- $ | |
11:58:39 ~ -1- $ type package.describe | |
package.describe is a function | |
package.describe () | |
{ | |
apt-cache show "$1" | grep-dctrl -s Description-en - | |
} | |
12:03:12 ~ -1- $ | |
7. package.whatprovides | |
Curious to know which package a particular command is from? | |
12:03:12 ~ -1- $ package.whatprovides grep-dctrl | |
dctrl-tools | |
12:04:45 ~ -1- $ | |
12:04:45 ~ -1- $ type package.whatprovides | |
package.whatprovides is a function | |
package.whatprovides () | |
{ | |
dpkg -S "$1" | cut -f1 -d: | sort | uniq | |
} | |
12:05:27 ~ -1- $ | |
8. package.is.installed | |
tells whether a package is installed or not. | |
17:27:31 ~ -1- $ package.is.installed apache2 | |
apache2 2.4.7-1ubuntu4.22 | |
17:27:39 ~ -1- $ package.is.installed nginx | |
dpkg-query: no packages found matching nginx | |
17:27:45 ~ -1- $ | |
17:27:45 ~ -1- $ type package.is.installed | |
package.is.installed is aliased to `dpkg-query -W' | |
17:28:17 ~ -1- $ | |
9. package.version / package.versions | |
Prints the installed version of a package / all available versions | |
12:29:32 ~/DOWNLOADS/LIBS -1- $ package.version vlc | |
vlc 2.1.6-0ubuntu14.04.4 | |
12:29:35 ~/DOWNLOADS/LIBS -1- $ package.versions vlc | |
Version: 2.1.6-0ubuntu14.04.5+esm1 | |
Version: 2.1.6-0ubuntu14.04.5+esm1 | |
Version: 2.1.6-0ubuntu14.04.4 | |
Version: 2.1.6-0ubuntu14.04.4 | |
Version: 2.1.2-2build2 | |
Version: 2.1.2-2build2 | |
Version: 2.1.6-0ubuntu14.04.4 | |
Version: 2.1.6-0ubuntu14.04.4 | |
12:29:39 ~/DOWNLOADS/LIBS -1- $ | |
/*******************************/ | |
/* 5. dealing with .deb files */ | |
/*******************************/ | |
10. package.files.extract.all | |
Extracts all the files inside a .deb package | |
12:06:50 ~ -1- $ type.cat package.files.extract.all | |
#!/bin/bash | |
package="$1" | |
if [[ "$package" =~ ".deb" ]] | |
then | |
echo "ar fp $package data.tar.xz | tar Jvx" | |
ar fp "$package" data.tar.xz | tar Jvx | |
else | |
echo "I only know about .deb packages." | |
echo "Sorry." | |
exit 1 | |
fi | |
12:06:53 ~ -1- $ | |
11. package.files.extract.one | |
Extracts one file from a .deb archive, | |
useful when looking for a specific .so for example. | |
#!/bin/bash | |
if (( $# != 2 )) | |
then | |
echo "usage : $(basename $0) .deb file" | |
exit 1 | |
fi | |
package="$1" | |
if ! [[ "$package" =~ ".deb" ]] | |
then | |
echo "not a debian package" | |
exit 2 | |
fi | |
file="$2" | |
echo "ar fp $package data.tar.xz | tar Jvx $file" | |
ar fp "$package" data.tar.xz | tar Jvx "$file" | |
/********************/ | |
/* 6. dependencies */ | |
/********************/ | |
12. package.installed.by | |
Tells you which package installed the provided package, | |
or informs you that it was manually installed. | |
requires aptitude. | |
12:15:32 ~ -1- $ package.installed.by a2ps | |
i hpijs-ppds Depends cups-filters (>= 1.0.42) | foomatic-filters (>= 3.0.2) | |
p foomatic-filters Recommends cups | enscript | a2ps | mpage | |
12:15:59 ~ -1- $ | |
12:15:28 ~ -1- $ type package.installed.by | |
package.installed.by is aliased to `aptitude why' | |
12:15:32 ~ -1- $ | |
13. package.needed.for | |
Useful to know if you can safely remove a package. | |
11:12:37 ~ -1- $ package.needed.for xpenguins | |
xpenguins | |
Reverse Depends: | |
xpenguins:i386 | |
junior-toys | |
11:13:23 ~ -1- $ package.is.installed junior-toys | |
dpkg-query: no packages found matching junior-toys | |
11:13:31 ~ -1- $ # | |
09:33:57 ~ -1- $ type package.needed.for | |
package.needed.for is aliased to `_asroot apt-cache rdepends' | |
11:10:14 ~ -1- $ | |
/****************/ | |
/* 7. searching */ | |
/****************/ | |
14.package.search | |
search packages by name or by file | |
12:07:47 ~ -1- $ package.search iodine | |
iodine - tool for tunneling IPv4 data through a DNS server | |
network-manager-iodine - network management framework (iodine plugin core) | |
network-manager-iodine-gnome - network management framework (iodine plugin GNOME GUI) | |
12:08:27 ~ -1- $ | |
12:21:31 ~/DOWNLOADS/LIBS -1- $ package.search.byfile libpq-fe.h | |
libpq-dev: /usr/include/postgresql/libpq-fe.h | |
postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.h | |
12:22:00 ~/DOWNLOADS/LIBS -1- $ | |
12:07:24 ~ -1- $ type package.search | |
package.search is aliased to `package.search.byname' | |
12:07:36 ~ -1- $ type package.search.byname | |
package.search.byname is aliased to `apt-cache search' | |
12:07:47 ~ -1- $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment