Bash
使用帶有萬用字元的“apt-get remove”時如何排除一組包?
我正在嘗試使用
sudo apt-get remove --purge
刪除所有“php7. ”包但是我想排除“php7.0 ”包。我努力了;sudo apt-get -y remove --purge php7.[^php7.0]*
但沒有奏效我嘗試了很多其他類似的解決方案,但實際上沒有奏效,它專門刪除了我想要排除的包。如果有人為我解決了這個難題,我將不勝感激。‘Ubuntu 16.04.4 LTS’
~$ dpkg -l | grep php7 ii php7.0-cli 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 command-line interpreter for the PHP scripting language ii php7.0-common 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 documentation, examples and common module for PHP ii php7.0-curl 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 CURL module for PHP ii php7.0-fpm 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary) ii php7.0-gd 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 GD module for PHP ii php7.0-imap 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 IMAP module for PHP ii php7.0-intl 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP ii php7.0-json 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 JSON module for PHP ii php7.0-ldap 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 LDAP module for PHP ii php7.0-mbstring 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 MBSTRING module for PHP ii php7.0-mcrypt 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 libmcrypt module for PHP ii php7.0-mysql 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 MySQL module for PHP ii php7.0-opcache 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 Zend OpCache module for PHP ii php7.0-readline 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 readline module for PHP ii php7.0-xml 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 DOM, SimpleXML, WDDX, XML, and XSL module for PHP ii php7.0-zip 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 Zip module for PHP ii php7.1 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 all server-side, HTML-embedded scripting language (metapackage) ii php7.1-bcmath 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 Bcmath module for PHP ii php7.1-bz2 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 bzip2 module for PHP ii php7.1-cli 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 command-line interpreter for the PHP scripting language ii php7.1-common 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 documentation, examples and common module for PHP ii php7.1-curl 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 CURL module for PHP ii php7.1-fpm 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary) ii php7.1-gd 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 GD module for PHP ii php7.1-intl 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP ii php7.1-json 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 JSON module for PHP ii php7.1-mbstring 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 MBSTRING module for PHP ii php7.1-opcache 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 Zend OpCache module for PHP ii php7.1-readline 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 readline module for PHP ii php7.1-xml 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 DOM, SimpleXML, WDDX, XML, and XSL module for PHP ii php7.1-zip 7.1.33-16+ubuntu16.04.1+deb.sury.org+1 amd64 Zip module for PHP ii php7.2 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 all server-side, HTML-embedded scripting language (metapackage) ii php7.2-bcmath 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 Bcmath module for PHP ii php7.2-bz2 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 bzip2 module for PHP ii php7.2-cli 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 command-line interpreter for the PHP scripting language ii php7.2-common 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 documentation, examples and common module for PHP ii php7.2-curl 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 CURL module for PHP ii php7.2-fpm 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary) ii php7.2-gd 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 GD module for PHP ii php7.2-intl 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP ii php7.2-json 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 JSON module for PHP ii php7.2-mbstring 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 MBSTRING module for PHP ii php7.2-opcache 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 Zend OpCache module for PHP ii php7.2-readline 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 readline module for PHP ii php7.2-xml 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 DOM, SimpleXML, WDDX, XML, and XSL module for PHP ii php7.2-zip 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 Zip module for PHP ii php7.3 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 all server-side, HTML-embedded scripting language (metapackage) ii php7.3-bcmath 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 Bcmath module for PHP ii php7.3-bz2 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 bzip2 module for PHP ii php7.3-cli 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 command-line interpreter for the PHP scripting language ii php7.3-common 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 documentation, examples and common module for PHP ii php7.3-curl 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 CURL module for PHP ii php7.3-fpm 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary) ii php7.3-gd 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 GD module for PHP ii php7.3-intl 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP ii php7.3-json 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 JSON module for PHP ii php7.3-mbstring 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 MBSTRING module for PHP ii php7.3-opcache 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 Zend OpCache module for PHP ii php7.3-readline 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 readline module for PHP ii php7.3-xml 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 DOM, SimpleXML, WDDX, XML, and XSL module for PHP ii php7.3-zip 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 Zip module for PHP
‘Ubuntu 16.04.6 LTS’
~$ dpkg -l | grep php7 ii php-common 2:69+ubuntu16.04.1+deb.sury.org+2+php7.3 all Common files for PHP packages ii php7.0 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 all server-side, HTML-embedded scripting language (metapackage) ii php7.0-bcmath 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 Bcmath module for PHP ii php7.0-bz2 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 bzip2 module for PHP ii php7.0-cli 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 command-line interpreter for the PHP scripting language ii php7.0-common 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 documentation, examples and common module for PHP ii php7.0-curl 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 CURL module for PHP ii php7.0-fpm 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary) ii php7.0-gd 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 GD module for PHP ii php7.0-intl 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP ii php7.0-json 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 JSON module for PHP ii php7.0-mbstring 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 MBSTRING module for PHP ii php7.0-opcache 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 Zend OpCache module for PHP ii php7.0-readline 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 readline module for PHP ii php7.0-xml 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 DOM, SimpleXML, WDDX, XML, and XSL module for PHP ii php7.0-zip 7.0.33-29+ubuntu16.04.1+deb.sury.org+1 amd64 Zip module for PHP ii php7.1-cli 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 command-line interpreter for the PHP scripting language ii php7.1-common 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 documentation, examples and common module for PHP ii php7.1-curl 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 CURL module for PHP ii php7.1-fpm 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary) ii php7.1-gd 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 GD module for PHP ii php7.1-imap 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 IMAP module for PHP ii php7.1-intl 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP ii php7.1-json 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 JSON module for PHP ii php7.1-ldap 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 LDAP module for PHP ii php7.1-mbstring 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 MBSTRING module for PHP ii php7.1-mcrypt 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 libmcrypt module for PHP ii php7.1-mysql 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 MySQL module for PHP ii php7.1-opcache 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 Zend OpCache module for PHP ii php7.1-readline 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 readline module for PHP ii php7.1-xml 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 DOM, SimpleXML, WDDX, XML, and XSL module for PHP ii php7.1-zip 7.1.30-1+ubuntu16.04.1+deb.sury.org+1 amd64 Zip module for PHP ii php7.2 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 all server-side, HTML-embedded scripting language (metapackage) ii php7.2-bcmath 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 Bcmath module for PHP ii php7.2-bz2 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 bzip2 module for PHP ii php7.2-cli 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 command-line interpreter for the PHP scripting language ii php7.2-common 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 documentation, examples and common module for PHP ii php7.2-curl 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 CURL module for PHP ii php7.2-fpm 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary) ii php7.2-gd 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 GD module for PHP ii php7.2-intl 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP ii php7.2-json 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 JSON module for PHP ii php7.2-mbstring 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 MBSTRING module for PHP ii php7.2-opcache 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 Zend OpCache module for PHP ii php7.2-readline 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 readline module for PHP ii php7.2-xml 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 DOM, SimpleXML, WDDX, XML, and XSL module for PHP ii php7.2-zip 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 amd64 Zip module for PHP ii php7.3 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 all server-side, HTML-embedded scripting language (metapackage) ii php7.3-bcmath 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 Bcmath module for PHP ii php7.3-bz2 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 bzip2 module for PHP ii php7.3-cli 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 command-line interpreter for the PHP scripting language ii php7.3-common 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 documentation, examples and common module for PHP ii php7.3-curl 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 CURL module for PHP ii php7.3-fpm 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary) ii php7.3-gd 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 GD module for PHP ii php7.3-intl 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP ii php7.3-json 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 JSON module for PHP ii php7.3-mbstring 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 MBSTRING module for PHP ii php7.3-opcache 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 Zend OpCache module for PHP ii php7.3-readline 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 readline module for PHP ii php7.3-xml 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 DOM, SimpleXML, WDDX, XML, and XSL module for PHP ii php7.3-zip 7.3.19-1+ubuntu16.04.1+deb.sury.org+1 amd64 Zip module for PHP
我會做什麼:
sudo apt-get remove --purge $( dpkg -l | awk '$1 == "ii" && /php7/ && !/php7\.0/{print $2}' )
要將變數傳遞給awk,請使用
-v
switch:EXCLUDE_VERSION='php7.0' awk -v exv="$EXCLUDE_VERSION" '$1 == "ii" && /php7/ && $2 !~ exv{print $2}'
您的正則表達式看起來不正確。它匹配包含(不一定以)“php7”加上一個任意字元(“.”)後跟任意數量的字元的包名稱,這些字元不是以下字元:p、h、7、.、0。
您可能想要的是以下正則表達式:
sudo apt-get -y remove --purge '^php7\.[^0]'
這匹配“php7”。在包名稱的開頭 (^) 加上除 0 以外的任何字元。後面可能會出現更多字元,但我們不需要考慮它們。