AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 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

如何为 gnome-screenshot 自动生成文件名?

  • 772

我想使用以下命令:

$ gnome-screenshot -caf=<file name>

我怎样才能传递自动生成的东西,比如Screenshot from 2017-12-07 20-22-56.pngfor <file name>?

command-line
  • 1 1 个回答
  • 708 Views

1 个回答

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

    您可以使用该date命令将实际日期和时间包含在文件名中。让我们看看我们可以在date手册页中找到什么:

    操作数

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

    转换规范 %a 区域设置的缩写工作日名称。

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

    由于date不能将空格格式化到其输出中,因此您必须使用两个日期命令,如下所示,首先是您可以+\%Y.\%m.\%d用作参数的日期,这将导致日期格式类似于2017.12.07您可以使用的时间,+\%H:\%M:\%S这将导致像20:37:18.

    剪贴板选项 ( -c) 不能与 的另存为文件名选项 ( -f)一起使用gnome-screenshot,因此您必须选择其中一个。此命令将执行此操作(c如果您需要剪贴板,只需编辑背面,然后f将文件名和文件名取出,两者不会一起工作):

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

    它会生成一个如下所示的文件名(仅包含您调用此命令的实际日期和时间):

    Screenshot from 2017.12.07 20:37:18.png
    

    但是,这会将文件存储在您当前所在的目录中,以添加~/Pictures您需要提供完整路径的路径,因为~不会在引号内展开。例如,以下会将文件保存在您的图片文件夹中:

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

    或者你去掉引号,这意味着你可以使用波浪号(~)但是你必须转义名称中的所有空格:

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

    有关更多详细信息,请参阅man date和Bash 参考手册。man gnome-screenshot

    • 1

相关问题

  • 如何从命令行仅安装安全更新?关于如何管理更新的一些提示

  • 如何从命令行刻录双层 dvd iso

  • 如何从命令行判断机器是否需要重新启动?

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

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

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve