Part 2: Using the Command Line for Beginners

Typing into the Command Line

You’ve already learned the basics of using the command line for beginners in Part 1. It’s time to get a bit more advanced. Now that we can move around and see where we are in our file system, we can use the file systems to create new files and directories. Personally, this is one set of commands that I find to be much faster than any method of creation offered by the operating system.

Typing into the Command Line

Setting up new directories & files

mkdir <new-directory-name> – This command is short for Make Directory. It may come as no surprise to you that this command creates a new directory. Like cd, mkdir needs an argument to use for the name of the new directory.

CMD-Demo - MKDIR make directory example
touch <new-file-name>
– Similar to mkdir, touch creates a new file. Also similar to mkdir, touch requires an argument to use for the new file’s name, including its suffix.

CMD-Demo - Touch or creating a new file

Terminal Commands

Now we have made files and directories and now we can move freely among them we can actually manipulate them with a new host of terminal commands.

cp <source-file> <destination-file> – The cp command is short for Copy. This command allows a user to make copies of current files. This commands needs two arguments. The first is to designate the file we wish to copy. The second is to name the file that we wish to copy to. That file may not currently exist and that’s okay. Like touch, cp will create the new file then copy the source file’s contents into it.  

CMD-Demo - Copy Filemv <source-file> <renamed-file-or-location> – The mv (Move) command allows for a couple of different applications. Firstly, we can, as the name implies, move a file to another destination. The other, less obvious, usage for this command is to rename files and folders.

CMD-DEMO - MV Source File example

rm <file-or-directory> – Finally if we need to get rid of a file we can use the rm command. Like cd, rm accepts an argument that is the path to the file you want to delete.  

CMD-Demo - RM File or Directoryflags – As if all of this wasn’t enough, each of these commands can be modified through the cunning use of flags. A flag modified or changes the behavior of a command. Flags are applied after the command. For instance, if you use the –l command in conjunction with the ls command, so ls –l, the command still lists all of the directory’s contents, but in list form. Additionally, if we include a a flag with our ls command it will list all files, even hidden ‘dot’ files. We can even combine them to do both!

CMD-Demo - Flags example

That’s a lot! But we’ve barely even had a taste of working with the terminal. Maybe in the future we can look a little deeper at commands like top, more,  and tail. Working with the terminal can be a great skill to become fluent with. Many great software tools are best operated from the command line (see: git). It is my opinion that fluency with the command line is non-negotiable, essential skill for the modern developer. For some other information and practice check out Code Academy’s course on the subject or this e-book called, fittingly, The Command Line Crash Course.