Explique como funcionam esses comandos com pipe e dash?

Explique como funcionam esses comandos com pipe e dash?

Como (e por que) esses comandos com barra vertical e traço funcionam exatamente?

pacman -Qqdt | sudo pacman -Rns -

Responder1

Um travessão solitário ( -), sem opção,geralmente significa "ler da entrada padrão". Esta é uma convenção muito comum usada por muitos programas. O pipe, |, é uma forma de conectar a saída padrão de um programa à entrada padrão de outro. Como pacmannão lê a entrada padrão por padrão, se você quiser, use o arquivo -.

Então, os comandos que você mostra fazem (veja 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.
    

    Combinadas, essas opções significam"consultar o banco de dados em busca de pacotes instalados como dependências de outros pacotes, mostrando apenas nomes de pacotes, e restringir a saída aos pacotes não necessários a nenhum pacote atualmente instalado". Em outras palavras, mostre os pacotes que foram instalados porque eram necessários para outra coisa, mas que não são mais necessários porque essa outra coisa foi removida.

  • 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.
    

    E o -(ênfase minha):

    Invocar o pacman envolve especificar uma operação com quaisquer opções e alvos potenciais para operar. Um destino geralmente é um nome de pacote, nome de arquivo, URL ou uma string de pesquisa. Os alvos podem ser fornecidos como argumentos de linha de comando. Além disso, se stdin não for de um terminal e um único hífen (-) for passado como argumento, os alvos serão lidos de stdin.

    Portanto, pacman -Rns -lerá os nomes dos pacotes da entrada padrão e removerá qualquer um deles e suas dependências, sem manter backups.

O comando inteiro, portanto, encontrará pacotes que não são mais necessários em seu sistema e os removerá. É uma maneira útil de limpar seu sistema de pacotes desnecessários.

informação relacionada