Navigating To The File Using CMD
Navigating To The File Using CMD
To delete a file or folder using the command prompt we must first navigate to the location of our
file. By default the command line is located at a folder named after your
computers username (C:\Users\MyPC). This folder contains your documents, downloads and
desktop directories, among others.
To view all the files in this directory use the “Dir” command, which stands for directory.
Dir
Cd "Desktop"
You will at once navigate into the desktop directory and from here you can use the “Dir”
command once again to locate the file or folder you want to delete.
If you navigated to the wrong directory by mistake, type:
CD ..
You might be wondering why we surrounded the name of our folder in quotes.
The quotes tell the command line that the spaces separating the words do not constitute an
additional parameter and that they are simply a part of the name of our folder.
“Rmdir” without any parameters only removes folders that are empty, to delete a folder along
with the files or folders within it you need to use the /S parameter.
The command would look like this:
Typing “Del” followed by a set of characters that is shared among the names of the files we want
to delete and an asterix, will delete all of them.
Del "File*"
Every file that begins with the word “File” will be deleted.
To delete a set of folders instead, simply replace the Del command with Rmdir.
Del "*.txt"
Rmdir /S "*"
Every folder in your current directory will be deleted along with any contents within it.
Be careful when deleting files and folders, the wrong command can easily delete important files
and folders.
In the same way you can replace “Rmdir” with any command to complete any task from any
directory.
Summary:
Navigate to the directory the file you want to delete is located with the “CD” and “Dir”
commands.
Use “Rmdir” to delete folders and “Del” to delete files. Don’t forget to surround the
name of your folder in quotes if it contains a space.
Use wildcards to delete many files or folders at once.
Ping:
Lets start with something simple.
Ping can help you resolve internet or network connectivity issues, by sending packets to your
destination and awaiting a response.
Type ping followed by a URL or an IP address.
Ping 8.8.8.8
If the server is there, you will see the reply as well as the amount of time the interaction took.
Tracert:
Tracert is similar to ping and it can be used to visually identify exactly where a problem occurs
when a packet gets sent and received from its destination.
Tracert, as the name implies, traces each hop on the route the packet takes to reach your
destination, and tells you information about each of them.
To use it, type tracert followed by your destination URL or IP.
Tracert 8.8.8.8
Pathping:
Pathping is a more advanced version of ping as well as a combination of ping and tracert.
Pathping sends ping commands to every hop a packet takes to reach your destination over a
period of time.
Resulting in a detailed report. Its usage its similar to both path and tracert, simply type Pathping
followed by your destination URL or IP.
Pathping 8.8.8.8
The operation can take quite a long time to complete and thus tracert is usually preferred.
However, the extra information it provides can be especially useful at times.
Ipconfig:
Type ipconfig in your command line, to get all sorts of information about your IP configuration
and all the IP addresses your pc is currently using.
Ipconfig
A particularly useful parameter is /flushdns which will completely delete your dns cache.
Ipconfig /flushdns
You can also use the following commands one after the to assign a new IP address to your
computer.
ipconfig /release
ipconfig /renew
Ipconfig is immensely powerful and if you want to learn more about it check out this blog post
where we go in depth into how it works and how it can be used.
Nslookup:
Use nslookup to find the IP of a server from a domain name. Simply type nslookup followed by
the domain you want to resolve.
Nslookup google.com
Alternatively, you can perform a reverse lookup by entering an IP address and finding out the
associated domain name.
Nslookup 8.8.8.8
Awesome, right?
Netstat:
Netstat stands for network statistics and as the name suggests it can be used to display various
information about your network connections such as which application (if any) is establishing
connections, which ports are being used, and various other statistics.
You can use this information to troubleshoot or manage your network as well as its connections.
Typing netstat by itself will display every active connection in your computer along with the
protocol, the local and remote address as well as whether the connection is currently active or
not.
Netstat
Once you are done, press control and c to stop the execution of the command.
The output of the netstat command can get a bit messy and confusing, you can use several
parameters to filter, sort or display more information about your network connections.
Starting with -a, which will display every active port sorted numerically.
Netstat -a
The -e parameter, which will display various information such as the number of packets sent and
received the number of errors that have occurred and more.
Netstat -e
Finally, we have the -b parameter which requires administrator privileges to be run and will
display which application is establishing a connection.
Netstat -b
There are many more parameters that can be used along with the netstat utility browse through
the output of the help command to find them out.
Route:
You can use the route command to display or modify your computer’s routing table. To display
your routing table, type route followed by the parameter print.
route print
The -p parameter makes your entry persistent, without this parameter your entry will be deleted
in the next boot.
Next, type the action you want to take with this entry and the IP of the destination subnet,
optionally you can enter the subnet mask, if you don’t, the default will be used.
Then, enter the gateway IP and finally with the -if parameter you can specify the interface from
which packets will be sent.
Make sure you know what you are doing before changing route tables, the wrong command can
potentially break your computer’s connectivity.
Netsh:
The Netsh command can be used to do a variety of things. Everything from viewing your
internet protocol configuration to deleting your address resolution protocol configuration
cache and configuring various tcp/ip related settings.
Lets start with viewing your interface configuration. To do so simply type the following
command.
The netsh command works a bit differently than other cmd commands because it doesn’t not
accept parameters in the usual sence but rather accepts contexts.
As the name suggests “contexts” are words that provide context to the netsh command so that it
knows what to do. In this case the “interface” context tells our command that the operation we
want to perform is on our interfaces.
The “ip” command specifies that we want to do something on the internet protocol
configuration and finally the “show config” contexts tell our command to show us our
configuration.
Apart from simply viewing information we can use the netsh command to perform a number of
operations on our network configuration. For example, with the following command we can
delete the cache of our address resolution protocol (or arp for short).
We can also configure our tcp/ip settings directly from the command line. The following
command for example will change the static ip, subnet mask and gateway ip of our “Local Area
Connection” interface.
We can even use the Netsh command to manage our firewall. With this command for example
we can create an exception for a specific port.
Summary:
Use ping, tracert and pathping to troubleshoot network problems.
Netstat stands for network statistics and as the name suggests it can be used to display
various information about your network connections.
Use ipconfig and nslookup to get all sorts of information about your network or a server.
Use the route command to display or configure your computer’s routing table.
The Netsh command can be used to view or configure your internet protocol
configuration.
Registry Structure:
Before we learn how to use the command line (CMD) to modify our registry we must first learn
how information within registry itself is structured.
The registry stores items in the following structure:
Hives -> Keys -> Values
Let’s start with Registry Hives.
Hives:
The windows registry contains several root locations that store various entries.
These locations are called registry hives.
Registry hives are separated based on the values they contain.
Here is a list of some of the most commonly used registry hives along with a brief description
about each one:
Name (Abbreviation) – Description
While there are several more registry hives these are the one you will likely be using almost
exclusively, so do not stress too much about the rest.
Keys:
Within these hives there are several sub-entries or keys, which categorize our values even further
into several groups.
For example, the Software key which is located with the HKEY_LOCAL_MACHINE registry
hive contains information and settings related to every application in your computer.
Basically, think of keys like containers or folders.
Values:
Within these keys we have various values, that our applications or windows have created.
Sort of like files within a folder.
These values are also called entries and will be using the two names interchangeably.
Entries, store data using several distinct data types, in the following list I have included the
name of each value in human-readable format, the name that they are listed as in the
registry(within parenthesis) along with a brief description.
There is no way I can explain this using plain English and fit it into a sentence, instead, if you
want to learn more, you would have to go here.
While these are not all the data types, they are the ones which you will likely use most.
Since this article is more about the command line itself and its relation to the registry, I wont
dive any deeper into the registry itself.
If you would like to, you can find more information about the registry by clicking here.
With that said you should now have the basics down and be ready for the following sections.
Right after our ADD parameter we have the location in which we want our key to be created, In
this case I created my key within the Software key which usually contains values for user-
installed programs.
Let’s check if our value was added successfully by using the QUERYparameter followed by the
location and name of our entry:
There are several more parameters with which you can use to perform several operations to your
registry and will learn about them later on.
Now we need to figure out the hex codes that correspond to our desired colors.
You can use an online converter, such as this one: HexColorTool
Or use an application with a color picker such as Paint or Photoshop.
In my case they are as follows:
You can find exactly what Hex codes (when referring to colors) are and how they work by
clicking here.
These hex codes are in the RGB Format, which means that the first two letters or numbers refer
to the red component, the next two the green component and so on.
Windows however uses the BGR format (for some reason), which means that if we want
windows to interpret our colors correctly, we need to convert them.
All we have to do is to switch the red and blue components around simply by switching the first
and last two numbers or letters around.
Here is what my colors look like in the BGR format:
Now that we have our colors lets create our first entry named AccentColor, which will specify
the title bar color for active applications:
Lest create a second entry named AccentColorInactive for our inactive applications.
Once again Replace the value of the /d parameter with the color of your choice while retaining
the 0x prefix.
The title bar color of your active and inactive applications should now be changed into your
desired colors.
Success! You not only know how to change the color of your title bar, but have learned a bit of
computer color science as well!
You are welcome.
Now this is usually the point where I give you the complete command, and all you have to do is
copy and paste it into your command line.
Not this time, call me cruel all you like, but you will have to do this one on your own.
This shouldn’t be hard, you might even learn something!
Thank me later!
P.S Be careful now, try not to break your computer (I take no responsibility).
Useful Parameters:
You are still here! All has gone well then.
Here is your reward:
A list of the most useful parameters for the reg command along with a brief description (not
much of a reward but whatever).
QUERY – Displays the contents of a location within the registry or the value of an entry.
ADD – Creates or Edits entries.
DELETE – You can probably guess this one.
COPY – Copies a specified registry entry from one location to another.
SAVE – Saves Keys and values into a specified file.
RESTORE – Writes entries and keys into the registry from a saved file.
LOAD – Writes entries and keys from a saved file into a different specified key.
UNLOAD – Removes entries and keys that where loaded with the Load parameter.
COMPARE – Compares two or more specified keys or values.
EXPORT – Writes entries and keys into the registry from a saved file, for use in a different
computer.
IMPORT – imports the keys and values form a file that was created using the export parameter.
Examples Summarized:
For your convenience, here is a list of some of the examples we used, along with a brief
description.
Creates a DWORD Entry with a data value of zero named MyEntry, within the
HKLM\Software Key.
Displays the data value of the MyEntry entry, which is located within the HKLM\Software Key.
Deletes the MyEntry entry, which is located within the HKLM\Software Key.
Deletes the entire MyKey Key, which is located within the HKLM\Software Key.
Summary:
If only an article of this size could be summarized perfectly into three bullet points. Anyway,
here goes:
The windows registry is a database that stores settings for the operating system as all as its
applications.
Use the REG command and the QUERY parameter to view your registry.
Create or delete entries or sub entries using the REG command and the Add or Delete
parameters.
That's It!