Tuesday, August 7, 2012

Command Line Tricks

The Windows command line is very useful if you know how to use it. Unfortunately, most people do not know how to use it or are scared of using it because they do not know enough of it. There's no better time to get your feet wet on how to use the Command Prompt than now. So are you all ready? 

Launch your command prompt. Here's how I do that in Vista. I simply hit the Windows key (on my keyboard) or click the Start menu and type "cmd" (no quotes) in the Start Search box, then hit the Enter key. The Command Prompt will usually open the C:\Users\(your username here) directory. If you type "cd.." (no quotes & those are two dots after "cd") your directory will revert to C:\Users\. If you enter "cd.." one more time, your directory will revert to C:\. If you enter "dir" (no quotes), Command Prompt will list the sub-directories and/or files in the current directory. The sub-directories have the "<DIR>" designation. The rest are just files. To shift to the subdirectories, just type "cd (name of the sub-directory here)" then hit Enter. For example, you can type this command:
cd Windows
When you hit Enter, your Command Prompt will shift you to the Windows directory. So that's your crash course on how to navigate through your file system using commands in Command Prompt. If you are using Windows 7 or other versions, the procedure is similar to the steps I described above. The difference may just lie on the way you get to your Command Prompt.


SOURCE: http://maketecheasier.com/simple-yet-useful-command-line-tricks-for-windows/2012/08/06#comment-32442


If you are familiar with using Command Prompt, see if you know some of these tricks:

1. Output to Your Clipboard

Type this command in your Command Prompt:
dir | clip
Note that there's a space after "dir" and before "clip". The straight line character is called a pipe. You can reach that by holding down the Shift key and hitting the backslash key (usually situated to the left of the Enter key on desktop keyboards or above the Enter key on laptops). If you use the above command, you will be outputting the contents of the current directory to your Clipboard. Try it! Then launch Notepad. Right-click Notepad then choose Paste from the menu. As you will see, the list of files and subdirectories in your current directory were copied to your Clipboard because you are able to paste its contents onto Notepad.

2. Output To A Text File

You can directly output the contents of a directory onto a text file using the Command Line. Here's how. First, type the "dir | clip" (no quotes) command on Command Prompt. Then type this:
dir > C:\crap.txt
After you hit the Enter key, launch your Windows Explorer and navigate to C:\. Look for the "crap.txt" file and open it. What you will see is a list of files and directories which are contained in the current directory in your Command Prompt. Simple enough for ya? Don’t forget to put quotation marks around the file path if you have spaces in the name! For example, if the name of your directory or sub-directory is "Lotsa crap" (which contains two words with a space in between them) and you need to include it in your Command Line command, you have to enclose the name with quotes. For example: c:\MISC\"lotsa crap.txt". Another example: c:\"Lotsa crap"\filelist.txt. In the first example, the text file name contains two words. In the 2nd example the name of the DIRECTORY "Lotsa Crap" contains two words. Clear as mud?

3. Show Your Command History

One quick way, both in Windows and Linux, to show ONLY your LAST COMMAND in your Command Prompt is to press the "Up arrow" key on your keyboard. But if you want Command Prompt to show you ALL the commands you had typed, you go with this command:
doskey /history

4. Run Several Different Commands At One Time

There are ways to execute multiple routines in one shot. For example let’s say that you want Command Prompt to show you your IP address and display the directory structure of your current directory. Try this command:
ipconfig && dir
The "&&" conjoins any two commands. The above command will look for your IP address and display the directory structure of your current directory.

cmdline-nn
You can even do this:
dir && ipconfig && doskey /history

The Best Part

Did you know that you can combine anything you learned here within the command line? Try typing this:
ipconfig && dir > C:\crap.txt
This will execute both commands and print their output into a file. 

If you know other tricks, don’t hesitate to share them with us!

No comments:

Post a Comment