Я хотел бы использовать следующую команду:
$ gnome-screenshot -caf=<file name>
Как передать что-то автоматически сгенерированное, например, Screenshot from 2017-12-07 20-22-56.png
для <file name>
?
Можно использовать 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
и man gnome-screenshot
а также справочник Bash для получения дальнейшей информации.