Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Creating a File

00:00 Okay, next let’s get a bit more Python specific. I want you to create a Python file but without stepping out of the terminal, and the file should be named hello_terminal.py.

00:14 Yes. So there are a couple of ways of doing this. So I guess we can start with the most basic one, which is called touch, and we can figure out why it’s called touch in a minute.

00:25 But if I just type touch hello_terminal.py, at least we got no feedback, so it seems like it worked. We can have a look now inside of here, which files are available.

00:38 So there’s a command called ls, which I think is short for list, and here we can see that it lists out the name of this file that we just created. Okay, so that’s, the contents of the directory are listed now, and the hello_terminal is in the pb_terminal/ directory.

00:57 Exactly. Okay, so the touch command is kind of like the touch on your—you touch it on your hard drive, or is there a history to this command?

01:08 Yes, I guess let’s start actually by increasing a little bit with the ls command. So we talked about so far that we sometimes want to have arguments to your commands, so like here we had makedir pb_terminal.

01:21 We can also have options, and typically they will start with the dash, or minus, sign (-) like this. So this -l here, that means long listing.

01:30 So it gives me a little bit more information about the files. So instead of just pointing at the name here, this one has the name right here, but it also has the creation date.

01:41 It has the size, which is currently empty, and it has my name because I’m the owner of this file. And over here is some access things essentially saying who is allowed to read this file.

01:54 What this touch command does, or was actually designed, to do is to change the access time on the file. So we can see here, if I just say touch hello_terminal.py one more time, that still works, and if I do ls -l, you can see that this timestamp there has been updated. Okay.

02:13 But now I have a question. If there would be some content in the hello_terminal.py file already, and you would run touch again, would you overwrite it?

02:22 Like, would it be empty again, or does it only modify the time? touch only modifies the time, so it doesn’t change the contents of it. What we’re kind of seeing, and it’s kind of become a typical thing to do, is to kind of abuse this command to create empty files because if the file doesn’t exist, then it creates the empty file. Okay, gotcha.

Become a Member to join the conversation.