{"id":129636,"date":"2020-12-09T17:00:56","date_gmt":"2020-12-09T14:00:56","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-rename-screenshots-in-linux-cloudsavvy-it\/"},"modified":"2020-12-09T17:00:56","modified_gmt":"2020-12-09T14:00:56","slug":"how-to-rename-screenshots-in-linux-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-rename-screenshots-in-linux-cloudsavvy-it\/","title":{"rendered":"#How to Rename Screenshots in Linux \u2013 CloudSavvy IT"},"content":{"rendered":"<p><strong>&#8220;#How to Rename Screenshots in Linux \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4038\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/f1fee0a0a83b16d260ba2e862cb46eec\/p\/uploads\/2017\/07\/add8ac45.png\" alt=\"Bash Shell\" width=\"1400\" height=\"600\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Many desktop Linux systems save screenshots with names like <code>Screenshot from 2020-11-29 18-57-51.png<\/code>. Often, what you really needed was to rename the files to something more obvious like <code>webinar1.png<\/code>, <code>webinar2.png<\/code>, and so on. Fortunately, renaming a bunch of files is really easy to do on the Linux command line.<\/p>\n<p>The Bash shell is very versatile, and provides different ways to evaluate values and expand variables. One neat evaluation is <em>arithmetic evaluation<\/em>. To perform this evaluation, wrap your arithmetic statement with <code>$((<\/code> and <code>))<\/code>.<\/p>\n<p>The evaluation can also include variable expansion, like <code>$sum<\/code> to resolve into a value. But for convenience, any Bash variables listed between <code>$((<\/code> and <code>))<\/code> are expanded automatically. For example, to increment a variable count by 1, you could type:<\/p>\n<pre>count=$(( count + 1 ))<\/pre>\n<p>This is the same as typing:<\/p>\n<pre>count=$(( $count + 1 ))<\/pre>\n<p>Arithmetic expansion supports the same operators found in other programming languages, including <code>+<\/code> and <code>-<\/code> for addition and subtraction, <code>*<\/code> and <code>\/<\/code> for multiplication and division, and <code>%<\/code> for remainder. You can also use <code>++<\/code> and <code>--<\/code> to increment and decrement a value in a variable. Check the man page for Bash, and scroll down to ARITHMETIC EVALUATION, for the full list of supported operators and their precedence.<\/p>\n<p>To rename all my screenshots, I needed to write this one-line Bash command:<\/p>\n<pre>n=1; for f in Screenshot*.png; do mv -v \"$f\" webinar$n.png; n=$(( n + 1 )); done<\/pre>\n<p>But what does this do?<\/p>\n<p>The first part of the command, <code>n=1<\/code>, initializes the variable <code>n<\/code> to 1.<\/p>\n<p>Then I use a <code>for<\/code> loop to operate on all the files that start with <code>Screenshot<\/code> and end with the <code>.png<\/code> extension. These are usually all the screenshots I captured during my last webinar. If I needed to be more precise, I might include the date in that file specification, such as <code>Screenshot from 2020-11-29*.png<\/code>. The backslashes are literal escapes to preserve the spaces in the file name.<\/p>\n<p>Each iteration of the for loop stores a file name in the f variable. So the <code>mv<\/code> command <code>mv -v \"$f\" webinar$n.png<\/code> renames each file to my preferred file names like <code>webinar1.png<\/code> , <code>webinar2.png<\/code> , and so on. I need quotes around the <code>$f<\/code> variable expansion so the spaces in <code>Screenshot from YYYY-MM-DD hh-mm-ss.png<\/code> don\u2019t cause problems in my <code>mv<\/code> command. If you get an error like <code>mv: target 'webinar1.png' is not a directory<\/code>, you probably didn\u2019t put quotes around the <code>$f<\/code>.<\/p>\n<p>Finally, I increment the value in the <code>n<\/code> variable so it\u2019s ready for the next iteration in the loop. The arithmetic expansion <code>n=$(( n + 1 ))<\/code> increments the <code>n<\/code> variable by 1.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8323\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/cef614fe55fe8cbdef9bb5f5b80fc003\/p\/uploads\/2020\/12\/f9277b35.png\" alt=\"\" width=\"915\" height=\"554\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/>\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener noreferrer\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/8322\/how-to-rename-screenshots-in-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Rename Screenshots in Linux \u2013 CloudSavvy IT&#8221; Many desktop Linux systems save screenshots with names like Screenshot from 2020-11-29 18-57-51.png. Often, what you really needed was to rename the files to something more obvious like webinar1.png, webinar2.png, and so on. Fortunately, renaming a bunch of files is really easy to do on the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":129637,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-129636","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/129636","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=129636"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/129636\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/129637"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=129636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=129636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=129636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}