<?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>MOleYArd (MOYA) blog &#187; cmd</title>
	<atom:link href="http://www.moyablog.com/tag/cmd/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.moyablog.com</link>
	<description>A Software Developer&#039;s Blog</description>
	<lastBuildDate>Sat, 07 Apr 2012 13:38:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Essential Windows commands tips – part 3</title>
		<link>http://www.moyablog.com/2011/12/29/essential-windows-commands-tips-%e2%80%93-part-3/</link>
		<comments>http://www.moyablog.com/2011/12/29/essential-windows-commands-tips-%e2%80%93-part-3/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 16:32:04 +0000</pubDate>
		<dc:creator>MOYA</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[bat]]></category>
		<category><![CDATA[batch files]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[command prompt]]></category>

		<guid isPermaLink="false">http://www.moyablog.com/?p=648</guid>
		<description><![CDATA[<p style="text-align: justify;">At the end of the previous part of this tutorial we briefly introduced echo command and I promised that we will deal with creating batch files in the command prompt. Actually, creating batch files is the second step. The first step is to create an arbitrary file.</p> <p></p> <p style="text-align: justify;">First let&#8217;s talk [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">At the end of the previous part of this tutorial we briefly introduced <strong>echo</strong> command and I promised that we will deal with creating batch files in the command prompt. Actually, creating batch files is the second step. The first step is to create an arbitrary file.</p>
<p><span id="more-648"></span></p>
<p style="text-align: justify;">First let&#8217;s talk about <strong>echo</strong> again. Type</p>
<pre name="code" class="vb:nocontrols">
echo /?
</pre>
<p style="text-align: justify;">to see how to use <strong>echo</strong> and what is its purpose. The output is:</p>
<pre name="code" class="vb:nocontrols">
Displays messages, or turns command-echoing on or off.

  ECHO [ON | OFF]
  ECHO [message]

Type ECHO without parameters to display the current echo setting.
</pre>
<p style="text-align: justify;">Last time we showed <em>turns command-echoing on or off</em> usage. This time <strong>ECHO [message]</strong> is the important one. Try few examples:</p>
<pre name="code" class="vb:nocontrols">
C:\Users\moya>echo text
text

C:\Users\moya>echo car
car
</pre>
<p style="text-align: justify;">Now we are almost done &#8211; we can echo text to the command line. Only other thing to do is to redirect that output to a file. Change current directory to <em>Desktop</em>:</p>
<pre name="code" class="vb:nocontrols">
cd Desktop
</pre>
<p style="text-align: justify;">and type:</p>
<pre name="code" class="vb:nocontrols">
echo car &gt; ourfile.txt
</pre>
<p style="text-align: justify;">In general <em>command > filename</em> redirect command output to a file. That&#8217;s exactly what we needed. Now ourfile.txt contains <em>car</em> string. Type</p>
<pre name="code" class="vb:nocontrols">
echo car &gt; ourfile.txt
</pre>
<p style="text-align: justify;">to see it. The file ourfile.txt will be opened and will contain <em>car</em> string.</p>
<p style="text-align: justify;">Now type</p>
<pre name="code" class="vb:nocontrols">
echo house &gt; ourfile.txt
</pre>
<p style="text-align: justify;">and open the file again. It now contains <em>house</em> string and <em>car</em> string was rewritten. What about not rewriting original content, but just appending it? It&#8217;s easy:</p>
<pre name="code" class="vb:nocontrols">
echo car &gt;&gt; ourfile.txt
</pre>
<p style="text-align: justify;">This will append echoed content to the end of the file. Its first line will now contain <em>house</em> and its second line <em>car</em>.</p>
<p style="text-align: justify;">Now try to echo some longer sentence:</p>
<pre name="code" class="vb:nocontrols">
echo This is a tutorial about essential Windows commands. &gt; ourfile.txt
</pre>
<p style="text-align: justify;">What if we would like to add several sentences (in separate line each). We can do this with several commands using append (&gt;&gt;). But we can also use one compound command. Try this:</p>
<pre name="code" class="vb:nocontrols">
echo This is a tutorial about essential Windows commands. &gt; ourfile.txt &#038;&#038; echo This is the second sentence. &gt;&gt; ourfile.txt
</pre>
<p style="text-align: justify;">We joined two commands with &#038;&#038;. Actually, we don&#8217;t have to open ourfile.txt in the external text editor. We can check output in command line as well with <strong>type</strong> command. Let&#8217;s type</p>
<pre name="code" class="vb:nocontrols">
type ourfile.txt
</pre>
<p style="text-align: justify;">and we will see the content of ourfile.txt file.</p>
<p style="text-align: justify;">Now we can probably imagine how to create batch files this way. It&#8217;s absolutely the same as the creation of any other file. We can see that this way of creating files is not at all practical, but it is one of the ways. But I guess you will rather use some text editor (though possibly command line based) for these kinds of tasks. We introduced this &#8211; &#038;&#038;. This stuff is much more practical. It serves for chaining commands. There are more types of chainings:</p>
<ul>
<li><span style="display:-moz-inline-stack; display: inline-block; width: 175px;"><strong>command1 &#038;  command2</strong></span> Run command1 and  then command2</li>
<li><span style="display:-moz-inline-stack; display: inline-block; width: 175px;"><strong>command1 &#038;&#038; command2</strong></span> Run command1 and if commandA succeeds then run command2</li>
<li><span style="display:-moz-inline-stack; display: inline-block; width: 175px;"><strong>command1 || command2</strong></span> Run command1 and if it fails then run command2</li>
</ul>
<p style="text-align: justify;">You can use these when you write your own batch files or if you use more complicated compound commands. We now know something about redirection of an output. Besides printing output applications (and thus their commands) might also have some input. An output of one application (command) may serve as an input for another one. We have actually encountered this when we used command <strong>tree</strong> (<em>tree | more</em>). But we haven&#8217;t yet really explained what it exactly does.</p>
<ul>
<li><span style="display:-moz-inline-stack; display: inline-block; width: 175px;"><strong>command1  |  command1</strong></span> Pipe the output from command1 into command2</li>
</ul>
<p style="text-align: justify;">It pipes output. It exactly means that the output of the command is served as the input for the another command. Utility <strong>more</strong> takes output of another command and then print it line-by-line or page-by-page when user press <em>Enter</em> or <em>Space</em>. So that&#8217;s all for this part <img src='http://www.moyablog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moyablog.com/2011/12/29/essential-windows-commands-tips-%e2%80%93-part-3/feed/</wfw:commentRss>
		<slash:comments>10495</slash:comments>
		</item>
		<item>
		<title>Essential Windows commands tips – part 2</title>
		<link>http://www.moyablog.com/2011/11/02/essential-windows-commands-tips-%e2%80%93-part-2/</link>
		<comments>http://www.moyablog.com/2011/11/02/essential-windows-commands-tips-%e2%80%93-part-2/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 15:15:29 +0000</pubDate>
		<dc:creator>MOYA</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[bat]]></category>
		<category><![CDATA[batch files]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[command prompt]]></category>

		<guid isPermaLink="false">http://www.moyablog.com/?p=391</guid>
		<description><![CDATA[<p style="text-align: justify;">Today I will move on with the second part of the article about Windows command tips. This part will discuss how to create and edit batch files.</p> <p></p> Creating batch files <p style="text-align: justify;">Batch files can be created in graphical environment of Windows as well as in CMD. While there are lots of [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Today I will move on with the second part of the article about Windows command tips. This part will discuss how to create and edit batch files.</p>
<p><span id="more-391"></span></p>
<h3>Creating batch files</h3>
<p style="text-align: justify;">Batch files can be created in graphical environment of Windows as well as in CMD. While there are lots of tasks that are much more efficient to be conducted in CMD, in the case of creating batch files I find it more convenient to do it in GUI environment.</p>
<p style="text-align: justify;">Just right-click on empty area of any folder or desktop and select New -&gt; Text Document. This will create an empty plain-text document in the folder named &#8220;New Text Document.txt&#8221; or similar name (possibly with a number in brackets if there were previously created empty text documents this way). Now click on it once, wait for a while and click on it second time (or click and press F2, or right-click and select Rename). The filename will be highlighted. Rename the filename and change the extension <em>.txt</em> to <em>.bat</em>.</p>
<p style="text-align: justify;">There is one common feature (but at least in my opinion issue) in Microsoft Windows operating systems that is in newer versions set to be default, which is really a shame. It is <em>Hide extensions for known file types</em> folder option. When I work on someone&#8217;s else computer, they actually often have this enabled… It has some pseudoaesthetic motivation of hiding these extensions, but otherwise it&#8217;s highly impractical. If you have this option enabled, you will not see .txt part of the filename. If you add it manually, you actually get <em>filename.txt.txt</em> or in a case of .bat <em>filename.txt.bat</em>. So if this is the case open any folder (for example (My) Computer folder). Choose <em>Tools -&gt; Folder options…</em> from the file menu (if you don&#8217;t see it, press Alt + F and it will show up). Then <em>Folder Options</em> window will appear. Select <em>View</em> tab and in the <em>Advanced settings:</em> list uncheck <em>Hide extensions for known file types</em> option. Now you can return to the previous step.</p>
<p style="text-align: justify;">In Windows NT, 2000, XP, Vista and 7 you can use <em>cmd</em> extension instead of <em>bat</em>. In old Windows 9x versions and in DOS you could use just <em>.bat</em>. (Command prompt cmd.exe can handle both <em>.cmd</em> and.<em>bat</em>, command.com only <em>.bat</em>). We might say that it would be correct to use <em>.bat</em> extension for command.com and newer <em>.cmd</em> for cmd.exe, but this is actually not the case. Because simply people are get used to <em>bat</em> and it&#8217;s still much more common. There are some (truly) minor differences between the two, but most of the time they are absolutely interchangeable in modern Windows operating system.</p>
<h3>Editing batch files</h3>
<p style="text-align: justify;">After creating the batch file, open it in some plain-text editor (Notepad is just enough). We have introduced some basic commands in the previous part of this article. So let&#8217;s type</p>
<pre name="code" class="vb:nocontrols">
dir
</pre>
<p style="text-align: justify;">and save the file. Now we can run test.bat (suppose that we named it so). A window will appear very shortly and then disappear.</p>
<p style="text-align: justify;">To prevent this add <em>pause</em> command in the second line.</p>
<pre name="code" class="vb:nocontrols">
dir
pause
</pre>
<p style="text-align: justify;">Now the window will stay open and its output will be similar to this:</p>
<pre name="code" class="vb:nocontrols">
C:\Users\moya\Desktop\bat-test>dir
 Volume in drive C has no label.
 Volume Serial Number is 20EB-818C

 Directory of C:\Users\moya\Desktop\bat-test

02. 11. 2011  11:36    &lt;DIR&gt;          .
02. 11. 2011  11:36    &lt;DIR&gt;          ..
02. 11. 2011  12:07                10 test.bat
               1 File(s)             10 bytes
               2 Dir(s)  747 433 140 224 bytes free

C:\Users\moya\Desktop\bat-test>pause
Press any key to continue . . .
</pre>
<p style="text-align: justify;">The <strong>pause</strong> command caused the suspension of processing of a batch program and the last line now contains <em>Press any key to continue . . .</em> message. Processing will continue after pressing any key as message states. Of course <strong>pause</strong> command may be inserted anywhere in the file, not just at the end, for example:</p>
<pre name="code" class="vb:nocontrols">
dir
pause
dir
pause
</pre>
<p style="text-align: justify;">Another thing you may notice are lines <em>C:\Users\moya\Desktop\bat-test>dir</em> and <em>C:\Users\moya\Desktop\bat-test>pause</em>. It appears as if we had typed these commands manually in the command prompt, but we hadn&#8217;t. To prevent this behavior you can preppend <em>@</em> sign before each command like this:</p>
<pre name="code" class="vb:nocontrols">
@dir
@pause
</pre>
<p style="text-align: justify;">Now the output will be:</p>
<pre name="code" class="vb:nocontrols">
 Volume in drive C has no label.
 Volume Serial Number is 20DA-972D

 Directory of C:\Users\moya\Desktop\bat-test

02. 11. 2011  11:36    &lt;DIR&gt;          .
02. 11. 2011  11:36    &lt;DIR&gt;          ..
02. 11. 2011  12:44                12 test.bat
               1 File(s)             12 bytes
               2 Dir(s)  747 431 907 328 bytes free
Press any key to continue . . .
</pre>
<p style="text-align: justify;">It&#8217;s a bit awkward to preppend <em>@</em> before every command. Luckily, there is a way to apply this behavior globally. Try:</p>
<pre name="code" class="vb:nocontrols">
@echo off
dir
pause
</pre>
<p style="text-align: justify;">The effect is the same. <strong>echo off</strong> applies demanded behavior for all following commands in the batch file and @ <strong>echo off</strong> applies this to that command itself.</p>
<p style="text-align: justify;">We introduced <strong>echo</strong> command. This command is also useful when we are creating batch files in the command prompt. We will tell more about it in the next part of this series <img src='http://www.moyablog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moyablog.com/2011/11/02/essential-windows-commands-tips-%e2%80%93-part-2/feed/</wfw:commentRss>
		<slash:comments>9070</slash:comments>
		</item>
		<item>
		<title>Essential Windows commands tips &#8211; part 1</title>
		<link>http://www.moyablog.com/2011/10/14/essential-windows-commands-tips-part-1/</link>
		<comments>http://www.moyablog.com/2011/10/14/essential-windows-commands-tips-part-1/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 15:39:52 +0000</pubDate>
		<dc:creator>MOYA</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[bat]]></category>
		<category><![CDATA[batch files]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[command prompt]]></category>

		<guid isPermaLink="false">http://www.moyablog.com/?p=105</guid>
		<description><![CDATA[<p style="text-align: justify">I decided to write a series about Windows commands targeted to less skilled users (there will be nothing new for the advanced Windows users, so if you belong to this group, you may skip this article )</p> <p style="text-align: justify">This series is not intended to be a complete tutorial, its intent is just [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify">I decided to write a series about Windows commands targeted to less skilled users (there will be nothing new for the advanced Windows users, so if you belong to this group, you may skip this article <img src='http://www.moyablog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<p style="text-align: justify">This series is not intended to be a complete tutorial, its intent is just to show some of the most useful tricks. However, since as I already mentioned, it is targeted to rookies, so in this first part we will deal with the very basics &#8211; how to actually work with commands, command line and batch files in general.</p>
<p><span id="more-105"></span></p>
<p style="text-align: justify">There are two ways of using commands &#8211; you can use it in the command prompt (<em>cmd.exe</em> or in old versions of Windows <em>command.com</em>) or you can use it in batch files.</p>
<h3>Using commands in command prompt</h3>
<p style="text-align: justify">Command Prompt can be found in Accessories. The fastest way to run it in Windows 7 is to press <em>Start</em> and type <em>cmd</em> in the search bar and press <em>Enter</em>. In Windows XP, you can do the same, but instead of typing it in the search bar, you run <em>Start-&gt;Run</em>. Hopefully you are not fed up with mentioning these trivial tasks <img src='http://www.moyablog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p style="text-align: justify">So assume that we have already started Command Prompt (CMD). We probably see the path of our user&#8217;s account root directory (or possibly other path, it&#8217;s not relevant now). There are 4 commands that I consider the most important and crucial to mention for people who are running CMD for the first time &#8211; <strong>cd</strong>, <strong>dir</strong>, <strong>help</strong> and <strong>more</strong>. After learning these four commands you can start using the command line relatively proficiently.</p>
<p style="text-align: justify">Type <strong>help</strong>. You will see a list of commands with their short description as an output. You will probably not see the complete list, but just the bottom of it. But you can use a scrollbar to see the upper part. However, sometimes an output of CMD commands might be so large that you cannot see the full output.</p>
<p style="text-align: justify">Let&#8217;s type <strong>tree</strong>. This will start outputting the whole structure of your directories. You can wait quite long to finish it, or you may stop it by pressing CTRL + C after a while. In any case (if you were not too fast <img src='http://www.moyablog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ), if you try to scroll on the top of command line window, you will not see the beginning of the output. For these situation there is a command called <strong>more</strong>.</p>
<p style="text-align: justify">Now type <strong>tree | more</strong>. The outputting will now stop so you can see the beginning of the output. You can shift it by pressing <em>Enter</em> line by line or by pressing <em>Space</em> screen by screen. Press CTRL + C to stop it.</p>
<p style="text-align: justify">When you type <strong>help</strong> together with another command name, it will show you help for this particular command. Try <strong>help cd</strong> for example. The second or further typed word of command is called <em>argument</em> or <em>parameter</em>. Instead of typing <strong>help cd</strong> you can also write <strong>cd /?</strong>. Arguments that starts with a forward slash (or with a hyphen, but this is not the case of standard Windows commands) are also sometimes called <em>switches</em>.</p>
<p style="text-align: justify">Now you can see outputted help of <strong>cd</strong> command. It contains text description, examples and in the beginning the command syntax. Note that arguments are in [] brackets. It means that these arguments are optional. Try to read instructions from that <strong>help</strong> output. Also try <strong>help dir</strong>.</p>
<p style="text-align: justify">I have not yet explicitly mentioned what are the tasks of <strong>cd</strong> and <strong>dir</strong> commands, but you had probably noticed it in the output of <strong>help</strong> command. In short, <strong>cd</strong> changes current active directory and<strong> dir</strong> lists all files and folders in the current or specified directory.</p>
<p>Here are som usage examples (commented odd lines contain description, even lines contain actual command):</p>
<pre name="code" class="vb">
'show contents of the current directory
dir
'show contents of the current directory
dir .
'change the current directory to the parent directory
cd ..
'show contents of the parent directory
dir ..
'change directory to drive C root directory
cd C:\
'change directory to directory C:\Users
cd C:\Users
'change directory to directory C:\Program Files
cd "C:\Program Files"
'show contents of directory C:\Program Files
dir "C:\Program Files"
'change drive to D:\
D:
</pre>
<p style="text-align: justify">You probably noticed two things, if you were attentive. We used double quotes in the antepenultimate and the penultimate example. That&#8217;s because the path of the chosen directory included white space, but white space is a delimiter for arguments. If an argument includes white spaces, you have to put it inside double quotes. The last example contains just <em>D:</em> and this switches the current drive. In fact, you cannot change a directory with <strong>cd</strong> command to directory outside the current drive. Although you can show its contents with <strong>dir</strong> command.</p>
<p style="text-align: justify">The last thing I will mention in this section is how to select and copy text from the command line. It differs from usual Windows way. Right-click on the CMD window and choose <em>Select All</em>. Then press <em>Enter</em>. Now the complete visible output is in the clipboard and you can paste it for example into Notepad. If you want to select just the part of CMD output, right-click again, but this time choose <em>Mark</em>. Click anywhere in the window and move cursor to select area to be copied and then press <em>Enter</em>.</p>
<p style="text-align: justify">Well, that&#8217;s enough for now. You can close CMD by typing <strong>exit</strong>. I intended to include also the basics of using batch files, but I don&#8217;t want to make this article too long. So, wait for the next time <img src='http://www.moyablog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
]]></content:encoded>
			<wfw:commentRss>http://www.moyablog.com/2011/10/14/essential-windows-commands-tips-part-1/feed/</wfw:commentRss>
		<slash:comments>8368</slash:comments>
		</item>
	</channel>
</rss>
