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 / ubuntu / Perguntas / 984188
Accepted
orschiro
orschiro
Asked: 2017-12-08 11:23:48 +0800 CST2017-12-08 11:23:48 +0800 CST 2017-12-08 11:23:48 +0800 CST

Como posso gerar automaticamente um nome de arquivo para gnome-screenshot?

  • 772

Gostaria de usar o seguinte comando:

$ gnome-screenshot -caf=<file name>

Como posso passar algo gerado automaticamente como Screenshot from 2017-12-07 20-22-56.pngfor <file name>?

command-line
  • 1 1 respostas
  • 708 Views

1 respostas

  • Voted
  1. Best Answer
    Videonauth
    2017-12-08T11:38:52+08:002017-12-08T11:38:52+08:00

    Você pode usar o datecomando para a tarefa de incluir a data e hora reais no nome do arquivo. Vamos ver o que podemos encontrar na datepágina de manual :

    OPERANDS

       The following operands shall be supported:
    
       +format   When the format is specified, each conversion specifier shall
                 be replaced in  the  standard  output  by  its  corresponding
                 value.  All  other  characters  shall be copied to the output
                 without change. The output shall always be terminated with  a
                 <newline>.
    

    Especificações de conversão %a Nome abreviado do dia da semana da localidade.

                 %A      Locale's full weekday name.
    
                 %b      Locale's abbreviated month name.
    
                 %B      Locale's full month name.
    
                 %c      Locale's appropriate date and time representation.
    
                 %C      Century  (a  year  divided by 100 and truncated to an
                         integer) as a decimal number [00,99].
    
                 %d      Day of the month as a decimal number [01,31].
    
                 %D      Date in the format mm/dd/yy.
    
                 %e      Day of the month as a decimal number [1,31] in a two-
                         digit field with leading <space> character fill.
    
                 %h      A synonym for %b.
    
                 %H      Hour (24-hour clock) as a decimal number [00,23].
    
                 %I      Hour (12-hour clock) as a decimal number [01,12].
    
                 %j      Day of the year as a decimal number [001,366].
    
                 %m      Month as a decimal number [01,12].
    
                 %M      Minute as a decimal number [00,59].
    
                 %n      A <newline>.
    
                 %p      Locale's equivalent of either AM or PM.
    
                 %r      12-hour  clock time [01,12] using the AM/PM notation;
                         in the POSIX locale,  this  shall  be  equivalent  to
                         %I:%M:%S %p.
    
                 %S      Seconds as a decimal number [00,60].
    
                 %t      A <tab>.
    
                 %T      24-hour clock time [00,23] in the format HH:MM:SS.
    
                 %u      Weekday as a decimal number [1,7] (1=Monday).
    
                 %U      Week  of  the  year  (Sunday  as the first day of the
                         week) as a decimal number [00,53]. All days in a  new
                         year  preceding  the first Sunday shall be considered
                         to be in week 0.
    
                 %V      Week of the year (Monday as  the  first  day  of  the
                         week)  as  a  decimal  number  [01,53].  If  the week
                         containing January 1 has four or more days in the new
                         year,  then it shall be considered week 1; otherwise,
                         it shall be the last week of the previous  year,  and
                         the next week shall be week 1.
    
                 %w      Weekday as a decimal number [0,6] (0=Sunday).
    
                 %W      Week  of  the  year  (Monday  as the first day of the
                         week) as a decimal number [00,53]. All days in a  new
                         year  preceding  the first Monday shall be considered
                         to be in week 0.
    
                 %x      Locale's appropriate date representation.
    
                 %X      Locale's appropriate time representation.
    
                 %y      Year within century [00,99].
    
                 %Y      Year with century as a decimal number.
    
                 %Z      Timezone name, or no characters  if  no  timezone  is
                         determinable.
    
                 %%      A <percent-sign> character.
    
                 See  the  Base  Definitions  volume  of POSIX.1‐2008, Section
                 7.3.5, LC_TIME for the conversion  specifier  values  in  the
                 POSIX locale.
    

    Como datenão pode ter espaços formatados em sua saída você teria que usar dois comandos de data como mostrado abaixo, primeiro para a data você pode usar +\%Y.\%m.\%dcomo parâmetro que resultará em um formato de data como 2017.12.07e para a hora que você pode usar +\%H:\%M:\%So que resultará em um formato como 20:37:18.

    A opção da área de transferência ( -c) não funciona junto com a opção salvar como nome do arquivo ( -f) de gnome-screenshot, então você deve escolher qualquer uma delas. Este comando fará isso (apenas edite o cback in se precisar da área de transferência, mas deixe o fe o nome do arquivo fora, ambos não funcionarão juntos):

    gnome-screenshot -af "Screenshot from $(date +\%Y.\%m.\%d) $(date +\%H:\%M:\%S).png"
    

    Ele gera um nome de arquivo como o seguinte (apenas com a data e hora reais em que você chama este comando):

    Screenshot from 2017.12.07 20:37:18.png
    

    No entanto, isso armazenará o arquivo dentro do diretório em que você está atualmente, para adicionar um caminho como ~/Picturesvocê precisa fornecer um caminho completo, pois ~não é expandido entre as aspas. O seguinte salvaria os arquivos, por exemplo, em sua pasta de imagens:

    gnome-screenshot -af "/home/$USER/Pictures/Screenshot from $(date +\%Y.\%m.\%d) $(date +\%H:\%M:\%S).png"
    

    Ou você se livra das aspas, o que significa que você pode usar o til ( ~), mas precisa escapar de todos os espaços no nome:

    gnome-screenshot -af ~/Pictures/Screenshot\ from\ $(date +\%Y.\%m.\%d)\ $(date +\%H:\%M:\%S).png
    

    Consulte man datee man gnome-screenshottambém o Manual de referência do Bash para obter mais detalhes.

    • 1

relate perguntas

Sidebar

Stats

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

    Existe um comando para listar todos os usuários? Também para adicionar, excluir, modificar usuários, no terminal?

    • 9 respostas
  • Marko Smith

    Como excluir um diretório não vazio no Terminal?

    • 4 respostas
  • Marko Smith

    Como descompactar um arquivo zip do Terminal?

    • 9 respostas
  • Marko Smith

    Como instalo um arquivo .deb por meio da linha de comando?

    • 11 respostas
  • Marko Smith

    Como instalo um arquivo .tar.gz (ou .tar.bz2)?

    • 14 respostas
  • Marko Smith

    Como listar todos os pacotes instalados

    • 24 respostas
  • Martin Hope
    Flimm Como posso usar o docker sem sudo? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    led-Zepp Como faço para salvar a saída do terminal em um arquivo? 2014-02-15 11:49:07 +0800 CST
  • Martin Hope
    ubuntu-nerd Como descompactar um arquivo zip do Terminal? 2011-12-11 20:37:54 +0800 CST
  • Martin Hope
    TheXed Como instalo um arquivo .deb por meio da linha de comando? 2011-05-07 09:40:28 +0800 CST
  • Martin Hope
    Ivan Como listar todos os pacotes instalados 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    David Barry Como determino o tamanho total de um diretório (pasta) na linha de comando? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher "Os seguintes pacotes foram retidos:" Por que e como resolvo isso? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford Como os PPAs podem ser removidos? 2010-07-30 01:09:42 +0800 CST

Hot tag

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

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