Note that this site is in currently in version 1.0.0-alpha.   Some functionality may be limited.

7. Creating Files and Folders

Creating a File

So far, we’ve only performed commands that give us information. Let’s use a command that creates something on the computer.

First, make sure you’re in your home directory:

$ pwd
/Users/your-username

Let’s move to the Desktop folder, or “change directory” with cd:

$ cd Desktop

Once you’ve made sure you’re in the Desktop folder with pwd, let’s try a new command:

$ touch foo.txt

The touch command is used to create a file without any content. This command can be used when you don’t have any data yet to store in it.

If the command succeeds, you won’t see any output. Now move the terminal window and look at your “real” desktop, the graphical one. See any differences? If the command was successful and you were in the right place, you should see an empty text file called foo.txt on the desktop. Pretty cool, right?

Handy Tip: Up Arrow

Let’s say you liked that foo.txt file so much you’d like another! In the terminal window, press the up arrow on your keyboard. You’ll notice this populates the line with the command that you just wrote. You can hit enter to create another foo.txt, (note - touch command will not overwrite your document nor will it add another document to the same directory, but it will update info about that file.) or you could use your left/right arrows to move the insert cursor around on the screen so you can, for instance, change the file name to foot.txt to create a different file.

As we start to write more complicated and longer commands in our terminal, the up arrow is a great shortcut so you don’t have to spend lots of time typing.

Creating Folders

OK, so we’re going to be doing a lot of work during the Digital Humanities Research Institute. Let’s create a projects folder on our desktop, where we can keep all our work in one place.

First, let’s check to make sure we’re still in the Desktop folder with pwd:

$ pwd
/Users/your-username/Desktop

Once you’ve double-checked you’re in Desktop, we’ll use the mkdir or “make directory” command to make a folder called projects:

$ mkdir projects

Now run ls to see if a projects folder has appeared. Once you confirm that the projects folder was created successfully, cd into it.

$ cd projects
$ pwd
/Users/your-username/Desktop/projects

OK, now you’ve got a projects folder that you can use throughout the Institute. It should be visible on your graphical desktop, just like the foo.txt file we created earlier.

Challenges for lesson 7

Assignment: Challenge

Try and create a sub-folder and file on your own!

  1. Type pwd to see where on your computer you are located. If you are not in the projects folder we just created, navigate to that folder using the commands you learned in the lesson on navigation.
  2. Type mkdir name-of-your-subfolder to create a subfolder.
  3. Type cd name-of-your-folder to navigate to that folder.
  4. Type challenge.txt to create a new text file.
  5. Type ls to check whether you created the file correctly.

Questions

Try again!

What does the up arrow command do?

(Select one of the following)

Workshop overall progress