AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / unix / Perguntas / 562650
Accepted
user387366
user387366
Asked: 2020-01-18 08:07:32 +0800 CST2020-01-18 08:07:32 +0800 CST 2020-01-18 08:07:32 +0800 CST

Como posso fazer a saída de `time` em zsh ser como bash?

  • 772

Formato do time <command>bash:

$time ./test.sh

real    0m0.000s
user    0m0.006s
sys     0m0.000s

Em zsh:

 $time ./test.sh                                                       
 ./test.sh  0.01s user 0.00s system 94% cpu 0.007 total

Isso sempre me incomodou quando mudei para zsh. Como fazer a saída do timezsh ser como o bash?

bash zsh
  • 1 1 respostas
  • 3377 Views

1 respostas

  • Voted
  1. Best Answer
    Kusalananda
    2020-01-18T08:15:36+08:002020-01-18T08:15:36+08:00

    A timepalavra-chave in zshproduz saída no formato especificado pela variável TIMEFMT.

    O valor padrão desta variável é

    %J  %U user %S system %P cpu %*E total
    

    Você pode alterar isso assim, por exemplo:

    TIMEFMT=$'%J\n%U user\n%S system\n%P cpu\n%*E total'
    

    (isso realmente apenas insere alguns caracteres de nova linha na string de formato padrão)

    O que dá o seguinte tipo de saída:

    $ time sleep 2
    sleep 2
    0.00s user
    0.00s system
    0% cpu
    2.010 total
    

    Ou, um pouco mais próximo do que bashtem:

    $ TIMEFMT=$'real\t%E\nuser\t%U\nsys\t%S'
    $ time sleep 2
    real    2.02s
    user    0.00s
    sys     0.01s
    

    Consulte a documentação da TIMEFMTvariável no zshparammanual.

    No meu sistema (executando o zsh 5.7.1), lê-se

       TIMEFMT
              The format of process time reports with the time keyword.  The
              default is `%J  %U user %S system %P cpu %*E total'.  Recognizes
              the following escape sequences, although not all may be
              available on all systems, and some that are available may not be
              useful:
    
              %%     A `%'.
              %U     CPU seconds spent in user mode.
              %S     CPU seconds spent in kernel mode.
              %E     Elapsed time in seconds.
              %P     The CPU percentage, computed as 100*(%U+%S)/%E.
              %W     Number of times the process was swapped.
              %X     The average amount in (shared) text space used in
                     kilobytes.
              %D     The average amount in (unshared) data/stack space used in
                     kilobytes.
              %K     The total space used (%X+%D) in kilobytes.
              %M     The  maximum memory the process had in use at any time in
                     kilobytes.
              %F     The number of major page faults (page needed to be
                     brought from disk).
              %R     The number of minor page faults.
              %I     The number of input operations.
              %O     The number of output operations.
              %r     The number of socket messages received.
              %s     The number of socket messages sent.
              %k     The number of signals received.
              %w     Number of voluntary context switches (waits).
              %c     Number of involuntary context switches.
              %J     The name of this job.
    
              A star may be inserted between the percent sign and flags
              printing time (e.g., `%*E'); this causes the time to be printed
              in `hh:mm:ss.ttt' format (hours and minutes are only printed if
              they are not zero).  Alternatively, `m' or `u' may be used
              (e.g., `%mE') to produce time output in milliseconds or
              microseconds, respectively.
    
    
    • 20

relate perguntas

  • exportar variáveis ​​​​env programaticamente, via stdout do comando [duplicado]

  • Problema estranho ao passar variáveis ​​do arquivo de texto

  • Enquanto a linha lê mantendo os espaços de escape?

  • ordem de substituição de processos `te` e `bash`

  • Execute um script muito lento até que seja bem-sucedido

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Possível firmware ausente /lib/firmware/i915/* para o módulo i915

    • 3 respostas
  • Marko Smith

    Falha ao buscar o repositório de backports jessie

    • 4 respostas
  • Marko Smith

    Como exportar uma chave privada GPG e uma chave pública para um arquivo

    • 4 respostas
  • Marko Smith

    Como podemos executar um comando armazenado em uma variável?

    • 5 respostas
  • Marko Smith

    Como configurar o systemd-resolved e o systemd-networkd para usar o servidor DNS local para resolver domínios locais e o servidor DNS remoto para domínios remotos?

    • 3 respostas
  • Marko Smith

    apt-get update error no Kali Linux após a atualização do dist [duplicado]

    • 2 respostas
  • Marko Smith

    Como ver as últimas linhas x do log de serviço systemctl

    • 5 respostas
  • Marko Smith

    Nano - pule para o final do arquivo

    • 8 respostas
  • Marko Smith

    erro grub: você precisa carregar o kernel primeiro

    • 4 respostas
  • Marko Smith

    Como baixar o pacote não instalá-lo com o comando apt-get?

    • 7 respostas
  • Martin Hope
    user12345 Falha ao buscar o repositório de backports jessie 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl Por que a maioria dos exemplos do systemd contém WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky Como exportar uma chave privada GPG e uma chave pública para um arquivo 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll status systemctl mostra: "Estado: degradado" 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim Como podemos executar um comando armazenado em uma variável? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S Por que /dev/null é um arquivo? Por que sua função não é implementada como um programa simples? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 Como ver as últimas linhas x do log de serviço systemctl 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - pule para o final do arquivo 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla Por que verdadeiro e falso são tão grandes? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis Substitua a string em um arquivo de texto enorme (70 GB), uma linha 2017-12-30 06:58:33 +0800 CST

Hot tag

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve