I have a zsh function which updates my system (.deb packages, pip packages, texlive packages, ...).

It looks like this:

up() {
  emulate -LR zsh
  [[ -d "${HOME}/log" ]] || mkdir "${HOME}/log"
  __update_system 2>&1 | tee -a "${LOGFILE}"

The last line calls the __update_system function and pipes its output to tee, which in turn should display the output on the terminal, and append it to a file, so that I can review it later if something went wrong.

One of the commands executed by __update_system is:

$ apt-file update

It seems to be executed, but its output is not logged in the file. All the other commands (including aptitude update) are logged.

I tried to understand by executing this command in a shell:

$ apt-file update >/tmp/log

Again, apt-file update seems to be executed, but the output is not logged as /tmp/log is empty.

I thought that maybe the output is sent on the standard error, so I tried:

$ apt-file update >/tmp/log 2>&1

But I got the same result, an empty file.

I tried in bash, which also gave me an empty file.

Here are some details about my system:

$ uname -a
Linux ubuntu 4.4.0-135-generic #161-Ubuntu SMP Mon Aug 27 10:45:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

About zsh:

$ zsh --version
zsh 5.5.1-dev-0 (x86_64-pc-linux-gnu)

About bash:

$ bash --version
GNU bash, version 4.4.0(1)-release (x86_64-unknown-linux-gnu)

About apt-file:

$ aptitude show apt-file
Package: apt-file
State: installed
Automatically installed: no
Version: 2.5.5ubuntu1
Priority: optional
Section: universe/admin
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: all
Uncompressed Size: 92,2 k
Depends: perl, curl, libconfig-file-perl, libapt-pkg-perl, liblist-moreutils-perl, libregexp-assemble-perl,
Suggests: openssh-client, sudo
Description: search for files within Debian packages (command-line interface)
 apt-file is a command line tool for searching files contained in packages for the APT packaging system. You can search
 in which package a file is included or list the contents of a package without installing or fetching it.

How to redirect the output of apt-file update into a file?

1 Answer 1

  • apt-file is a perl script.
  • It uses diffindex-download. That is another perl script.
  • That one writes to /dev/tty and not to stdout (the difference is explained on this SO answer)
  • Soooo... this will log the output to logfile.log

    script -c "apt-file update" logfile.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.