Using the command line on Windows

We’re all used to using the mouse and nice user interfaces when working on a computer, but sometimes using a command line can be very useful! For instance, it’s the best way to encode videos and audio using the excellent FFmpeg, or using the command line renderer of After Effects. I’m going to explain here the basics of the command line on Windows. If you’re on Mac, click here (coming soon)!

Click on the images to see them at full size.

Opening a terminal

You can just press the windows button of your keyboard, type “cmd” and press return, or you can use the application called Windows PowerShell which is a bit more advanced, but still very similar to the standard command line.

This is the terminal on Windows. Like in the file explorer, you’re “in a folder”, in this example in the “Duduf” subfolder of the “Users” folder on the “C” drive.

Navigating, typing commands

To know where you are in the file system, just look at the beginning of the current line.
You can navigate in the file structure by typing the command cd followed by a space and the name of the folder where you want to go.

As you can see in this example, typing cd .. gets you to the parent folder. Note that to be quicker, you do not have to type the whole name of the folder where you want to go, you can only type the first letters and then press the Tab button, and the terminal will automatically complete the name. If there are several folders which names begin with the first letters you typed, you can cycle through all of them by pressing the Tab button again.

If you type a letter followed by a colon – e:in this example – you can access the drive corresponding to this letter.

Spaces in the command line are used as a delimiter between commands or options. When you navigate to a folder which has spaces in its name, you have to write it between double quotes. But this is done automatically when pressing the Tab button!

Notice the double quotes for the folder name. They were added automatically after typing only cd de and pressing Tab.

You can display the list of the sub-folders and files in the current folder with the command dir.

Using command line applications

To use a command line application, you either have to navigate to the executable file, or to type the whole path to it (which can be quick using the Tab button trick), and type its name.

Most of applications are launched with command line arguments or options, which are just other commands added after the executable file name and separated between spaces.

This is the command to display the help of the FFmpeg application.

Simplifying the access to the executable files you often use.

Of course, it can be a pain to always have to navigate to the folder containing some applications, if you use them very often. Fortunately, it is easy on Windows to make the system “know” where they are so you do not have to type the whole path anymore. This is done using the Environment Variables of Windows, which are just simple options you can modify.

Just go to the system informations (through the configuration panel, or right-click on the This Computer icon on your desktop, then go into the Properties), and then open the advanced system parameters.

There, click on the Environment Variables button. In the dialog which opens, find the variable called Path in the user variables.

Now you just have to click on modify, then browse in the next window to add the path to the executable file of the application you want to use.
Once it’s done, you can open a new command line and now you just have to type the name of the executable file wherever you are to use the application!

Now I can use the application wherever I am, without the need to navigate to its folder. Notice that I don’t even need to add “.exe” to the name of the command.

That’s it for now! These are the very basics you’ll need to use tools like FFmpeg, but there are a lot more things you can do with the command line, like managing files (copy, move, remove…). You can even use it for batch processes with .bat files. Use your favorite search engine to find out more 😉


I could not do and share what I do for free without your support. Help me on Patreon! Thanks.

2 thoughts on “Using the command line on Windows

  • 20 October 2017 at 5 h 40 min
    Permalink

    If you’re on a recent version of Windows I really suggest you look at Powershell, which is a more modern approach to shell scripting. Unlike cmd, it is object-oriented, giving you the power of the shell with the ease of working with objects. It’s like applescript, but way faster and less quirky.

    Since leaving OSX on my workstation I was really missing having zsh to do all my shell stuff, but now I’m learning Powershell I don’t want to go back.

    Reply
  • Pingback:Easily transcode any media to any format using FFmpeg – Duduf

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.