Getting Cosy With The Command Line
The command line is well scary. You can literally break your machine if you don’t know what you’re doing. In an attempt to make it a little less scary, I’ve been trying to get to grips with some of the basic commands and concepts that I might find useful. They are presented here for your reading pleasure…
Finding this information for Linux and Mac systems is ridiculously easy, but the Command Line in Windows is (in my experience) fairly poorly documented/explained. As such I’ve written the following with a beginner Windows user in mind.
The most basic commands that you’ll use will help you navigate around your PC. When you open Command Prompt, you are starting in a location on your PC. In this sense, the command line is an alternative to Windows Explorer.
You’re usually told where you are in the short line before your cursor:
From here you can mess around with your files and file structure using the following commands:
The above command provides you with a list of all of the files and folders that are in this location.
This changes your location, letting you move up or down the folder structure. The [target] in the above example will need to be replaced with instructions on where you’d like to go.
cd .. cd NewFolder cd NewFolder/AnotherFolder
If you wish to move up (into the parent directory), [target] should be replaced by ‘..’. If you wish to move down (into a child directory), you just need to type the name of that directory. If you wished to move more than one level at a time, your [target]s would just need to be separated by a ‘/’ (as shown above).
mkdir [new directory]
This makes a new directory in this location. You will need to replace [new directory] with the name of your new directory (unless that’s what you want to call it).
rmdir [unwanted directory]
This will remove a directory from this location. In place of [unwanted directory], insert the name of the directory that you want to delete. And in case you hadn’t guessed, this will also remove all files within that directory!
This will spit out a load of information which you’ll probably never use, but somewhere in there is a reference to your IP address, which you might otherwise have some difficulty finding.
You can also run programs from the command line by using something called the Path. Most programs have no need to be run from the command line, but in development there are plenty out there that do use it, and are powerful enough that learning how to use them on the command line is highly beneficial.
The path is a list of directories which will be searched (after the current location) when a command is entered. If a matching file is found, it will be run.
If you want to have a look at the files that are currently on your Path, you can use the following command:
That is a super-quick start in the command line. Once you understand the above commands and are a bit more comfortable on the command line, you can start using it for other things. I’ve used it for managing my Git repositories and downloading packages from Composer. There’s plenty more out there though, so the sooner you get used to the command line, the better off you’ll be!