“apt-get update”가 정확한 출력을`apt update`로 표시하게하십시오


8

Advanced Packaging Tool의 CLI 인터페이스를 배우고 있습니다. apt(8)stdout이 터미널이 아닌 경우 의 출력에서 "안정적인 프로그래밍 인터페이스를 기대하는 스크립트"에는 적합하지 않으므로을 살펴 보겠습니다 apt-get(8).

사이의 한 가지 차이점 apt updateapt-get update모든 캐시가 업데이트 된 후, 후자는 최종 라인이 누락되어 있다는 것입니다 :

8 packages can be upgraded. Run 'apt list --upgradable' to see them.

이 정확한 줄을 표시하는 방법을 알고 싶습니다 apt-get(8).


내가 아는 한 apt(Advanced Packaging Tool) apt-get은 다릅니다. 그것들은 내가 이해 한 것과 다르게 실행되도록 설계되었습니다. 만약 당신이 원하는 것을 주면, 대신 그 명령을 사용하는 습관을들이십시오.
Brenden McFarling

답변:


9

man apt-get 보여줍니다 :

   -s, --simulate, --just-print, --dry-run, --recon, --no-act
       No action; perform a simulation of events that would occur based on
       the current system state but do not actually change the system.
       Locking will be disabled (Debug::NoLocking) so the system state
       could change while apt-get is running. Simulations can also be
       executed by non-root users which might not have read access to all
       apt configuration distorting the simulation. A notice expressing
       this warning is also shown by default for non-root users
       (APT::Get::Show-User-Simulation-Note). Configuration Item:
       APT::Get::Simulate.

그래서 당신이 방금한다면 :

apt-get upgrade --dry-run

출력됩니다 :

...
4 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
...

예, 나는 man 8 apt-get그 옵션을 찾았지만 출력은과 다릅니다 apt.
iBug

어떻게 다른가요? 방금 시스템을 확인했는데 동일합니다. 나는 apt실제로 프로그래밍 방식의 래퍼 이기 때문에 그것이 동일하다고 생각했고 apt-get이것이 경고가 존재하는 이유입니다.
tu-Reinstate Monica-dor duh

apt8 packages can be upgraded. Run 'apt list --upgradable' to see them., 동안 당신의 대답 쇼4 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
iBug

1
그렇습니다. 제가 4 개 위치에서 업그레이드해야 할 것이 8 개이기 때문입니다.
tu-Reinstate Monica-dor duh

4
예, 이것이 바로 경고에 관한 것입니다. apt해당 텍스트를 보증하지 않으며 해당 숫자를 보증하지 않을 수도 있습니다. apt-get그러나 UI 및 데몬과 같은 다른 소프트웨어에서 다양한 방법으로 처리하기 때문에 출력 요구 사항이 엄격합니다. 따라서 코드를 변경하여 apt-get출력 을 수락 하거나 | sed 's/to upgrade/packages can be upgraded/g'예를 들어 코드를 나중에 손상시킬 수 있습니다.
tu-Reinstate Monica-dor duh

4

사용 가능한 업데이트 수를 처리해야한다고 추측하면 다음과 같이 제안합니다.

# With no option, returns two numbers, no CR nor LF
/usr/lib/update-notifier/apt-check

# With --human-readable, returns numbers, locale LANG text & CR/LF
/usr/lib/update-notifier/apt-check  --human-readable

sudo 할 필요가 없습니다
. 출력 작업이 쉽습니다.

더 많은 옵션 :

> /usr/lib/update-notifier/apt-check  --help
Usage: apt-check [options]

Options:
  -h, --help            show this help message and exit
  -p, --package-names   Show the packages that are going to be
                        installed/upgraded
  --human-readable      Show human readable output on stdout
  --security-updates-unattended
                        Return the time in days when security updates are
                        installed unattended (0 means disabled)

이것은 motdSSH 로그인 에서 생성 하는 데 사용되는 정확한 것 입니까?
iBug

예, 그것은 같은 출력처럼 보이지만 어떻게 motd
합니까

2

보낸 사람 man 8 apt:

... 일부 옵션을 활성화합니다 ...

그런 다음 텍스트 내용을 표시 /usr/share/doc/apt/examples/configure-index.gz하는 zcat(1)데 사용 하여이 옵션을 발견했습니다.

apt::cmd::show-update-stats

그래서 내가 원하는 것을 정확하게 수행 한 다음 명령을 수행했습니다.

# apt-get -o apt::cmd::show-update-stats=true update

Xenial 및 Bionic에서 작동하는 것으로 테스트되었습니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.