Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now that we understand about file naming, we are actually ready to start creating some files and there are three main ways to create files in Unix. The first is using a text editor and Unix has its own text editor. We are not going to be using the text editors that you have on your Mac like Microsoft Word or whatever it might be. We are going to be using Unix's text editors and we are going to see how to do that in the next movie. There is also a technique where we can direct output from a command and put that in a file and we will see that in a future chapter. Then there is the simplest of all, the one that we are going to look at right now, which is just touch.
Let's go back to our command line and see how the touch command works. Back in my home directory, we can just see what's in there right now, ls -la. We will see the full list. Before we do touch, let's take a look at what touch actually does. Let's look in the manual for touch. Change file access and modification times. Well that doesn't sound like it has anything to do with creating files. But here is the thing. touch is a very simple command that Unix users use all the time and what it does is it just reaches out to a file and if it exists it touches it and updates its access time.
If it doesn't exist, it creates it for us and it's that second part that is what I want us to see. So let's just do touch somefile.txt and now let's do a listing again and there it is. It's the last one there. It's a zero file. There is nothing inside of it. You can see that the size of the file here. All I did was reach out and say, "Oh you want me to touch that file? Well it doesn't exist. I will create it for you." Now the other way of using touch would just be to say, let's say, touch .bash_history and see my history file right there. You can see the last access time for it was 15:59.
I will touch the bash_history and then let's go up, ls -la, now we can see that the time has been updated. Now it's 16:12. Now let me be the more conventional way of using touch, but the thing is that Unix users use touch to create files all the time. It's a really, really simple thing to do. You want to make sure that the file exists, so you touch it. If it exists already, fine. It's just going to update its access time and it's there, but if not, it will create it for us so that we can be assured that that file is there whenever we do a future operation.
So just keep it in mind as one of the tools. Now the file it creates is empty and in most cases what's more useful is actually to be able to put content in the file. So for that we are going to need to use a text editor.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97238 Viewers
61 Video lessons · 84517 Viewers
71 Video lessons · 68723 Viewers
56 Video lessons · 101209 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.