Creating new folders and files in terminal

Creating new folders and files in terminal

For most people the typical way to create new folders and files is through finder on their computer. Using terminal or iTerm2, however, to create new files can be an easier and faster way.

First, open terminal. If you are using a mac, one way to open terminal is through Finder.

Image for postFinder icon

From there choose the Utilities folder. Depending on your computer it should look similar to a blue folder with tools on the front.

Image for postUtilities folder icon

Once in the Utilities folder, scroll down to the Terminal application and double click on the icon.

Image for postTerminal application icon

The terminal window will open up and you should see something similar to the image below. The most important part you are looking for is the dollar sign. This is your prompt where you will enter commands into the terminal.

Image for post

Even though it may seem like you are floating around in nothingness you are in computer. To ?see? where you are, type pwd (which stands for print working directory) at the command prompt.

Then to see what is in that location type ls (list folder contents) and terminal will return all the folders in that location. It should look similar to the following:

Image for post

Now we see that in the folder of hcleland there are 12 different folders or directories.

In terminal folders are referred to as directories. Let?s create a new file called collie within a directory called dog. You will need to FIRST create directory, then GO INTO that directory. Once you are in that directory you can create a new file that will be stored in the directory you are in.

Step 1. Create a new directory. Enter the command mkdir dog at the prompt. (Hint: right after the $ sign.)

Step 2. Go into or cd(change directory) into the new dog directory you just created using this command: cd dog

Step 3. Create a new file. Enter the command touch collie

Image for post

Voila! You have now created a new folder and file in 3 short steps.


No Responses

Write a response