A Next Generation Blog

DOS Commands Every Windows User Must know

There used to be a day when computers were huge ugly beasts with black and white screens staring back with geeky texts. Yes, the old CUI days. Now, there is much more icons and cursors all the way in our computers than fancy text. But there still remains a legacy interface intact and well maintained. “Command Prompt” as you might be knowing it as. Wondered why does it continues to exist? Legacy? The answer is no. Command-line is very popular among those who know its power. It is invaluable for remote systems maintainers and so many more. Lets journey a bit through the command prompt.

cmd

Why has the shell remained as it was?

While GUI flexed our day-to-day computer activities, there still remain tasks that are best done under the good old textual interface. Think of system admin tools, servers, telnet, ping and all. Tools that we developers use, compilers, debuggers are all command-line based. It it is worth to note that a CUI is less resource intensive that a full-blown GUI. Remote usage with GUI, though possible, is a terrible experience, while a SSH is pretty easy. Recovery environments are text based for the major part. So, if your GPU brickes, you’ll get that old faithful shell to carry out recovery. Or just try renaming a 1000 files with Windows Explorer – you are simply out of luck.

Let’s discover some common commands that every user using windows ought to know.

Starting the Shell

The Windows Command Processor can be launched by running “cmd.exe” from run dialog or from “Start>Programs>Accessories>Command Prompt”.

Note:

  • Some commands we discuss here need administrator rights. For this Command Promt must run with elevated permissions. Right click the shortcut and select “Run as administrator…”
  • Always enclose parameters containing spaces with quotes. If you have a quote somewhere in it prefix it with a ‘\’.

Basic Commands

CD (CHDIR)

Changes the working directory. By default, “Command Prompt” starts in your user directory, or the “System32” directory if you’ve launched it with administrator privileges. CD without parameters prints out the current directory you are under. Under normal conditions CD won’t change directory on a different drive. You must specify the ‘/D’ switch to allow such behaviour.

Syntax

CD [/D] <directory> ↲

Arguments:

  • directory    the directory to change the prompt into.

Switches:

  • /D    switch to directory under a different drive.
CLS

Clears the command prompt screen. Useful if lots of output have eaten up your text buffer.

Syntax

CLS

Example

CLS

Directory Changing

You can’t directly change from “C:\Users” to “D:\Flex” with CD. Thus you need to change the “prompt” to that drive before working on it.

Syntax

<DRIVE>:

Example

D:

File and Folder Management

TYPE

The type command prints the contents of a file on the screen. Typing a binary file will result in garbage!

Syntax

TYPE <file>:

Example

TYPE file.txt

DIR

The DIR command shows the files and subdirectories under a directory.

Syntax

DIR [switches] <directory>

Switches
  • /A    Displays files with specified attributes. Such as H – hidden, S – System, A – archived.\
  • /B    Display only file names and directories
  • /D    Same as wide but files are list sorted by column.
  • /O    Sort file names.
    • N – Sort alphabetically
    • S – By size (ascending)
    • E – Sort by extension
    • D – Sort by date/time (oldest first)
  • /P    Displays file information one page at a time.
  • /S    Displays files in specified directory and all subdirectories.
  • /W    Shows files in wide list format.
  • /X    This displays the short names generated for non-8dot3 file names. This is particularly useful for inputting files into legacy dos applications.
Example

DIR

Sample Output


Volume in drive C has no label.
Volume Serial Number is 78DF-949D
Directory of C:\Users\Amitosh
30-04-2014 15:25 <DIR> .
30-04-2014 15:25 <DIR> ..
26-07-2013 17:22 <DIR> Contacts
03-05-2014 17:13 <DIR> Desktop
07-05-2014 11:29 <DIR> Documents
07-05-2014 09:56 <DIR> Downloads
11-04-2014 10:55 2,148 drawing.svg
07-05-2014 09:57 <DIR> Dropbox
06-04-2014 15:04 <DIR> Links
20-02-2014 21:43 <DIR> Music
05-05-2014 12:45 <DIR> Pictures
25-11-2013 12:27 <DIR> Saved Games
21-09-2013 13:39 <DIR> Searches
07-05-2014 10:07 <DIR> SkyDrive
29-03-2014 13:45 <DIR> Videos
1 File(s) 2,148 bytes
14 Dir(s) 89,215,967,232 bytes free

COPY

Copy command is used to copy files across the file system. It is the most basic and commonly used operation in any filesystem.

Syntax

COPY [switches] [/A | /B] <source> [/A | /B] + <source> [/A | /B] [+ …] <Destination> [/A | /B]

Arguments:

  • source        The source file(s)
  • /A        Indicates a text file
  • /B        Indicates a binary file
  • Destination    Specifies the directory and/or filename for the new file(s).

Switches

  • /V    Verifies that new files are written correctly
  • /Y    Assumes yes on all queries.
  • /-Y    Causes prompting to confirm you want to overwrite an existing destination file.
  • /L    Copy shortcuts.
Example

This will copy a file from the current directory to a sub-directory.

COPY records.db records

The copy command may be used for concatenating files with the ‘+’ operator

Example

This command will concatenate all the files specified into one

COPY table1.csv + table2.csv + table3.csv merged_tables.csv

MOVE

Move is used to move (cut-and-paste) files and directories across the filesystem.

Syntax

MOVE [/Y] <file(s)> <destination>

Arguments:

  • Files        The files or directories to move
  • Destination    Specifies the new location of the file. It can consist of a directory path or a file path if you are moving a single file and want to perform a “move-and-rename”

Switches

  • /Y        Assumes yes on all queries. Here it overwrites all files without prompting.
Example

This will move a file from the current directory to a subdirectory.

MOVE records.db records

RENAME

Renames files and folders. It is also very handy for mass renaming tasks or changing file extensions.

Syntax

RENAME <oldname> <newname>

Arguments:

  • Oldname    The original file name
  • Destination    Specifies the new location of the file. It can consist of a directory path or a file path if you are moving a single file and want to perform a “move-and-rename”

Switches

  • /Y        Assumes yes on all queries. Here it may potentially overwrite files without prompting.
Example

This will rename records.db to records.

RENAME records.db records

This will rename all files with bin extension to pngs. Note that this will not perform a file format conversion.

RENAME *.bin *.png

DEL (ERASE)

This command deletes one or more files and folders permanently. Files deleted this way do not land up into the Recycle Bin

Syntax

DELETE [switches] <file(s)>

Arguments:

  • Files        The files or directories to delete

Switches

  • /P    Prompts for confirmation before deleting each file.
  • /F    Force deleting of read-only files.
  • /S    Delete specified files from all subdirectories.
  • /Q    Quiet mode, do not ask if ok to delete on global wildcard
Example

This deletes the file “decoded.db”

DELETE decoded.db

This deletes all files with extension “tmp”

DELETE *.tmp

Well, this is only a few of the entire resources available under windows. You can find a lot of hidden “gems” while “digging the command line”. Stay tuned for more awesome tips and tricks.

 

Leave A Reply

Your email address will not be published.