命令行大全

apt-cache

rose1 发表于 2020-08-05 11:48浏览次数:

apt-cache查询高级打包工具(APT)的包缓存,这在Linux系统(例如Debian和Ubuntu)上很常见。 最常见的是,它用于搜索软件包和软件包名称。 这对于帮助您跟踪软件依赖性也很有用。

查看英文版

目录:

1 apt-cache 运行系统环境

2 apt-cache 说明

3 apt-cache 语法

4 apt-cache 例子

apt-cache 运行系统环境

Linux

apt-cache 说明

apt-cache对APT的程序包缓存执行各种操作。apt-cache不会操纵系统状态,但会提供操作以从包元数据搜索并生成有趣的输出。
apt-cache performs a variety of operations on APT's package cache. apt-cache does not manipulate the state of the system but does provide operations to search and generate interesting output from the package metadata.

查看英文版

查看中文版

apt-cache 语法

apt-cache [-agipns] [-o=config_string] [-c=config_file]
          {gencaches | showpkg pkg... | showsrc pkg... |
          stats | dump | dumpavail | unmet | search regex... |
          show pkg [{=pkg_version_number | /target_release}]... |
          depends pkg [{=pkg_version_number | /target_release}]... |
          rdepends pkg [{=pkg_version_number | /target_release}]... |
          pkgnames [prefix] | dotty pkg [{=pkg_version_number |
          /target_release}]... | xvcg pkg [{=pkg_version_number |
          /target_release}]... | policy [pkg...] | madison pkg... |
          {-v | --version} | {-h | --help}}

指令

gencaches

创建或重新创建APT的程序包缓存。如果缺少此缓存或该缓存已过期,则需要该缓存的所有命令都会隐式完成此操作。

showpkg pkg...

显示有关命令行中列出的软件包的信息。其余参数是程序包名称。显示列出的每个程序包的可用版本和反向依赖关系,以及每个版本的正向依赖关系。前向(正常)依赖关系是相关程序包所依赖的程序包;反向依赖性是指那些依赖于所讨论的软件包的软件包。因此,必须满足程序包的前向依存关系,而不必满足反向依存关系。例如,apt-cache showpkg libreadline2将产生类似于以下内容的输出:

Package: libreadline2Versions: 2.1-12(/var/state/apt/lists/foo_Packages),Reverse Depends:libreadlineg2,libreadline2libreadline2-altdev,libreadline2Dependencies:2.1-12 - libc5 (2 5.4.0-0) ncurses3.0 (0 (null))Provides:2.1-12 -Reverse Provides:

因此可以看出,libreadline2版本2.1-12取决于libc5和ncurses3.0,必须安装它们才能使libreadline2正常工作。反过来,libreadlineg2和libreadline2-altdev依赖于libreadline2。如果已安装libreadline2,则还必须安装libc5和ncurses3.0(和ldso);否则,必须先安装libread5。无需安装libreadlineg2和libreadline2-altdev。对于输出的其余部分的特定含义,最好参考apt源代码。

stats

显示有关缓存的一些统计信息。预计不会有其他争论。报告的统计数据是:

  • 软件包名称总数是在缓存中找到的软件包名称的数量。
  • 普通软件包是常规,普通软件包名称的数量;这些程序包的名称与依赖关系中其他程序包使用的名称之间是一一对应的。大多数软件包都属于此类。
  • 纯虚拟软件包是仅作为虚拟软件包名称存在的软件包的数量;也就是说,软件包仅“提供”虚拟软件包名称,而没有软件包实际使用该名称。例如,在Debian系统中,“ mail-transport-agent”是一个纯虚拟包。有几个软件包提供“ mail-transport-agent”,但是没有名为“ mail-transport-agent”的软件包。
  • 单个虚拟软件包是软件包的数量,其中只有一个软件包提供了特定的虚拟软件包。例如,在Debian系统中,“ X11-text-viewer”是一个虚拟软件包,但是只有一个软件包xless提供了“ X11-text-viewer”。
  • 混合虚拟软件包是提供特定虚拟软件包或以虚拟软件包名称作为软件包名称的软件包数量。例如,在Debian系统中,“ debconf”既是实际的软件包,也由debconf-tiny软件包提供。
  • 缺少依赖项中引用但没有任何软件包提供的软件包名称的数量。如果没有访问完整的发行版,或者已从发行版中删除了某个软件包(真实或虚拟),则可能缺少软件包。通常,它们是从“冲突或中断”语句中引用的。
  • 完全不同的版本总数是在缓存中找到的软件包版本的数量;因此,该值至少等于软件包名称总数。如果要访问多个分发(例如,“稳定”和“不稳定”),则此值可能会比软件包名称总数大得多。
  • 总依赖关系是高速缓存中所有程序包声明的依赖关系的数量。

showsrc pkg...

显示与给定包名称匹配的所有源包记录。显示所有版本,以及所有声明该名称为二进制包的记录。

dump

显示缓存中每个软件包的简短列表。它主要用于调试。

dumpavail

dumpavail将可用列表打印到标准输出。这适合与dpkg一起使用,并由dselect方法使用。

unmet

显示软件包缓存中所有未满足的依赖项的摘要。

show pkg...

show执行类似于dpkg --print-avail的功能;它显示命名软件包的软件包记录。

search regex...

在给定的POSIX样式正则表达式模式的所有可用软件包列表上执行全文搜索。它在软件包名称和描述中搜索正则表达式的出现,并打印出软件包名称和简短描述,包括虚拟软件包名称。如果给出--full,则为每个匹配的软件包产生与show相同的输出;如果给出--names-only,则不搜索长描述,仅软件包名称。

可以使用单独的参数来指定将AND在一起的多个搜索模式。

depends pkg...

显示了软件包具有的每个依赖关系的列表,以及可以满足该依赖关系的所有其他可能的软件包。

rdepends pkg...

显示了软件包具有的每个反向依赖性的列表。

pkgnames [prefix]

此命令显示APT知道的每个软件包的名称。可选参数是前缀匹配,用于过滤名称列表。该输出适合在Shell Tab完整功能中使用,并且生成速度非常快。此命令最好与--generate选项一起使用。

注意,APT知道的软件包不一定可以下载,安装或安装(例如,虚拟软件包也列在生成的列表中)。

dotty pkg...

在命令行中获取软件包列表,并从GraphViz软件包中生成适合dotty使用的输出。结果将是代表程序包之间关系的一组节点和边。默认情况下,给定的软件包将跟踪所有相关的软件包;这会产生非常大的图形。要将输出限制为仅在命令行中列出的软件包,请设置APT :: Cache :: GivenOnly选项。

生成的节点将具有多种形状。普通包装是盒子,纯虚拟包装是三角形,混合虚拟包装是菱形,缺失包装是六角形。橙色框表示递归已停止(叶包装),蓝线表示依赖,绿线表示冲突。

dotty无法显示较大的软件包集。

xvcg pkg...

一样疯疯癫癫,只为xvcg从VCG工具。

policy [pkg...]

该策略旨在帮助调试与首选项文件有关的问题。没有任何参数,它将打印出每个源的优先级。否则,它将打印出有关命名包优先级选择的详细信息。

madison pkg...

尝试模仿Debian档案管理工具madison的输出格式和功能的子集。它以表格格式显示软件包的可用版本。与原始的madison不同,它只能显示有关APT已为其检索程序包列表(APT :: Architecture)的体系结构的信息。

选件

可以使用配置文件来设置所有命令行选项,描述指示要设置的配置选项。对于布尔选项,你可以通过使用类似覆盖配置文件-F-,--no-F ,-f =没有或其他变化。

-p--pkg-cache

选择文件以存储程序包缓存。程序包缓存是所有操作使用的主要缓存。

配置项:Dir :: Cache :: pkgcache。

-s--src-cache

选择要存储源缓存的文件。该源仅由gencaches使用,它存储来自远程源的包信息的已解析版本。构建程序包高速缓存时,源高速缓存用于避免重新解析所有程序包文件。

配置项:Dir :: Cache :: srcpkgcache。

-q--quiet

安静; 产生适合记录的输出,省略进度指示器。更多的q将产生更大的静默度,最大为2。您也可以使用-q = #设置静默度级别,从而覆盖配置文件。

配置项:安静。

-i--important

仅打印重要的依赖项;与unmet和依赖一起使用。原因只有Depends中和预依赖要打印的关系。

配置项:APT :: Cache :: Important。

--no-pre-depends,
--no-depends,
--no-recommends,
--no-suggests,
--no-conflicts,
--no-breaks,
--no-replaces,
--no-enhances

默认情况下,depends和rdepends打印所有依赖项。可以使用这些标志进行调整,这些标志将忽略指定的依赖项类型。

配置项:APT :: Cache :: ShowDependencyType(例如,APT :: Cache :: ShowRecommends)。

-f--full

搜索时打印完整的包裹记录。

配置项:APT :: Cache :: ShowFull。

-a--all-versions

打印所有可用版本的完整记录。这是默认值。要关闭它,请使用--no-all-versions。如果指定--no-all-versions,则仅显示候选版本(将选择要安装的版本)。此选项仅适用于show命令。

配置项:APT :: Cache :: AllVersions。

-g--generate

执行程序包高速缓存的自动更新,而不是照原样使用高速缓存。这是默认值。要关闭它,请使用--no-generate。

配置项:APT :: Cache :: Generate。

--names-only-n

仅搜索软件包名称,而不搜索详细说明。

配置项:APT :: Cache :: NamesOnly

.

--all-names

使pkgnames打印所有名称,包括虚拟软件包和缺少的依赖项。

配置项:APT :: Cache :: AllNames。

--recurse

进行makedepend和rdepends递归,以便所有提及的软件包都打印一次。

配置项:APT :: Cache :: RecurseDepends。

--installed

将depends和rdepends的输出限制为当前安装的软件包。

配置项:APT :: Cache :: Installed。

-h--help

显示简短的使用摘要。

-v--version

显示程序版本。

-c--config-file

配置文件;指定要使用的配置文件。该程序将读取默认配置文件,然后读取此配置文件。如果需要在解析默认配置文件之前设置配置设置,请使用APT_CONFIG环境变量指定一个文件。有关语法信息,请参见apt.conf。

-o--option

设置配置选项;这将设置一个任意配置选项。语法为-o Foo :: Bar = bar。-o和--option可以多次使用以设置不同的选项。

档案

/etc/apt/sources.list

获取软件包的位置。

配置项:Dir :: Etc :: SourceList。

/etc/apt/sources.list.d/

用于获取软件包位置的文件片段。

配置项:Dir :: Etc :: SourceParts。

/var/lib/apt/lists/

sources.list中指定的每个包资源的状态信息存储区。

配置项:Dir :: State :: Lists。

/var/lib/apt/lists/partial/

状态信息的存储区域。

配置项:Dir :: State :: Lists

apt-cache [-agipns] [-o=config_string] [-c=config_file]
          {gencaches | showpkg pkg... | showsrc pkg... |
          stats | dump | dumpavail | unmet | search regex... |
          show pkg [{=pkg_version_number | /target_release}]... |
          depends pkg [{=pkg_version_number | /target_release}]... |
          rdepends pkg [{=pkg_version_number | /target_release}]... |
          pkgnames [prefix] | dotty pkg [{=pkg_version_number |
          /target_release}]... | xvcg pkg [{=pkg_version_number |
          /target_release}]... | policy [pkg...] | madison pkg... |
          {-v | --version} | {-h | --help}}

Commands

gencaches

creates or re-creates APT's package cache. This is done implicitly by all commands needing this cache if it is missing or outdated.

showpkg pkg...

displays information about the packages listed on the command line. Remaining arguments are package names. The available versions and reverse dependencies of each package listed are displayed, as well as forward dependencies for each version. Forward (normal) dependencies are those packages upon which the package in question depends; reverse dependencies are those packages that depend upon the package in question. Thus, forward dependencies must be satisfied for a package, but reverse dependencies need not be. For instance, apt-cache showpkg libreadline2 would produce output similar to the following:

Package: libreadline2Versions: 2.1-12(/var/state/apt/lists/foo_Packages),Reverse Depends:libreadlineg2,libreadline2libreadline2-altdev,libreadline2Dependencies:2.1-12 - libc5 (2 5.4.0-0) ncurses3.0 (0 (null))Provides:2.1-12 -Reverse Provides:

Thus it may be seen that libreadline2, version 2.1-12, depends on libc5 and ncurses3.0 which must be installed for libreadline2 to work. In turn, libreadlineg2 and libreadline2-altdev depend on libreadline2. If libreadline2 is installed, libc5, and ncurses3.0 (and ldso) must also be installed; libreadlineg2 and libreadline2-altdev do not have to be installed. For the specific meaning of the remainder of the output it is best to consult the apt source code.

stats

displays some statistics about the cache. No further arguments are expected. Statistics reported are:

  • Total package names is the number of package names found in the cache.
  • Normal packages is the number of regular, ordinary package names; these are packages that bear a one-to-one correspondence between their names and the names used by other packages for them in dependencies. The majority of packages fall into this category.
  • Pure virtual packages is the number of packages that exist only as a virtual package name; that is, packages only "provide" the virtual package name, and no package actually uses the name. For instance, "mail-transport-agent" in the Debian system is a pure virtual package; several packages provide "mail-transport-agent", but there is no package named "mail-transport-agent".
  • Single virtual packages is the number of packages with only one package providing a particular virtual package. For example, in the Debian system, "X11-text-viewer" is a virtual package, but only one package, xless, provides "X11-text-viewer".
  • Mixed virtual packages is the number of packages that either provide a particular virtual package or have the virtual package name as the package name. For instance, in the Debian system, "debconf" is both an actual package, and provided by the debconf-tiny package.
  • Missing is the number of package names that were referenced in a dependency but were not provided by any package. Missing packages may be an evidence if a full distribution is not accessed, or if a package (real or virtual) has been dropped from the distribution. Usually they are referenced from Conflicts or Breaks statements.
  • Total distinct versions is the number of package versions found in the cache; this value is therefore at least equal to the number of total package names. If more than one distribution is being accessed (for instance, "stable" and "unstable"), this value can be considerably larger than the number of total package names.
  • Total dependencies is the number of dependency relationships claimed by all of the packages in the cache.

showsrc pkg...

displays all the source package records that match the given package names. All versions are shown, as well as all records that declare the name to be a binary package.

dump

shows a short listing of every package in the cache. It is primarily for debugging.

dumpavail

dumpavail prints out an available list to stdout. This is suitable for use with dpkg and is used by the dselect method.

unmet

displays a summary of all unmet dependencies in the package cache.

show pkg...

show performs a function similar to dpkg --print-avail; it displays the package records for the named packages.

search regex...

performs a full text search on all available package lists for the POSIX-style regex pattern given. It searches the package names and the descriptions for an occurrence of the regular expression and prints out the package name and the short description, including virtual package names. If --full is given then output identical to show is produced for each matched package, and if --names-only is given then the long description is not searched, only the package name is.

Separate arguments can be used to specify multiple search patterns that are AND'ed together.

depends pkg...

shows a listing of each dependency a package has and all the possible other packages that can fulfill that dependency.

rdepends pkg...

shows a listing of each reverse dependency a package has.

pkgnames [prefix]

This command prints the name of each package APT knows. The optional argument is a prefix match to filter the name list. The output is suitable for use in a shell tab complete function and the output is generated extremely quickly. This command is best used with the --generate option.

Note that a package which APT knows of is not necessarily available to download, installable or installed (e.g., virtual packages are also listed in the generated list).

dotty pkg...

takes a list of packages on the command line and generates output suitable for use by dotty from the GraphViz package. The result will be a set of nodes and edges representing the relationships between the packages. By default, the given packages will trace out all dependent packages; this can produce a very large graph. To limit the output to only the packages listed on the command line, set the APT::Cache::GivenOnly option.

The resulting nodes will have several shapes; normal packages are boxes, pure virtual packages are triangles, mixed virtual packages are diamonds, missing packages are hexagons. Orange boxes mean recursion was stopped (leaf packages), blue lines are pre-depends, green lines are conflicts.

dotty cannot graph larger sets of packages.

xvcg pkg...

The same as dotty, only for xvcg from the VCG tool.

policy [pkg...]

policy is meant to help debug issues relating to the preferences file. With no arguments it will print out the priorities of each source. Otherwise, it prints out detailed information about the priority selection of the named package.

madison pkg...

attempts to mimic the output format and a subset of the functionality of the Debian archive management tool, madison. It displays available versions of a package in a tabular format. Unlike the original madison, it can only display information for the architecture for which APT has retrieved package lists (APT::Architecture).

Options

All command line options may be set using the configuration file, the descriptions indicate the configuration option to set. For boolean options you can override the config file by using something like -f-,--no-f-f=no or other variations.

-p--pkg-cache

Select the file to store the package cache. The package cache is the primary cache used by all operations.

Configuration Item: Dir::Cache::pkgcache.

-s--src-cache

Select the file to store the source cache. The source is used only by gencaches and it stores a parsed version of the package information from remote sources. When building the package cache the source cache is used to avoid reparsing all of the package files.

Configuration Item: Dir::Cache::srcpkgcache.

-q--quiet

Quiet; produces output suitable for logging, omitting progress indicators. More q's will produce more quietness up to a maximum of 2. You can also use -q=# to set the quietness level, overriding the configuration file.

Configuration Item: quiet.

-i--important

Print only important dependencies; for use with unmet and depends. Causes only Depends and Pre-Depends relations to be printed.

Configuration Item: APT::Cache::Important.

--no-pre-depends,
--no-depends,
--no-recommends,
--no-suggests,
--no-conflicts,
--no-breaks,
--no-replaces,
--no-enhances

Per default the depends and rdepends print all dependencies. This can be tweaked with these flags which will omit the specified dependency type.

Configuration Item: APT::Cache::ShowDependencyType (e.g., APT::Cache::ShowRecommends).

-f--full

Print full package records when searching.

Configuration Item: APT::Cache::ShowFull.

-a--all-versions

Print full records for all available versions. This is the default; to turn it off, use --no-all-versions. If --no-all-versions is specified, only the candidate version will be displayed (the one which would be selected for installation). This option is only applicable to the show command.

Configuration Item: APT::Cache::AllVersions.

-g--generate

Perform automatic package cache regeneration, rather than use the cache as it is. This is the default; to turn it off, use --no-generate.

Configuration Item: APT::Cache::Generate.

--names-only-n

Only search on the package names, not the long descriptions.

Configuration Item: APT::Cache::NamesOnly

.

--all-names

Make pkgnames print all names, including virtual packages and missing dependencies.

Configuration Item: APT::Cache::AllNames.

--recurse

Make depends and rdepends recursive so that all packages mentioned are printed once.

Configuration Item: APT::Cache::RecurseDepends.

--installed

Limit the output of depends and rdepends to packages that are currently installed.

Configuration Item: APT::Cache::Installed.

-h--help

Show a short usage summary.

-v--version

Show the program version.

-c--config-file

Configuration File; Specify a configuration file to use. The program will read the default configuration file and then this configuration file. If configuration settings need to be set before the default configuration files are parsed specify a file with the APT_CONFIG environment variable. See apt.conf for syntax information.

-o--option

Set a Configuration Option; This will set an arbitrary configuration option. The syntax is -o Foo::Bar=bar-o and --option can be used multiple times to set different options.

Files

/etc/apt/sources.list

Locations of where to fetch packages.

Configuration Item: Dir::Etc::SourceList.

/etc/apt/sources.list.d/

File fragments for locations of where to fetch packages.

Configuration Item: Dir::Etc::SourceParts.

/var/lib/apt/lists/

Storage area for state information for each package resource specified in sources.list.

Configuration Item: Dir::State::Lists.

/var/lib/apt/lists/partial/

Storage area for state information in transit.

Configuration Item: Dir::State::Lists

查看英文版

查看中文版

apt-cache 例子

apt-cache search opengl

在APT存储库中搜索名称或描述中带有文本opengl的软件包。

apt-cache search opengl

Search the APT repositories for a package with the text opengl in the name or description.

查看英文版

查看中文版