<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.tordeu.com &#187; Linux</title>
	<atom:link href="http://blog.tordeu.com/?cat=13&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.tordeu.com</link>
	<description>a blog about stuff</description>
	<lastBuildDate>Thu, 25 Apr 2013 07:03:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.2</generator>
		<item>
		<title>Changing PATH to include /sbin or: How to fix &#8220;bash: ldconfig: command not found&#8221;</title>
		<link>http://blog.tordeu.com/?p=374</link>
		<comments>http://blog.tordeu.com/?p=374#comments</comments>
		<pubDate>Fri, 08 Jun 2012 00:23:51 +0000</pubDate>
		<dc:creator>tordeu</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[PATH]]></category>
		<category><![CDATA[profile]]></category>
		<category><![CDATA[sbin]]></category>

		<guid isPermaLink="false">http://blog.tordeu.com/?p=374</guid>
		<description><![CDATA[It&#8217;s been a while, but in the oh so distant past I stumbled upon the following error on my then fairly new Debian Wheezy system: bash: ldconfig: command not found You might encounter this error or something very similar, especially when you are using sudo instead of changing to root with su (see my article <a href='http://blog.tordeu.com/?p=374'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s been a while, but in the oh so distant past I stumbled upon the following error on my then fairly new Debian Wheezy system:</p>
<pre>bash: ldconfig: command not found</pre>
<p>You might encounter this error or something very similar, especially when you are using sudo instead of changing to root with su (<a title="How to enable sudo in Linux (here: Debian Squeeze)?" href="http://blog.tordeu.com/?p=31">see my article on how to enable sudo</a>).</p>
<p>&nbsp;</p>
<h2>Problem</h2>
<p>The problem is that programs like ldconfig are located in the  /sbin folder, but this folder is not added to the PATH variable.</p>
<p>If you don&#8217;t know what PATH is:</p>
<p>The path variable is essentially a list of folders. When you type a command in bash (the terminal/command line) like this:</p>
<pre>ldconfig</pre>
<p>then bash will go through all the folders listed in the PATH variable and see if a program with that name is in that folder. If it finds that program, it will execute it.</p>
<p>The problem here is that PATH (the list of directories where bash will look for the program) does not contain the folder /sbin. But because the program is in this folder and bash does not look there, bash will not find the program and instead annoy you with an error.</p>
<p>&nbsp;</p>
<h2>Solution</h2>
<p>The solution is to add  &#8220;/sbin&#8221; to the PATH variable. This can be done by editing the file &#8220;/etc/profile&#8221;.</p>
<p>Type</p>
<pre>sudo nano /etc/profile</pre>
<p>or &#8211; if you are more comfortable with a GUI based text editor &#8211; you can also type</p>
<pre>sudo gedit /etc/profile</pre>
<p>&nbsp;</p>
<p>At the beginning of the file, you will see the following:</p>
<pre>if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi</pre>
<p>This sets the PATH variable for the root user and every other user. The first line that starts with &#8220;PATH=&#8230;&#8221; sets the PATH for the root user and the second line sets PATH for everybody else. So the code fragment basically translates to:</p>
<pre>if user=root then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
otherwise
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"</pre>
<p>The second line is what we have to care right now. The directories in the list are separated by a colon, so the list contains the following directories:</p>
<ul>
<li>
<pre>/usr/local/bin</pre>
</li>
<li>
<pre>/usr/bin</pre>
</li>
<li>
<pre>/bin</pre>
</li>
<li>
<pre>/usr/local/games</pre>
</li>
<li>
<pre>/usr/games</pre>
</li>
</ul>
<p>We want to add a few directories to that, namely:</p>
<ul>
<li>
<pre>/usr/local/sbin</pre>
</li>
<li>
<pre>/usr/sbin</pre>
</li>
<li>
<pre>/sbin</pre>
</li>
</ul>
<p>For ldconfig and a lot of other programs, adding &#8220;/sbin&#8221; would be enough, but I added the others as well, because I thought: &#8220;I don&#8217;t wanna come back two more times, just because I might realize later that I should have added them as well in the first place&#8221;</p>
<p>You could add the directories anywhere in the list, but I like to add them in the same order they appear in the PATH variable for the root user, so I will change the beginning of the file to this (remember to separate the directories with a colon):</p>
<pre>if user=root then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
otherwise
  PATH="<span style="color: #ff0000;">/usr/local/sbin:</span>/usr/local/bin:<span style="color: #ff0000;">/usr/sbin:</span>/usr/bin:<span style="color: #ff0000;">/sbin:</span>/bin:/usr/local/games:/usr/games"
fi</pre>
<p>Save the file; when using nano, just</p>
<ul>
<li>hit &#8220;Ctrl+X&#8221; to quit</li>
<li>then &#8220;Y&#8221; to confirm that you want to save the modified version</li>
<li>then hit the enter key to confirm the filename</li>
</ul>
<p>And finally: Log out and log back in.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tordeu.com/?feed=rss2&#038;p=374</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using Aliases in Bash</title>
		<link>http://blog.tordeu.com/?p=289</link>
		<comments>http://blog.tordeu.com/?p=289#comments</comments>
		<pubDate>Sun, 22 Jan 2012 12:53:56 +0000</pubDate>
		<dc:creator>tordeu</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Alias]]></category>
		<category><![CDATA[Aliases]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://blog.tordeu.com/?p=289</guid>
		<description><![CDATA[Introduction What Aliases Are Here is a short introduction to aliases in case you have not idea what they are: An alias is simply a different name for a specific command line command. You can call an alias like any other program and the shell will then replace the alias with the command it represents. <a href='http://blog.tordeu.com/?p=289'>[...]</a>]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<h3>What Aliases Are</h3>
<p>Here is a short introduction to aliases in case you have not idea what they are:</p>
<p>An alias is simply a different name for a specific command line command. You can call an alias like any other program and the shell will then replace the alias with the command it represents.</p>
<p>If you find yourself typing&#8221;aptitude&#8221; a lot you could, for example, define an alias &#8220;a&#8221; for this command instead. Now, instead of typing</p>
<pre>aptitude install &lt;package&gt;</pre>
<p>you just need to type</p>
<pre>a install &lt;package&gt;</pre>
<p>Bash will recognize that the command a is really just an alias that stands for &#8220;aptitude&#8221; and therefore replace a with &#8220;aptitude&#8221;. You could make your like even easier by assigning an alias &#8220;ai&#8221; to the command &#8220;aptitude install&#8221;. Then, when typing</p>
<pre>ai &lt;package&gt;</pre>
<p>bash will notice that the command &#8220;ai&#8221; is really just an alias for &#8220;aptitude install&#8221; and replace &#8220;ai&#8221; accordingly. Therefore, the command that bash will execute is:</p>
<pre>aptitude install &lt;package&gt;</pre>
<p><span id="more-289"></span></p>
<h3>Permanently Storing Your Aliases</h3>
<p>It is important to note than running the commands below will only change the alias definitions for the current shell. The changes will not appear in other shells and they will be lost when closing the shell (and logout/shutdown/reboot). This basically means that the changes are only temporary.</p>
<p>Therefore, if you want to permanently define new aliases, you can create new file named</p>
<pre>.bash_aliases</pre>
<p>in your homefolder (the file will most likely not exist already) and put all you alias definitions in there. Alternatively you can add the definitions to the file</p>
<pre>.bashrc</pre>
<p>in your home folder, but it&#8217;s cleaner to have a separate file for the aliases and the .bashrc should already check for a file named .bash_aliases, so you only need to create the .bash_aliases and the file will automatically loaded.</p>
<p>It is important to note that the .bashrc and therefore the .bash_aliases will only be read when the shell is created. Therefore, you won&#8217;t see the changes to .bash_aliases immediately. You need to either create a new shell after saving your modified .bash_aliases or (re)load the .bash_aliases file like this:</p>
<pre>. ~/.bash_aliases</pre>
<p>You can, of course, create an an alias for this command in your .bash_aliases file&#8230;</p>
<p>&nbsp;</p>
<h2>List All Aliases</h2>
<p>To get a list of all aliases which are currently defined, all you need to do is to run:</p>
<pre>alias</pre>
<p>This will list all defined aliases, one per line, like this:</p>
<pre>alias la='ls -la'
alias ls='ls --color=auto'
alias lx='ls -lAh --group-directories-first'</pre>
<p>&nbsp;</p>
<h2>List A Specific Alias</h2>
<p>To only get the value of a specific alias, you can type:</p>
<pre>alias &lt;name&gt;</pre>
<p>You can also use this command to display several aliases:</p>
<pre>alias &lt;name1&gt; &lt;name2&gt; ...</pre>
<h3>Example 1</h3>
<pre>alias la</pre>
<p>will display</p>
<pre>alias la='ls -la'</pre>
<h3>Example 2</h3>
<pre>alias ls la</pre>
<p>will display:</p>
<pre>alias ls='ls --color=auto'
alias la='ls -la'</pre>
<h2></h2>
<h2>Create A New Alias / Change An Existing Alias</h2>
<p>Creating a new alias or changing the value of an existing alias can be done in the same way:</p>
<pre>alias &lt;name&gt;=&lt;value&gt;</pre>
<p>For example, creating an alias &#8220;www&#8221; to avoid typing &#8220;cd /var/www&#8221; all the time, can be done like this:</p>
<pre>alias www='cd /var/www'</pre>
<p>&nbsp;</p>
<h3>Combining Aliases</h3>
<p>When defining an alias it is possible to use another alias. Let me show you two examples of how this might be put to use:</p>
<h4>Supplying (additional) options</h4>
<p>The only predefined alias on Debian is</p>
<pre>ls='ls --color=auto</pre>
<p>By defining an alias la like this:</p>
<pre>alias la='ls -la'</pre>
<p>You already used an alias for defining the new alias. When typing</p>
<pre>la</pre>
<p>bash will now recognize that &#8220;la&#8221; is an alias and replace it with its value:</p>
<pre>ls -la</pre>
<p>But now, again, bash will recognize that &#8220;ls&#8221; is an alias as well and replace this will its value &#8220;ls &#8211;color=auto&#8221;, which results in the command:</p>
<pre>ls --color=auto -la</pre>
<p>(bash will not recognize ls an alias again, so this is where it stops)</p>
<p>In this example the alias &#8220;la&#8221; used the already defined alias &#8220;ls&#8221; (which adds coloring to the command ls) to add the additional options &#8220;-l&#8221; and &#8220;-a&#8221; to it. This can be used for various purposes. If you want to define various aliases for the ls command, for example, it might be a good idea to create an alias that already contains the common options (like coloring) you want to use for all the other aliases. This will shorten the alias values, which makes them easier to manage. Instead of defining the following aliases:</p>
<pre>alias la='ls -la --color=auto'
alias lh='ls -lh --color=auto'
alias lx='ls -lAh --color=auto --group-directories-first'</pre>
<p>you could define them like this:</p>
<pre>alias la='ls -a'
alias lh='ls -h'
alias ls='ls -l --color=auto'
alias lx='lh -A --group-directories-first'</pre>
<p>In this example the alias ls already carried the &#8220;-l&#8221; and &#8220;&#8211;color=auto&#8221; option, therefore avoiding the others to specify them as well. The definition of the lx alias uses the lh alias, which additionally carries the &#8220;-h&#8221; option. You should be careful when using this approach, because creating two many connections between aliases can make management more complicated instead of simplifying it and also create some unwanted side effects.</p>
<p>&nbsp;</p>
<h4> Supplying (additional) arguments</h4>
<p>Similar to applying additional command line options, you can supply additional arguments to</p>
<p>&nbsp;</p>
<h2>Delete An Alias</h2>
<p>To delete an alias you need to use the unalias command:</p>
<pre>unalias &lt;name&gt;</pre>
<p>It is also possible to delete several aliases at once:</p>
<pre>unalias &lt;name1&gt; &lt;name2&gt; ...</pre>
<h3>Example</h3>
<p>To delete the www alias that we just created, type:</p>
<pre>unalias www</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tordeu.com/?feed=rss2&#038;p=289</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disable GNOME3&#8242;s Habbit Of Turning Off The Display After Some Time.</title>
		<link>http://blog.tordeu.com/?p=292</link>
		<comments>http://blog.tordeu.com/?p=292#comments</comments>
		<pubDate>Sun, 15 Jan 2012 04:29:32 +0000</pubDate>
		<dc:creator>tordeu</dc:creator>
				<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[GNOME]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.tordeu.com/?p=292</guid>
		<description><![CDATA[Gnome3 has the annoying habbit of turning off the monitor after a while, even if you are watching a video. Unfortunately, if you go to System Settings &#62; Screen   you will be surprised that if offers you the possibility to change the time the system has to be idle for the monitor to be <a href='http://blog.tordeu.com/?p=292'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p>Gnome3 has the annoying habbit of turning off the monitor after a while, even if you are watching a video. Unfortunately, if you go to</p>
<address>System Settings &gt; Screen</address>
<address> </address>
<p>you will be surprised that if offers you the possibility to change the time the system has to be idle for the monitor to be turned off from 1 minute to 1 hour. But what is missing is an option to turn this function off entirely.</p>
<p>Fortunately, it is possible to do that, just not in System Settings and you can either do that from command line or with a GUI.</p>
<p><span id="more-292"></span></p>
<h2>Explanation</h2>
<p>I will not explain GSettings here, but just in case you don&#8217;t know: GSettings (which replaces GConf) is used to store the configuration of the GNOME desktops. Don&#8217;t worry, you don&#8217;t need to know GSettings to follow the instructions below. But GSettings is also used to store the information about when to turn off the display. The keys that are important here are the following:</p>
<pre>org.gnome.settings-daemon.plugins.power sleep-display-ac
org.gnome.settings-daemon.plugins.power sleep-display-battery
org.gnome.desktop.session idle-delay</pre>
<p>Those are the keys that the System Settings GUI is changing when you use it.</p>
<p>The first two determine when the display is turned off (on a desktop system that is always plugged in the first value is the important one. The second key is used in case the system is running on a battery, which is important for portable devices like notebooks and tablets).</p>
<p>The third key is important, because it is used to determine when to start the screensaver and lock the screen, although there are additional values that target those two in org.gnome.desktop.session.</p>
<p><span style="text-decoration: underline;">The values of all three keys are in seconds (so a value of 600 stands for 600s = 10min).</span></p>
<p>But because the System Settings GUI does change these three keys altogether and there is a connection between these three, it is probably a good idea for most people to change all three to the same value by hand as well.</p>
<p>&nbsp;</p>
<h2>Using Command Line</h2>
<p>You can use the gsettings command to change the values of the keys.</p>
<p>First, let&#8217;s see what the values of these keys are. You can do that by running the following three commands.</p>
<pre>gsettings get org.gnome.settings-daemon.plugins.power sleep-display-ac
gsettings get org.gnome.settings-daemon.plugins.power sleep-display-battery
gsettings get org.gnome.desktop.session idle-delay</pre>
<p>Each command will print the value of the given key. You will notice (most likely) that all three values are equal and that they reflect the value that is displayed in System Settings. If you change the value in System Settings, you will notice that these three keys do change accordingly.</p>
<p>To set these by hand you can use the following three commands:</p>
<pre>gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac &lt;value&gt;
gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery &lt;value&gt;
gsettings set org.gnome.desktop.session idle-delay &lt;value&gt;</pre>
<p>Just replace &lt;value&gt; with the number of seconds you want the system to wait before turning off the display (and potentially locking the screen). To tell the system that it should let the display turned on forever, you can use the value 0:</p>
<pre>gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 0
gsettings set org.gnome.settings-daemon.plugins.power sleep-display-battery 0
gsettings set org.gnome.desktop.session idle-delay 0</pre>
<p>&nbsp;</p>
<h2>Using A GUI</h2>
<p>To change the keys you can use &#8220;dconf Editor &#8220;. You can start the program by one of the following ways:</p>
<ul>
<li>go to Applications and either</li>
<ul>
<li>search for dconf or</li>
<li>look for it under &#8220;System Tools&#8221; or</li>
</ul>
<li>press Alt+F2 and enter: dconf-editor or</li>
<li>open a terminal and run &#8220;dconf-editor&#8221;</li>
</ul>
<p>Once dconf Editor starts, you will see the following window:</p>
<div id="attachment_297" class="wp-caption aligncenter" style="width: 534px"><a href="http://blog.tordeu.com/wp-content/uploads/2012/01/1.png"><img class="size-full wp-image-297 " title="dconf-editor_1" src="http://blog.tordeu.com/wp-content/uploads/2012/01/1.png" alt="dconf-editor 1" width="524" height="463" /></a><p class="wp-caption-text">The dconf-editor window after starting the I</p></div>
<p>On the left side you now need to navigate to &#8220;org.gnome.settings-daemon.plugins.power&#8221; (that means: open &#8220;org&#8221;, then &#8211; within &#8220;org&#8221; &#8211; open &#8220;gnome&#8221; and so on until you reach &#8220;power&#8221;). Then, you need to find the keys &#8220;sleep-display-ac&#8221; and &#8220;sleep-display-battery&#8221; on the right side:</p>
<div id="attachment_301" class="wp-caption aligncenter" style="width: 696px"><a href="http://blog.tordeu.com/wp-content/uploads/2012/01/2b.png"><img class="size-full wp-image-301" title="dconf-editor 2b" src="http://blog.tordeu.com/wp-content/uploads/2012/01/2b.png" alt="dconf-editor 2b" width="686" height="596" /></a><p class="wp-caption-text">The dconf-edtior window after navigating to the first key</p></div>
<p>Change both numbers to 0 to prevent the system from turning off the display.</p>
<p>After that you should navigate to &#8220;org.gnome.desktop.session&#8221; on the left side and change the key &#8220;idle-delay&#8221; (on the right side) to 0 as well.</p>
<p>After that, just quit the editor (the changes are automatically saved).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tordeu.com/?feed=rss2&#038;p=292</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to use Ctrl+Alt+F1 etc. in a Virtual Machine in VirtualBox</title>
		<link>http://blog.tordeu.com/?p=322</link>
		<comments>http://blog.tordeu.com/?p=322#comments</comments>
		<pubDate>Sat, 07 Jan 2012 08:56:22 +0000</pubDate>
		<dc:creator>tordeu</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[VirtualBox]]></category>

		<guid isPermaLink="false">http://blog.tordeu.com/?p=322</guid>
		<description><![CDATA[Problem When using a virtual machine in VirtualBox you might want to switch to a different console by hitting Ctrl+Alt+F&#60;n&#62;   where &#60;n&#62; stands for the number of the console you want to access (like Ctrl+Alt+F1 to get a text console and Ctrl+Alt+F7 to get back to your X session). Unfortunately, key combinations with Ctrl+Alt <a href='http://blog.tordeu.com/?p=322'>[...]</a>]]></description>
				<content:encoded><![CDATA[<h2>Problem</h2>
<p>When using a virtual machine in VirtualBox you might want to switch to a different console by hitting</p>
<address>Ctrl+Alt+F&lt;n&gt;</address>
<address> </address>
<p>where &lt;n&gt; stands for the number of the console you want to access (like Ctrl+Alt+F1 to get a text console and Ctrl+Alt+F7 to get back to your X session).</p>
<p>Unfortunately, key combinations with Ctrl+Alt like the mentioned Ctrl+Alt+F&lt;n&gt; or Ctrl+Alt+Del will not be sent to the guest operating system. <span id="more-322"></span>Instead, Ctrl+Alt+F&lt;n&gt; will only let you change consoles on your host and Ctrl+Alt+Del will magically disappear and effect neither the host nor the guest OS.</p>
<p>VirtualBox offers two menu entries (under the menu entry &#8220;Machine&#8221;) to send Ctrl+Alt+Del and Ctrl+Alt+Backspace to the guest OS, but does not offer such a feature for other key combinations.</p>
<p>&nbsp;</p>
<h2>Solution</h2>
<p>Fortunately, you can use the host key (the right Ctrl key by default) as a substitute for Ctrl+Alt. Therefore when pressing</p>
<pre>HOST+F&lt;n&gt;</pre>
<p>VirtualBox will send</p>
<address>Ctrl+Alt+F&lt;n&gt;</address>
<address> </address>
<p>to the guest OS and this will let you change consoles in your guest and also use other key combination that include Ctrl+Alt.</p>
<p>&nbsp;</p>
<h2>Links</h2>
<p><a title="Link to the corresponding section in the VirtualBox User Manual" href="https://www.virtualbox.org/manual/ch01.html#idp7685232">https://www.virtualbox.org/manual/ch01.html#idp7685232</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tordeu.com/?feed=rss2&#038;p=322</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>rename &#8211; Batch renaming files in command line</title>
		<link>http://blog.tordeu.com/?p=112</link>
		<comments>http://blog.tordeu.com/?p=112#comments</comments>
		<pubDate>Thu, 08 Dec 2011 16:05:52 +0000</pubDate>
		<dc:creator>tordeu</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux Commands]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command line]]></category>

		<guid isPermaLink="false">http://blog.tordeu.com/?p=112</guid>
		<description><![CDATA[&#160; There are several ways one can batch rename files in Linux. One of the possibilities is the linux command rename. Usage To rename files you have to supply a Perl expression. Using Perl expressions might be scary for beginners (because they look like someone hit his head on the keyboard), but they allow for <a href='http://blog.tordeu.com/?p=112'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p>There are several ways one can batch rename files in Linux. One of the possibilities is the linux command rename.</p>
<h2>Usage</h2>
<p>To rename files you have to supply a Perl expression. Using Perl expressions might be scary for beginners (because they look like someone hit his head on the keyboard), but they allow for complex renaming with a minimum of characters.</p>
<p>Although I won&#8217;t go into detail about Perl expressions here, I will try to make it a little easier for beginners to use them for batch renaming.</p>
<p>According to the man page of rename, this is the way to use rename:</p>
<pre>rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]</pre>
<p>If you have not worked with Perl expressions before, this might not be enough to get you started. So let me present you with the way one would probably use rename most of the time:</p>
<pre>rename 's/<span style="color: #00ccff;">OLD</span>/<span style="color: #00ccff;">NEW</span>/' <span style="color: #00ccff;">FILES</span></pre>
<p>OLD is an expressions which describes a pattern in the name filenames. If rename can find this pattern in the name of a file, it will replace this part of the filename with what is defined as NEW. The files rename should rename are defined by FILES.</p>
<p>Let me provide you with two examples:<span id="more-112"></span></p>
<h2>Examples</h2>
<h3>Example 1 &#8211; Replacing a single word/string</h3>
<p>Let&#8217;s start with a very simple example: Imagine, you have a lot of images that are named</p>
<pre>picture 1.jpg
picture 2.jpg
...</pre>
<p>and you would like to replace the word &#8220;picture&#8221; with the word &#8220;image&#8221;, so that the files will be named like this:</p>
<pre>image 1.jpg
image 2.jpg
...</pre>
<p>As describes under usage, OLD represents the part that we want to replace. As we want  to replace the word &#8220;picture&#8221;, in this example OLD will be &#8220;picture&#8221;.</p>
<p>And because NEW defines with what OLD is replaced with, in our example. We want the OLD(=&#8221;picture&#8221;) to be replaced with &#8220;image&#8221;, so here NEW=&#8221;image&#8221;.</p>
<p>And because we want to do this only for all the pictures which name starts with &#8220;picture&#8221; FILES will be &#8220;picture*.jpg&#8221;.</p>
<p>Therefore the general command</p>
<pre>rename 's/OLD/NEW/' FILES</pre>
<p>becomes:</p>
<pre>rename 's/picture/image/' picture*.jpg</pre>
<p>It might have not been necessary for us to restrict this to the the files &#8220;picture*.jpg&#8221;. We might have just used *.jpg (all files in the current directory with the extension .jpg) or even * (all files in the current directory), because rename will only change the filename, if the pattern OLD (here: &#8220;picture&#8221;) is found in the filename. You have to be careful, though. A file with the name &#8220;just a picture.jpg&#8221; would have been renamed to &#8220;just a image.jpg&#8221;, because we told rename to replace &#8220;picture&#8221; with &#8220;image&#8221;.</p>
<h3>Example 2</h3>
<p>Let&#8217;s go back to Example 1. One problem I mentioned is that running</p>
<pre>rename 's/picture/image' *.jpg</pre>
<p>to rename files like &#8220;picture 23.jpg&#8221; to &#8220;image 23.jpg&#8221; would also rename files like &#8220;just a picture.jpg&#8221; to &#8220;just a image.jpg&#8221;, because rename would find the word &#8220;picture&#8221; and replace it with &#8220;image&#8221;, although this is not what we intended.</p>
<p>We could prevent this by calling rename like this:</p>
<pre>rename 's/picture/image' picture*.jpg</pre>
<p>This would call rename only for the .jpg files starting with the word &#8220;picture&#8221;. But this is not really a solution, because files like &#8220;picture of a sunset.jpg&#8221; would still be renamed to &#8220;image of a sunset.jpg&#8221;.</p>
<p>To make sure that rename really does what we want it to do, we need to be very clear about what should be renamed. Because what we want is not to replace the word &#8220;picture&#8221; with the word &#8220;image&#8221; in every case, we want to replace the word &#8220;picture&#8221; with the word &#8220;image&#8221;, but only for the files which name consists of the word &#8220;picture&#8221;, then a space and then a number and then the extension &#8220;.jpg&#8221;.</p>
<p>This can be achieved with the following command:</p>
<pre>rename 's/^picture( [0-9]*\.jpg)$/image$1/' *.jpg</pre>
<p>This might look a little scary, but is a good example of what you can do with Perl expressions. Because this would only rename the desired files. Files like &#8220;my picture 11.jpg&#8221; or &#8220;picture 28 (beach).jpg&#8221; would not be renamed and in this example that is exactly what we want to do.</p>
<p>Let me go through the different parts of the expression above briefly, to give you an idea of how this works. Keep in mind that this just an example and not intended as a complete tutorial. I will just try to explain to you the various elements of this expression to show you some of the possibilities and to demystify them a little bit.</p>
<p>When you compare the command to the general form under &#8220;Usage&#8221;, you will see that in this case:</p>
<ul>
<li>OLD = ^picture( [0-9]*\.jpg)$</li>
<li>NEW = image$1</li>
<li>FILES = *.jpg</li>
</ul>
<p>In this example OLD makes sure that only the desired files are renamed by defining the structure of what we are looking for exactly. This works, because OLD defines what should be renamed. That means that files where the pattern/structure defined by OLD can not be found will not be renamed. Therefore, OLD automatically works as a filter to make sure that only the desired files get renamed. The trick is to make sure that OLD and NEW reflect what you wish to do. Let&#8217;s dissect it:</p>
<p>Let&#8217;s ignore the &#8220;^&#8221; at the beginning, the &#8220;$&#8221; at the end, the parentheses and the &#8220;\&#8221;  at the moment. This leaves the following:</p>
<pre>picture [0-9]*.jpg</pre>
<p>This describes our basic structure. First, we have the word &#8220;picture&#8221;, then a space. [0-9] means any character from 0 to 9, which essentially means &#8220;a digit&#8221; and when putting a &#8220;*&#8221; after it, it means that there can be &#8220;any number of&#8221; digits. We need this, because we don&#8217;t know how many digits there will be. We can have files like &#8220;picture 7.jpg&#8221;, where there is only 1 digit or files like &#8220;picture 1432.jpg&#8221;, where he have four of them. So, &#8220;[0-9]*&#8221; stands for &#8220;any number of digits&#8221;, which just means: a number. And then we have &#8220;.jpg&#8221;, our extensions.</p>
<p>It is important to note that  &#8220;[0-9]*&#8221; really means &#8220;any number of digits&#8221; and that &#8220;any number&#8221; could also mean 0. This means that the number is optional and a file named &#8220;picture .jpg&#8221; would also be renamed. In this example it probably would not make a real difference, but in general you need to be careful. If there really has to be a number and it can not be optional, you can use a &#8220;+&#8221; instead of a &#8220;*&#8221;, because &#8220;[0-9]+&#8221; means &#8220;at least one digit&#8221;.  But because it will not be a problem in this case, we will keep the &#8220;*&#8221;.</p>
<p>Now, let&#8217;s add the parts we ignored:</p>
<p>The &#8220;.&#8221; is a special character which stand for &#8220;any character&#8221;. But in our pattern, we want to make clear that the filename ends with &#8220;.jpg&#8221;. But &#8220;.jpg&#8221; would be interpreted as &#8220;any character, then j, then p, then g&#8221;. Therefore a file like &#8220;picture 234Xjpg&#8221; would be renamed, because the . (which stand for &#8220;any character&#8221;) would be &#8220;X&#8221; in this case. But really want to make sure that the file ends with &#8220;.jpg&#8221; and therefore need to make it clear that the &#8220;.&#8221; really stand for &#8220;.&#8221; and not for &#8220;any character&#8221;. This can be done by escaping it with a &#8220;\&#8221;. Therefore, we need to write &#8220;\.jpg&#8221;.</p>
<p>The parentheses are added, because the pattern we are creating will be matching the complete filename. If we would run a command like this:</p>
<pre>rename 's/^picture [0-9]*\ .jpg$/image/' *.jpg</pre>
<p>A file like &#8220;picture 23.jgp&#8221; would be renamed to &#8220;image&#8221; and not to &#8220;image 23.jpg&#8221;. This is because our pattern &#8220;^picture [0-9]*\.jpg$&#8221; describes the whole filename. So the complete filename would be replace with &#8220;image&#8221;. But we just want to replace &#8220;picture&#8221; and keep the rest.</p>
<p>We can do this by telling rename that we want to keep everything after &#8220;picture&#8221;. While we can&#8217;t do this directly, we can put every after &#8220;picture&#8221; in parentheses and then later use this part to build our new filename, because everything within the parentheses will be saved accessible later as &#8220;$1&#8243;, so if we use the pattern</p>
<pre>picture( [0-9]*\.jpg)</pre>
<p>We can now see that the space, the number and the extension &#8220;.jpg&#8221; are within the parentheses and we can access this part as &#8220;$1&#8243;. When the filename is &#8220;picture 83.jpg&#8221;, $1 will therefore contain &#8221; 83.jpg&#8221;. Then, when we define our replacement, we can tell rename to use &#8220;image$1&#8243; as our replacement for the filename. Because $1 contains the space, the number and the extension, this would translate to &#8220;image 83.jpg&#8221;.</p>
<p>Now, what&#8217;s left are &#8220;^&#8221; and &#8220;$&#8221;. &#8220;^&#8221; stand for the beginning of the filename. This makes sure that files like &#8220;some picture 44.jpg&#8221; would not be renamed. This is because a pattern like &#8220;picture&#8221; means: find the word picture anywhere. Whereas &#8220;^picture&#8221; essentially means: find the word picture at the beginning of the input(=filename).</p>
<p>Similarly, &#8220;$&#8221; stand for the end of the input (here: filename). We use this to make sure that something like &#8220;picture 74.jpg.gz&#8221; does not get renamed.</p>
<p>Combining &#8220;^&#8221; and &#8220;$&#8221; therefore ensures that the filename only consists of the pattern we defined and there is nothing before &#8220;picture&#8221; and nothing after our &#8220;.jpg&#8221;.</p>
<p>Therefore, our final pattern is:</p>
<pre>^picture( [0-9]*\.jpg)$</pre>
<p>And the command to rename the files is, again:</p>
<pre>rename 's/^picture [0-9]*\ .jpg$/image/' *.jpg</pre>
<h3>Example 4 &#8211; add a prefix to all filenames (added on 2012-05-20)</h3>
<p>In case you want to add a prefix at the beginning of a filename, you can use this line:</p>
<p>rename &#8216;s/(.*)/PREFIX$1/&#8217; FILES</p>
<p>Substitute PREFIX to whatever you want to put in front of the filename and substitute FILES for the files you want to rename (see Example 6 below for some examples)</p>
<p>If you run</p>
<p>rename &#8216;s/(.*)/foo_$1/&#8217; *.txt</p>
<p>All the .txt files in the current directory will get an &#8220;foo_&#8221; in front of of their name. (So info.txt would be renamed to foo_info.txt, for example)</p>
<p>&nbsp;</p>
<h3>Example 5 &#8211; add a suffix to all filenames (added on 2012-05-20)</h3>
<p>Adding a suffix at the end of a filename can be as simple as adding a prefix; you could simply run:</p>
<pre>rename 's/(.*)/$1SUFFIX/' FILES</pre>
<p>The problem is that this might not be what you expected, because the suffix will be added at the end of the filename, which also means after the suffix the file might already have to denote its type (e.g. &#8220;.txt&#8221;, &#8220;.tar&#8221;, &#8220;.jpg&#8221; etc. Running</p>
<pre>rename 's/(.*)/$1boo/' info.tar</pre>
<p>would rename the file &#8220;info.tar&#8221; to &#8220;info.tar.boo&#8221;. If that is what you want, you can use the line above, but if you would want to rename it to &#8220;infoboo.tar&#8221;, then you can use the following line:</p>
<pre>rename 's/(.*)\.(.*)/$1SUFFIX.$2/' FILES</pre>
<p>with this, running</p>
<pre>rename 's/(.*)\.(.*)/$1boo.$2/' FILES</pre>
<p>would rename &#8220;info.tar&#8221; to &#8220;infoboo.tar&#8221;.</p>
<p>Be aware that this will not work for files with suffixes that contain two dots (like &#8220;archive.tar.gz&#8221;).</p>
<h4>Improvement 1 (Update 2012-05-22):</h4>
<p>The fact that files like &#8220;archive.tar.gz&#8221; would be renamed as well and the result would certainly not be as hoped, we can try to improve the pattern above a little bit:</p>
<pre>rename 's/^([^.]*)\.([^.]*)$/$1SUFFIX.$2/' FILES</pre>
<p>This approach will only rename files that only contain a single dot and leave all other files alone.</p>
<h4>Improvement 2 (Update 2012-05-22):</h4>
<p>If you want to rename files with extensions like &#8220;.tar.gz&#8221; correctly, you can use the following approach:</p>
<pre>rename 's/^([^.]*)\.(.*)$/$1SUFFIX.$2/' FILES</pre>
<p>This will essentially add the suffix directly in front of the first dot. However, this approach will not work in case you have files that contain dots that are not supposed to be part of the file extension (in &#8220;some.great.file.txt&#8221;, the suffix &#8220;111&#8243; would be added like this: &#8220;some111.great.file.txt&#8221;)</p>
<h3>Example 6 &#8211; how to define which files to rename (added on 2012-05-20)</h3>
<p>In the beginning I noted the general form of how to use rename:</p>
<pre>rename 's/OLD/NEW/' FILES</pre>
<p>I now want to give you some simple examples of what you can do with &#8220;FILES&#8221;, which tells rename which files it<br />
should try to rename in the first place. This list is by no means complete. It just provides you with a few (hopefully useful) examples.</p>
<ul>
<li>to rename a single file just state its name. Example: backup.tar</li>
<li>to rename several specific files just list all their names. Example: backup.tar mypicture.jpg asong.ogg</li>
<li>to rename all files in the current directory just use &#8220;*&#8221; (without the &#8220;).</li>
<li>to rename all files with a specific ending (e.g. .jpg) use &#8220;*ENDING&#8221;. Example: *.jpg</li>
<li>to rename files with different endings, just list them all. Example: *.jpg *.jpeg *.mp3 *.txt *.ar</li>
<li>to rename files that start with the same word/characters use &#8220;START*&#8221;. Example: my* old*</li>
<li>to rename files that contain the same word/sequence of characters use &#8220;*WITHIN*&#8221;. Example: *good*</li>
<li>you can combine all of those things. Example: my*.txt *boo*.jpg foo* test.tmp</li>
</ul>
<p>&nbsp;</p>
<h2>Conclusion</h2>
<p>I hope that this article succeeds in demonstrating how rename can be used to batch rename files (not in detail, but at least in pushing you in the right direction). And I also hope that while covering Perl expressions in detail is beyond the scope of this article, the second example gives you an idea of how powerful and useful they can be and why it can make sense to learn more about them.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tordeu.com/?feed=rss2&#038;p=112</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>mkdir &#8211; Creating directories with the Linux command mkdir</title>
		<link>http://blog.tordeu.com/?p=262</link>
		<comments>http://blog.tordeu.com/?p=262#comments</comments>
		<pubDate>Thu, 01 Dec 2011 21:52:23 +0000</pubDate>
		<dc:creator>tordeu</dc:creator>
				<category><![CDATA[Linux Commands]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[create directories]]></category>
		<category><![CDATA[create directory]]></category>
		<category><![CDATA[directories]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[mkdir]]></category>

		<guid isPermaLink="false">http://blog.tordeu.com/?p=262</guid>
		<description><![CDATA[The Linux command mkdir (make directory/make directories) can be used to create new directories. Basic Usage Creating directories in the current working directory The most basic usage of mkdir is the following: mkdir &#60;name&#62; This will create a new directory with the given name in the current directory. Therefore, if your username is &#8220;me&#8221; and <a href='http://blog.tordeu.com/?p=262'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p>The Linux command mkdir (make directory/make directories) can be used to create new directories.</p>
<h2>Basic Usage</h2>
<h3>Creating directories in the current working directory</h3>
<p>The most basic usage of mkdir is the following:</p>
<pre>mkdir &lt;name&gt;</pre>
<p>This will create a new directory with the given name in the current directory. Therefore, if your username is &#8220;me&#8221; and in the terminal you are using you are currently in your home folder (/home/me) then running the command</p>
<pre>mkdir backup</pre>
<p>will create a the directory /home/me/backup.</p>
<p><span id="more-262"></span></p>
<h3>Creating directories using relative or absolute paths</h3>
<p>You do not need to be in a directory do create a new directory in it. You can, for example, use relative or absolute  paths to create them.</p>
<p>Let&#8217;s assume you are in your home folder (/home/me) and you just created the folder backup (/home/me/backup). And now you want to create a folder named &#8220;old&#8221; in it. Then you can either call mkdir with a relative path:</p>
<pre>mkdir backup/old</pre>
<p>or with the absolute path:</p>
<pre>mkdir /home/me/backup/old</pre>
<p>&nbsp;</p>
<p>Note, however, that if you would call</p>
<pre>mkdir backup/old</pre>
<p>and the directory &#8220;backup&#8221; would not exist already in the current folder, then you would get an error.  This is, because calling mkdir like this:</p>
<pre>mkdir &lt;path&gt;/&lt;name&gt;</pre>
<p>will create the directory &lt;name&gt; in the directory &lt;path&gt; only if &lt;path&gt; already exists. Otherwise, mkdir will quit with an error message. This is the default behavior of mkdir.</p>
<p>&nbsp;</p>
<h2>Options</h2>
<p>There are a few options which can be quite useful when creating directories.</p>
<h3>-p, &#8211;parents</h3>
<p>Under &#8220;Basic Usage&#8221;, I mentioned that the path you want to create a new directory in, needs to exists or otherwise you will get an error. You can use the option &#8220;-p&#8221; or &#8220;&#8211;parents&#8221; to change that behavior. With this option, mkdir will create all the directories that don&#8217;t exists already, not just the last one. If you would call</p>
<pre>mkdir -p backup/old</pre>
<p>or</p>
<pre>mkdir --parents backup/old</pre>
<p>in your home directory and the directory &#8220;backup&#8221; would not exist already, then the -p options will tell mkdir to create this directory as well instead of quitting with an error message. This option is therefore very useful if you need to create a directory, but you are not sure if the directory you want to create it in already exists. Even if you know that this directory does not exist yet, you can use the -p option to reduce the number of necessary calls.</p>
<p>If you know that there currently is no backup (or are not sure) and you want to create the folder backup/old, then calling</p>
<pre>mkdir backup/old</pre>
<p>could result in an error if the directory &#8220;backup&#8221; would not exist. This is a problem especially in scripts. Without the -p option you would have to make two calls to mkdir; one to create the &#8220;backup&#8221; directory (to ensure it is there) and one to create the directory &#8220;old&#8221; itself:</p>
<pre>mkdir backup
mkdir old</pre>
<p>When creating deeper directory structures, more than two calls might be needed. Think about creating the folder &#8220;backup/server/2011/11/30&#8243; in your home folder (/home/me). You would have to create every folder separately:</p>
<pre>mkdir backup
mkdir backup/server
mkdir backup/server/2011
mkdir backup/server/2011/11
mkdir backup/server/2011/11/30</pre>
<p>With the -p option you just need to call mkdir once:</p>
<pre>mkdir -p backup/server/2011/11/30</pre>
<p>and everything will be created for you.</p>
<p>&nbsp;</p>
<p>It is also worth noting that using the &#8220;-p&#8221; option will prevent errors in case the directory already exists. Without the &#8220;-p&#8221; option, running</p>
<pre>mkdir backup</pre>
<p>would result in the following error message in case the directory backup already exists:</p>
<pre>mkdir: cannot create directory `backup': File exists</pre>
<p>However, running</p>
<pre>mkdir -p backup</pre>
<p>will prevent the error message from being printed. Running mkdir with the  &#8220;-p&#8221; can therefore be interpreted as &#8220;make sure the following directory exists&#8221;.</p>
<p>&nbsp;</p>
<h3>-v, &#8211;verbose</h3>
<p>When using the &#8220;-v&#8221;/&#8221;&#8211;verbose&#8221; option, mkdir will ouput a message for the directory  it created.</p>
<p>Calling</p>
<pre>mkdir backup</pre>
<p>will therefore either output</p>
<pre>mkdir: created directory `backup'</pre>
<p>if the directory did not exist already or print the previously mentioned error message in case the directory was already there. When combining the &#8220;-v&#8221; option&#8221; with the &#8220;-p&#8221; option, mkdir will output a message for every directory it created.</p>
<p>Typing</p>
<pre>mkdir -p -v backup/server/2011/11/30</pre>
<p>or even shorter</p>
<pre>mkdir -pv backup/server/2011/11/30</pre>
<p>would create the following output if none of the directories would already exist:</p>
<pre>mkdir: created directory `backup'
mkdir: created directory `backup/server'
mkdir: created directory `backup/server/2011'
mkdir: created directory `backup/server/2011/11'
mkdir: created directory `backup/server/2011/11/30'</pre>
<p>If, for example, the directory &#8220;backup/server&#8221; already existed, then mkdir would only need to create the last three directories and therefore the output would be:</p>
<pre>mkdir: created directory `backup/server/2011'
mkdir: created directory `backup/server/2011/11'
mkdir: created directory `backup/server/2011/11/30'</pre>
<p>Using this option therefore provides feedback about which directories already existed and which had to be created. Because the &#8220;-p&#8221; option suppresses error messages about already existing directories, you won&#8217;t get error messages about the fact that &#8220;backup&#8221; and &#8220;backup/server&#8221; could not be created, because they were already there. The messages from mkdir about which directories have been created would therefore only implicitly tell you which directories existed beforehand.</p>
<h3>-m, &#8211;mode=MODE</h3>
<p>Using the &#8220;-m&#8221; option you can set the permission on the directory you want to create. If you want to create a directory which should be  fully accessible by everyone, you could type</p>
<pre>mkdir -m 777 backup</pre>
<p>or</p>
<pre>mkdir -m a=rwx backup</pre>
<p>It is important to note that when combining this option with the &#8220;-p&#8221; option, the mode only affects the last directory. Calling</p>
<pre>mkdir -p -m 777 backup/server/2011/11/30</pre>
<p>would therefore create all the directories necessary, but the permissions specified with the &#8220;-m&#8221; option will be only assigned to the directory &#8220;30&#8243; and not to the other directories. Their permissions are instead determined by the current umask.</p>
<p>It is also worthy to note that the permissions of the directory &#8220;30&#8243; would not be changed in case it already existed. This is especially important to point out, because the &#8220;-p&#8221; option will prevent all error messages about already existing directories. Therefore, running this command does not give you any feedback about the permissions the directory &#8220;30&#8243; has after running the command. If it already existed, the permissions will be left untouched and if it didn&#8217;t exist, the permissions will be set as defined by the &#8220;-m&#8221; option.</p>
<p>Therefore, if you are not sure if the directory already existed, but want to make sure that the permissions are set correctly, you could either run the command with the -v option (which will then tell you if the directory &#8220;30&#8243; was created) and then use chmod if necessary or &#8211; if you are writing a script &#8211; you should just run chmod afterwards instead of using the &#8220;-m&#8221; option:</p>
<pre>mkdir -p backup/server/2011/11/30
chmod 777 backup/server/2011/11/30</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tordeu.com/?feed=rss2&#038;p=262</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating Screenshots of Virtual Machines [VirtualBox]</title>
		<link>http://blog.tordeu.com/?p=130</link>
		<comments>http://blog.tordeu.com/?p=130#comments</comments>
		<pubDate>Sun, 27 Nov 2011 23:54:16 +0000</pubDate>
		<dc:creator>tordeu</dc:creator>
				<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[virtual machine]]></category>

		<guid isPermaLink="false">http://blog.tordeu.com/?p=130</guid>
		<description><![CDATA[If you ever wanted to create screenshots of a virtual machine (for a tutorial, a presentation, a forum post or any other reason), you probably already noticed that the VirtualBox GUI does not offer a screenshot function. Although using additional programs (like GIMP, for example) would get the job done, you do not need them, <a href='http://blog.tordeu.com/?p=130'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p>If you ever wanted to create screenshots of a virtual machine (for a tutorial, a presentation, a forum post or any other reason), you probably already noticed that the VirtualBox GUI does not offer a screenshot function.</p>
<p><span id="more-130"></span>Although using additional programs (like GIMP, for example) would get the job done, you do not need them, because VirtualBox does offer screenshot functionality on the command line. And using the built-in function has two advantages:</p>
<ul>
<li>The screenshot will only include what is seen in the virtual machine and won&#8217;t include the VirtualBox window the machine is running in or even the whole Desktop, so there is no need to edit the screenshot.</li>
<li>The screenshots can be made without user-interaction, which is nice if you need to create screenshots automatically with a script or a cron job (e.g. if you want to take a screenshot every 5 minutes &#8211; for whatever reason you might have &#8211; you could completely automate the task).</li>
</ul>
<p>The command to take a screenshot generally looks like this:</p>
<pre>VBoxManage controlvm &lt;uuid&gt; screenshotpng &lt;file&gt;</pre>
<p>or like this</p>
<pre>VBoxManage controlvm &lt;name&gt; screenshotpng &lt;file&gt;</pre>
<p>depending on whether you want to use the UUID or the name of the virtual machine. The name for the virtual machine can be obtained directly from the VirtualBox Manager window or from the window of the running virtual machine:</p>
<div id="attachment_227" class="wp-caption aligncenter" style="width: 703px"><a href="http://blog.tordeu.com/wp-content/uploads/2011/11/VirtualBox-Screenshot3.png"><img class="size-full wp-image-227" title="VirtualBox-Screenshot3" src="http://blog.tordeu.com/wp-content/uploads/2011/11/VirtualBox-Screenshot3.png" alt="Obtaining the name of a virtual machine" width="693" height="379" /></a><p class="wp-caption-text">Obtaining the name of a virtual machine</p></div>
<p>As you can see in the screenshot, the name of the virtual machine is &#8220;Debian Server 1&#8243;.</p>
<p>If we wanted to take a screenshot of the machine and save it as &#8220;server.png&#8221;, we could therefore use the following command:</p>
<pre>VBoxManage controlvm "Debian Server 1" screenshotspng server.png</pre>
<p>And this is what the screenshot would look like:</p>
<div id="attachment_228" class="wp-caption aligncenter" style="width: 730px"><a href="http://blog.tordeu.com/wp-content/uploads/2011/11/snapshot.png"><img class="size-full wp-image-228" title="snapshot" src="http://blog.tordeu.com/wp-content/uploads/2011/11/snapshot.png" alt="Screenshot of a virtual machine" width="720" height="400" /></a><p class="wp-caption-text">Screenshot of the virtual machine</p></div>
<p>&nbsp;</p>
<h2>Appendix: Using UUIDs</h2>
<h3>UUIDs vs Names</h3>
<p>You might also want to think about using the UUID instead of the name of a virtual machine, depending on your situation. Both have their advantages and disadvantages, especially when working with scripts. I am not going to cover this topic in-depth, but let give you something to think about. The advantage of using UUIDs is that you can rename your virtual machines without having to edit the scripts which reference the, directly, because the UUID will stay the same. This is especially useful if you might want to migrate your virtual machine to a different host, because if the new host already has a virtual machine with the same name you have to rename one of them.</p>
<p>But now think of the following situation: You have a virtual machine named &#8220;server&#8221; that you want to migrate to a new host. And you wrote some scripts that somehow work with this VM by using it&#8217;s name. The new host already has a VM named &#8220;server&#8221;, which prevents importing the VM.  So you just rename the VM you want to migreate to &#8220;server2&#8243; and add it, which works great, because there was no VM with the name &#8220;server2&#8243; before.  But now your scripts, which reference a VM called &#8220;server&#8221;, suddenly work on the VM which was already there and not on the VM you migrated (which is now called &#8220;server2&#8243;) and for which the scripts were written. It&#8217;s very easy to forget to alter your scripts to reflect the name change after renaming a virtual machine. But an even bigger problem is: Because there still is a VM called &#8220;server&#8221;, you don&#8217;t even get an error message.</p>
<p>On the other side, two advantages of using the name of the virtual machine that I can think of, are the fact that the name is very easy to see and change in the VirtualBox GUI, so working with VM names in VirtualBox is easier. And if you use the command line,  typing a name is certainly easier and faster (depending on the names you use, of course) than typing the UUID.</p>
<p>Therefore, I personally prefer using the names when using the command line directly and using the UUIDs in scripts.</p>
<h3>Getting the UUID</h3>
<p>In case you want to get the UUID of a virtual machine, you can type the following:</p>
<pre>VBoxManage showvminfo &lt;name&gt;</pre>
<p>This will print a  lot of info, though. To just get the line with the UUID, you can type:</p>
<pre>VBoxManage showvminfo &lt;name&gt; | grep ^UUID</pre>
<p>In this example, you would type:</p>
<pre> VBoxManage showvminfo "Debian Server 1" | grep ^UUID</pre>
<p>which  gives you something like this:</p>
<pre>UUID:        e9e99378-3332-42f4-a6a3-d5490123fe33</pre>
<p>And if you really just want the UUID, you might use the following:</p>
<pre>VBoxManage showvminfo "Debian Server 1" | grep ^UUID | sed 's/UUID: *//'</pre>
<p>to get an output like this:</p>
<p>9e99378-3332-42f4-a6a3-d5490123fe33</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tordeu.com/?feed=rss2&#038;p=130</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting FLAC to MP3 (including Tags) on command line</title>
		<link>http://blog.tordeu.com/?p=184</link>
		<comments>http://blog.tordeu.com/?p=184#comments</comments>
		<pubDate>Wed, 23 Nov 2011 07:29:14 +0000</pubDate>
		<dc:creator>tordeu</dc:creator>
				<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[flac]]></category>
		<category><![CDATA[metaflac]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://blog.tordeu.com/?p=184</guid>
		<description><![CDATA[ (Download the script from this article ) When converting FLAC files to MP3, the first problem you will notice is that lame does not support FLAC files. This might now seem like big problem, because you can easily decode FLAC files using the command line tool flac and then use the decoded file with lame. <a href='http://blog.tordeu.com/?p=184'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p style="text-align: right;"> (Download the script from this article <a href="http://blog.tordeu.com/downloads/2">flac2mp3.sh</a>)</p>
<p>When converting FLAC files to MP3, the first problem you will notice is that lame does not support FLAC files. This might now seem like big problem, because you can easily decode FLAC files using the command line tool flac and then use the decoded file with lame.</p>
<h2>The Problem</h2>
<p>The real problem is that you will loose your metadata in this process, so the tags you added to your FLAC won&#8217;t be copied to the MP3 file. While you could &#8220;easily&#8221; add them by hand, it is pretty annoying to do that even if you only want to convert a handful of files.</p>
<p><span id="more-184"></span></p>
<h2>The solution</h2>
<p>The solution is to extract the metadata from the FLAC file using metaflac and to use the options lame provides to inject the tags into the MP3 file when calling lame.</p>
<p>Note:</p>
<p>This section is merely provided to explain the steps involved. You do not need to read this nor do you need to do this by hand, since I offer you a small script that will do these steps for you (look at the very first line of the article or below under &#8220;Download&#8221; to download the script).</p>
<h3>Step 1 &#8211; Extract the Metadata</h3>
<p>To extract a single tag, you can use metaflac like this:</p>
<pre>metaflac --show-tag=&lt;tag&gt; &lt;file&gt;</pre>
<p>To extract the artist of the track from the file named &#8220;1 &#8211; Let It In.flac&#8221;, you could call:</p>
<pre>metaflac --show-tag=ARTIST "1 - Let It In.flac"</pre>
<p>&nbsp;</p>
<p>In general you will get a result like this:</p>
<pre>&lt;TAG&gt;=&lt;VALUE&gt;</pre>
<p>In the mentioned example you might get the following:</p>
<pre>ARTIST=Josh Woodward</pre>
<h3></h3>
<h3> Step 2 &#8211; Fomat the Metadata</h3>
<p>We only need the name of the artist, so we need to get rid of  &#8220;ARTIST=&#8221;. This can be easily achieved with sed.  The general way of replacing something with sed is this:</p>
<pre>sed 's/OLD/NEW/'</pre>
<p>OLD is the part that you want to replace and NEW is the part that you want to replace it with. What we want to replace is &#8220;ARTIST=&#8221; (which is our OLD) and what we want to replace it with is nothing (which will essentially remove OLD), so our NEW is empty. And this is what we get:</p>
<pre>sed 's/ARTIST=//'</pre>
<p>But that would only work for the ARTIST tag. A general solution would be to remove anything up to and including the equal sign. I won&#8217;t go into detail on this one, but this would be achieved by setting OLD to &#8220;.*=&#8221; and the line would look like this:</p>
<pre>sed 's/.*=//'</pre>
<p>To make this work, we need to we need to pass the output of metaflac to our sed command, which we would do like this:</p>
<pre>metaflac --show-tag=ARTIST "1 - Let It In.flac" | sed 's/.*=//'</pre>
<p>This way the output of metaflac (&#8220;ARTIST=Josh Woodward&#8221;) is send to our sed command, which then removes the &#8220;ARTIST=&#8221; part and thus we get the output:</p>
<pre>Josh Woodward</pre>
<p>&nbsp;</p>
<h3>Step 3 &#8211; Store the tag</h3>
<p>While the line from Step 2 works, it merely prints the tag. What we need to do is to store the tag somehow, so that we can use it again later for adding the tag to the MP3 file. To store the output of a command in a variable, you generally type:</p>
<p>&lt;var&gt;=`&lt;command&gt;`</p>
<p>(Those are not single quotes in this line, but backticks/grave accents) This will execute &lt;command&gt; and then store the output to the variable &lt;var&gt;.</p>
<p>In this example we could do this:</p>
<p>ARTIST=`metaflac &#8211;show-tag=ARTIST &#8220;1 &#8211; Let It In.flac&#8221; | sed &#8216;s/.*=//&#8217;`</p>
<p>This would execute out metaflac command and save the output (&#8220;Josh Woodward&#8221;) in the variable ARTIST.</p>
<p>We can test if everything worked by printing the value of ARTIST:</p>
<pre>echo $ARTIST</pre>
<p>which should now give us:</p>
<pre>Josh Woodward</pre>
<p>&nbsp;</p>
<h3>Step 4 &#8211; Passing the tags to lame</h3>
<p>In general, calling lame (and using VBR mode) would work like this:</p>
<pre>lame -V &lt;oldfile&gt; &lt;mp3file&gt;</pre>
<p>If you want lame to save metadata to the mp3 file, you can use several options do to this. To continue our example, let&#8217;s assume we want to add the name of the artist (that we have stored in the variable ARTIST in the last step) to the new MP3 file. This can be done with the &#8211;ta option:</p>
<pre>lame -V --ta "$ARTIST" &lt;oldfile&gt; &lt;mp3file&gt;</pre>
<p>In a similar way, we can add other tags to the mp3 file as well. Here is a small table that shows you the options lame offers to add metadata, the name of the FLAC tag that theese options correspond to and what they mean.</p>
<table border="1">
<tbody>
<tr>
<th>FLAC tag</th>
<th>Lame option</th>
<th>Description</th>
</tr>
<tr>
<td>TITLE</td>
<td>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--tt</div></div>
</td>
<td>The title of the track</td>
</tr>
<tr>
<td>ARTIST</td>
<td>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--ta</div></div>
</td>
<td>The title artist</td>
</tr>
<tr>
<td>ALBUM</td>
<td>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--tl</div></div>
</td>
<td>The album name</td>
</tr>
<tr>
<td>DATE</td>
<td>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--ty</div></div>
</td>
<td>The year of the album</td>
</tr>
<tr>
<td>COMMENT</td>
<td>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--tc</div></div>
</td>
<td>a comment for this track</td>
</tr>
<tr>
<td>TRACKNUMBER, TRACKTOTAL</td>
<td>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--tn</div></div>
</td>
<td>The number of the track and the total number of the tracks</td>
</tr>
<tr>
<td>GENRE</td>
<td>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--tg</div></div>
</td>
<td>the genre of the track</td>
</tr>
</tbody>
</table>
<h2></h2>
<h3>Step 5 &#8211; Passing the FLAC to lame</h3>
<p>We have not solved the original problem yet: you can not pass a flac file to lame. We could decode the FLAC to WAV and then pass the WAV file to lame, but we don&#8217;t need do really create a WAV file, because we can just decode the FLAC and pass the decoded data directly to lame. To do this, we need to call flac with two options:</p>
<ul>
<li>-d to tell it we want to decode a flac file</li>
<li>-c, so that the decoded data is not written to a file, but to stdout</li>
</ul>
<p>Then, we can tell lame that it should read the data from stdin instead of from a file, which can be done by providing a dash for the &lt;oldfile&gt; parameter. Now we can connect them both with a pipe and the decoded flac data will directly flow into our lame command:</p>
<pre>flac -c -d &lt;flacfile&gt;| lame - &lt;mp3file&gt;</pre>
<p>In our example, we would get something like this (which includes adding the ARTIST tag and a VBR quality of 6):</p>
<pre>flac -c -d "1 - Let It In.flac" | lame -V 6 --ta "$ARTIST" - "1 - Let It In.mp3"</pre>
<p>Now that the basic  steps involved are covered, we can let a script do the work.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>The Script</h2>
<p>I wrote a small script that converts a FLAC file to MP3 while preserving  the following tags (=all the tags listed in &#8220;Step 4&#8243; above):</p>
<ul>
<li>Track Title</li>
<li>Track Artist</li>
<li>Album Title</li>
<li>Year</li>
<li>Comment</li>
<li>Tracknumber</li>
<li>Total number of tracks</li>
<li>Genre</li>
</ul>
<h3>Download</h3>
<p>You can download the script here: <a href="http://blog.tordeu.com/downloads/2">flac2mp3.sh</a></p>
<h3>Usage</h3>
<p>The script takes three arguments:</p>
<ul>
<li>The VBR quality (This corresponds to the -V option of lame, which means that you can use a number between 0 and 9, with smaller numbers meaning higher quality and bigger files). If you omit this option, -V 4 will be used.</li>
<li>The filename of the FLAC file you want to convert</li>
<li>The filename of the new MP3 file that you want to create.</li>
<li>You can (but don&#8217;t have to) add &#8220;mtime&#8221; as the fourth argument in which case the script will not start the conversion if the MP3 file is newer than the FLAC file, which indicates that a conversion is not necessary. (If you don&#8217;t add &#8220;mtime&#8221;, the script will convert the files no matter what)</li>
</ul>
<p>Example:</p>
<p>If you want to convert the file &#8220;1 &#8211; Let It In.flac&#8221; to &#8220;1 &#8211; Let It In.mp3&#8243; with a VBR quality level of 3, you would call the script like this:</p>
<pre>flac2mp3.sh 3 "1 - Let It In.flac" "1 - Let It In.mp3"</pre>
<pre>flac2mp3.sh 3 "1 - Let It In.flac" "1 - Let It In.mp3" mtime</pre>
<h3>Source</h3>
<p>The script generally works as described under &#8220;The Solution&#8221;, but instead of repeating the line from &#8220;Step 3&#8243; for every tag, it uses a more elegant approach (which in this case just means less code). But instead of posting the complete source code (which you can look at by download the script), let me just show you  the meat of the script (extracting the 8 tags and passing them to lame for conversion):</p>
<pre>for tag in TITLE ARTIST ALBUM DATE COMMENT TRACKNUMBER TRACKTOTAL GENRE; do
    eval "$tag=\"`metaflac --show-tag=$tag "$FLAC" | sed 's/.*=//'`\""
done

flac -cd "$FLAC" | lame -V "$V" --tt "$TITLE" --ta "$ARTIST" --tl "$ALBUM" --ty "$DATE" --tc "$COMMENT" --tn "$TRACKNUMBER/$TRACKTOTAL" --tg "$GENRE" - "$MP3"</pre>
<p>&nbsp;</p>
<h2>Update (2012-06-05)</h2>
<p>I have updated the script a little. It&#8217;s now possible to append a &#8220;mtime&#8221; after the three arguments. When adding &#8220;mtime&#8221;, the script will only start the conversion if the MP3 file does not exist yet or the FLAC file is newer than the MP3 file.</p>
<p>This will avoid unnecessary conversions in case the MP3 is newer than the FLAC file, which indicates it is up-to-date. This is useful when using this script to somehow manage your library as it will reduce a large number of conversions.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tordeu.com/?feed=rss2&#038;p=184</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>xwd &#8211; Using xwd To Take Screenshots In Linux</title>
		<link>http://blog.tordeu.com/?p=135</link>
		<comments>http://blog.tordeu.com/?p=135#comments</comments>
		<pubDate>Tue, 22 Nov 2011 00:26:12 +0000</pubDate>
		<dc:creator>tordeu</dc:creator>
				<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux Commands]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[imagemagick]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[x window dump]]></category>
		<category><![CDATA[x window system]]></category>
		<category><![CDATA[xwd]]></category>
		<category><![CDATA[xwinfo]]></category>

		<guid isPermaLink="false">http://blog.tordeu.com/?p=135</guid>
		<description><![CDATA[Introduction One of the possibilities of taking screenshots in Linux is using xwd , a utility of the X Window System. I just want to give a short overview on how to take interactive and non-interactive screenshots, view them and convert them to different formats. Taking Screenshots To take a screenshot you could just open <a href='http://blog.tordeu.com/?p=135'>[...]</a>]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<p>One of the possibilities of taking screenshots in Linux is using</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwd</div></div>
<p>, a utility of the X Window System.</p>
<p>I just want to give a short overview on how to take interactive and non-interactive screenshots, view them and convert them to different formats. <span id="more-135"></span></p>
<h2>Taking Screenshots</h2>
<p>To take a screenshot you could just open a terminal and type &#8221;</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwd</div></div>
<p>&#8220;, but by default</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwd</div></div>
<p>does not save the screenshot to a file (it outputs the image to stdout). To save the screenshot in a file, you can either use the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-out</div></div>
<p>option of</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwd</div></div>
<p>:</p>
<pre>xwd -out &lt;filename&gt;</pre>
<p>or redirect the output of</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwd</div></div>
<p>to a file using the functionality offered by the shell:</p>
<pre>xwd &gt; &lt;filename&gt;</pre>
<p>Just replace</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&amp;lt;filename&amp;gt;</div></div>
<p>with the name of the file you want to use for your screenshot. Examples:</p>
<pre>xwd -out myshot.xwd</pre>
<p>or</p>
<pre>xwd &gt; myshot.xwd</pre>
<p>Notice the changed mouse pointer after typing one of these commands ? That&#8217;s because you now need to select the window of which you want to take a screenshot. The format</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwd</div></div>
<p>uses for the images it is called &#8220;X Window Dump&#8221; and the extension often used is</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.xwd</div></div>
<p>. I will cover the subject of converting the images to different formats (like JPEG or PNG) later.</p>
<h3></h3>
<h3>Including the Window Frame</h3>
<p>If you want to include the frame of the window in the screenshot, you have to add the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-frame</div></div>
<p>option. For example:</p>
<pre>xwd -frame -out myshot.xwd</pre>
<p>or</p>
<pre>xwd -frame &gt; myshot.xwd</pre>
<p>&nbsp;</p>
<h3>Taking Screenshots Of The Whole Desktop</h3>
<p>If you want to create a screenshot of the whole desktop instead of a single window, you can use the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-root</div></div>
<p>option for that:</p>
<pre>xwd -root -out myshot.xwd</pre>
<p>or</p>
<pre>xwd -root &gt; myshot.xwd</pre>
<p>&nbsp;</p>
<h3>Automated Screenshots Without Selecting The Window</h3>
<p>It&#8217;s also possible to create screenshots of windows without the need to select them every time. This is especially useful if you want to make numerous screenshots of a single window (e.g. for a tutorial, a presentation, an article etc.).</p>
<p>To do this, you have to tell xwd which window you want to take a screenshot of on the command line, so that it does not have to ask. You can do this either by using the &#8220;resource id&#8221; of the window or the &#8221;</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">WM_NAME</div></div>
<p>property&#8221;. The value of the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">WM_NAME</div></div>
<p>property basically is the title of your window as it is displayed in the window title bar. Using this to create screenshots can be problematic (With Firefox, for example, this value depends on the title of the active tab, so going to a different tab will change the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">WM_NAME</div></div>
<p>property of the window).</p>
<p>To determine the resource id or the value of the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">WM_NAME</div></div>
<p>property, you can use the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwininfo</div></div>
<p>tool. Just type this in the terminal:</p>
<pre>xwininfo</pre>
<p>And then, similar to</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwd</div></div>
<p>, click on the window you are interested in. It will then display a bunch of information about the window, which might look like this:</p>
<pre>xwininfo: Window id: <span style="color: #ff0000;">0x40000e7</span> <span style="color: #3366ff;">"Home of the Mozilla Project - Mozilla Firefox"</span>

  Absolute upper-left X:  1287
  Absolute upper-left Y:  70
  Relative upper-left X:  0
  Relative upper-left Y:  0
  Width: 1159
  Height: 1501
  Depth: 24
  Visual: 0x21
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x20 (installed)
  Bit Gravity State: NorthWestGravity
  Window Gravity State: NorthWestGravity
  Backing Store State: NotUseful
  Save Under State: no
  Map State: IsViewable
  Override Redirect State: no
  Corners:  +1287+70  -114+70  -114-29  +1287-29
  -geometry 1159x1501+1279-21</pre>
<p>The red and blue color was something I added for clarification. The red thing is the resource ID we are interested in and the blue thing is the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">WM_NAME</div></div>
<p>property that we also could use.</p>
<p>If we wanted to use the resource ID, we would do it like this</p>
<pre>xwd -id  -out myshot.xwd</pre>
<p>If we want to use the WM_NAME property, we would do this:</p>
<pre>xwd -name  -out myshot.xwd</pre>
<p>&nbsp;</p>
<p>One important thing to note about this approach is that using the -frame option for xwd does not have any effect if you supply the id or name as well. That is, because the resource id for both cases is different. Therefore, if you want to include the window frame, you have to supply the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-frame</div></div>
<p>option to</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwininfo</div></div>
<p>to retrieve the correct resource id. You would then type:</p>
<pre>xwininfo -frame</pre>
<p>Just to show you that they really differ: In my case, right now, running</p>
<pre>xwininfo</pre>
<p>gives me:</p>
<pre>xwininfo: Window id: 0x40000e7 "Home of the Mozilla Project - Mozilla Firefox"</pre>
<p>while running</p>
<pre>xwininfo -frame</pre>
<p>and clicking on the same, unchanged window, gives me:</p>
<pre>xwininfo: Window id: 0xe002df (has no name).</pre>
<p>&nbsp;</p>
<h2>Viewing Screenshots</h2>
<p>You can view the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwd</div></div>
<p>-screenshots directly with the tool</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwud</div></div>
<p>. Just type:</p>
<pre>xwud &lt;filename&gt;</pre>
<p>for example:</p>
<pre>xwud screenshot.xwd</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>Converting and Editing Screenshots</h2>
<h3>Converting Screenshots</h3>
<p>You can easily convert the screenshots to &#8220;normal&#8221; image formats like JPEG or PNG with tools like ImageMagick. If you don&#8217;t have ImageMagick installed, it should be available through your repositories. For example, in Ubuntu/Debian you would simply type:</p>
<pre>sudo aptitude install imagemagick</pre>
<p>or</p>
<pre>sudo apt-get install imagemagick</pre>
<p>&nbsp;</p>
<p>Once you have ImageMagick installed, you can convert an</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwd</div></div>
<p>image by using</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">convert</div></div>
<p>. For example, to convert an</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xwd</div></div>
<p>-screenshot named</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">shot.xwd</div></div>
<p>to a JPEG file named</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">shot.jpg</div></div>
<p>, type:</p>
<pre>convert shot.xwd shot.jpg</pre>
<p>You can convert the image to other formats as well, like PNG for example:</p>
<pre>convert sot.xwd shot.png</pre>
<p>&nbsp;</p>
<h3>Editing Screenshots</h3>
<p>I won&#8217;t include a tutorial on editing screenshots here, but I just wanted to mention that you might not have to convert your screenshots to JPG or PNG (or something else) in order to edit them, because your image editor might already be able to load</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.xwd</div></div>
<p>files. GIMP, for example, can open them directly.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tordeu.com/?feed=rss2&#038;p=135</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>&#8220;ERROR: Input file  is not a supported format&#8221; when using oggenc to convert a FLAC to OGG Vorbis</title>
		<link>http://blog.tordeu.com/?p=61</link>
		<comments>http://blog.tordeu.com/?p=61#comments</comments>
		<pubDate>Wed, 16 Nov 2011 13:53:03 +0000</pubDate>
		<dc:creator>tordeu</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[flac]]></category>
		<category><![CDATA[metaflac]]></category>
		<category><![CDATA[ogg]]></category>
		<category><![CDATA[oggenc]]></category>

		<guid isPermaLink="false">http://blog.tordeu.com/?p=61</guid>
		<description><![CDATA[(Download the script here: ) Problem When using oggenc to convert a FLAC file to OGG Vorbis using oggenc, you might encounter the following error: "ERROR: Input file &#60;file&#62; is not a supported format" Explanation One possible reason for this can be an ID3 tag in the flac file. This can happen if the program <a href='http://blog.tordeu.com/?p=61'>[...]</a>]]></description>
				<content:encoded><![CDATA[<p style="text-align: right;">(Download the script here: <a href="http://blog.tordeu.com/downloads/1">reflac.sh</a>)</p>
<h2>Problem</h2>
<p>When using oggenc to convert a FLAC file to OGG Vorbis using oggenc, you might encounter the following error:</p>
<pre>"ERROR: Input file &lt;file&gt; is not a supported format"</pre>
<h2>Explanation</h2>
<p>One possible reason for this can be an ID3 tag in the flac file. This can happen if the program you used to create your FLAC files uses ID3 tags instead of native FLAC tags to store metadata.</p>
<p><span id="more-61"></span>You can confirm this by typing the following:</p>
<pre>flac --ogg enc &lt;file&gt;</pre>
<p>which would then output something like this:</p>
<pre>ERROR: input file &lt;file&gt; has an ID3v2 tag</pre>
<p>If this is the problem you are having, then the following should help you</p>
<h2>Bad &#8220;Solutions&#8221;</h2>
<p>The &#8220;solutions&#8221; I found on the web have drawbacks that I could not accept.</p>
<p>The first &#8220;solution&#8221; is to just rip the CD again with a different software or different options. This is annoying, because you need to go through the whole process again and ripping a CD can take a long time, depending on how you do it.</p>
<p>Another &#8220;solution&#8221; is to convert your FLACs to WAV files and then either to OGG or back to FLAC (to get &#8220;repaired&#8221; FLACs you can now use with oggenc). The drawback of this approach is that all the metadata gets lost during the conversion from FLAC to WAV, because WAV files can not hold metadata.</p>
<p>I am using quotes (&#8220;solution&#8221;) to make clear that I don&#8217;t really consider them solutions to the problem, because the amount of work that would be required makes them practically useless for large collections.</p>
<h2>Solution</h2>
<p>The &#8220;only&#8221; problem with the second &#8220;solution&#8221; is the lost metadata. Other than that the solution works fine. Fortunately it is possible to solve the problem by using a command line tool that is already installed with flac, but that most people don&#8217;t seem to know about: metaflac.</p>
<p>Metaflac can extract metadata from a FLAC file and add metadata to a FLAC file as well. Therefore, all we need to do is:</p>
<ol>
<li>extract the metadata using metaflac</li>
<li>decode the FLAC to a WAV file</li>
<li>encode the WAV file back to FLAC</li>
<li>import the metadata using metaflac into the new FLAC file</li>
</ol>
<h2>Using a script to &#8220;repair&#8221; the FLACs</h2>
<p>Because this is pretty annoying by hand, I wrote a script named &#8220;reflac&#8221;. You can either use the script in a terminal or &#8220;integrate&#8221; it with Nautilus.</p>
<h3>Downloading the script</h3>
<p>You can download the script here: <a href="http://blog.tordeu.com/downloads/1">reflac.sh</a></p>
<h3>Using the script from the command line</h3>
<p>The script can be used like this:</p>
<pre>reflac.sh &lt;flac file&gt;...</pre>
<p>Example 1:</p>
<pre>refla.shc foo.flac bar.flac</pre>
<p>Example 2:</p>
<pre>reflac.sh *.flac</pre>
<p>It just goes through the four steps for every file you throw at it.</p>
<h3>Adding the script to Nautilus</h3>
<p>If you don&#8217;t like the terminal that much, you can also use the script directly from Nautilus. Just copy the script to the folder ~/.gnome2/nautilus-scripts/ (To copy the script to this location from within Nautilus, download the script</p>
<p>Just as a disclaimer: This is a quick &amp; dirty script I wrote and I don&#8217;t really see something in it that could go horribly wrong. Nevertheless, there is ALWAYS a risk when using software, so backing up your data is YOUR responsibility. And always keep in mind: &#8220;If it&#8217;s worth saving, it&#8217;s worth backing up!&#8221;.</p>
<h2>Download</h2>
<p>Download the script here: <a href="http://blog.tordeu.com/downloads/1">reflac.sh</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tordeu.com/?feed=rss2&#038;p=61</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
