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

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

パイプとダッシュを含むコマンドは正確にどのように(そしてなぜ)機能しますか?

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 -パッケージ名は標準入力から読み取られ、すべてのパッケージ名とその依存関係はバックアップを保持せずに削除されます。

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

おすすめ記事