パイプとダッシュを含むこれらのコマンドがどのように機能するかを説明してください。

パイプとダッシュを含むこれらのコマンドがどのように機能するかを説明してください。

パイプとダッシュを含むこれらのコマンドは、具体的にどのように (そしてなぜ) 機能するのでしょうか?

pacman -Qqdt | sudo pacman -Rns -

答え1

-オプションのない単独のダッシュ( )通常は「標準入力から読み込む」という意味ですこれは、多くのプログラムで使用される非常に一般的な規則です。パイプ は、|あるプログラムの標準出力を別のプログラムの標準入力に接続する方法です。 はpacmanデフォルトでは標準入力から読み取らないため、標準入力から読み取るようにしたい場合は を使用します-

したがって、あなたが示すコマンドは次のように機能します (を参照man pacman)。

  • pacman -Qqdt:

    -Q, --query
           Query the package database. This operation allows you to view installed
           packages and their files, as well as meta-information about individual
           packages (dependencies, conflicts, install date, build date, size). This can
           be run against the local package database or can be used on individual
           package files. In the first case, if no package names are provided in the
           command line, all installed packages will be queried. Additionally, various
           filters can be applied on the package list. See Query Options below.
    
    -q, --quiet
       Show less information for certain query operations. This is useful when
       pacman’s output is processed in a script. Search will only show package
       names and not version, group, and description information; owns will only
       show package names instead of "file is owned by pkg" messages; group will
       only show package names and omit group names; list will only show files and
       omit package names; check will only show pairs of package names and missing
       files; a bare query will only show package names rather than names and
       versions.
    
    -d, --deps
       Restrict or filter output to packages installed as dependencies. This option
       can be combined with -t for listing real orphans - packages that were
       installed as dependencies but are no longer required by any installed
       package.
    
    -t, --unrequired
       Restrict or filter output to print only packages neither required nor
       optionally required by any currently installed package. Specify this option
       twice to include packages which are optionally, but not directly, required
       by another package.
    

    これらのオプションを組み合わせると、「他のパッケージの依存関係としてインストールされたパッケージをデータベースで照会し、パッケージ名のみを表示し、現在インストールされているパッケージに必要のないパッケージのみに出力を制限します」つまり、他の何かに必要だったためにインストールされたが、他の何かが削除されたために不要になったパッケージを表示します。

  • sudo pacman -Rns -:

    -R, --remove
       Remove package(s) from the system. Groups can also be specified to be
       removed, in which case every package in that group will be removed. Files
       belonging to the specified package will be deleted, and the database will be
       updated. Most configuration files will be saved with a .pacsave extension
       unless the --nosave option is used. See Remove Options below.
    
    -n, --nosave
       Instructs pacman to ignore file backup designations. Normally, when a file
       is removed from the system, the database is checked to see if the file
       should be renamed with a .pacsave extension.
    
    -s, --recursive
       Remove each target specified including all of their dependencies, provided
       that (A) they are not required by other packages; and (B) they were not
       explicitly installed by the user. This operation is recursive and analogous
       to a backwards --sync operation, and it helps keep a clean system without
       orphans. If you want to omit condition (B), pass this option twice.
    

    そして-(強調は私による):

    pacman を呼び出すには、操作対象となる可能性のあるオプションとターゲットを指定して操作を指定します。ターゲットは通常、パッケージ名、ファイル名、URL、または検索文字列です。ターゲットは、コマンド ライン引数として指定できます。 さらに、stdin が端末からのものではなく、単一のハイフン (-) が引数として渡された場合、ターゲットは stdin から読み取られます。

    したがって、pacman -Rns -標準入力からパッケージ名を読み取り、バックアップを保持せずに、それらのパッケージ名とその依存関係を削除します。

したがって、コマンド全体は、システム上で不要になったパッケージを見つけて削除します。これは、システムから不要なパッケージを消去するのに便利な方法です。

関連情報