Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this movie, we are going to be working with files and directories in Unix. Before we see how to create files in Unix, I want to just first talk about the way we name files, to make sure that we follow the standard Unix rules and conventions, and that's because they are a little bit different than what you are used to in working with Mac OS X's Finder. The first rule is that there is a maximum for 255 characters. That's the same as you are used and 255 should be more than enough. The second rule is that you want to avoid most symbols. I have listed off the main ones there, but you really want to stay away from almost all symbols and the reason why is that in Unix a lot of these from the command line have special meaning. In Unix, as it's trying to parse the line and figure out what you mean, may confuse the symbol on a file name for being a command or an operator that it normally uses. Now in some of these cases, Unix will allow you to use the symbol but then whenever you want to reference that file name and do something with it, you will have to escape the symbol. You have to put a backslash in front of it. So you end up typing a lot of backslashes to escape the characters, which is just more needless typing. So we just typically want to stay away from them altogether. What you do want to use are letters, numbers, and the period, underscore, and hyphen. Remember period has a special meaning. If it's the first letter of the file name, it becomes a dot file and it gets treated a little bit differently and it won't show up in the Mac OS X Finder. You also don't want to put a hyphen as the first character of a name because if you remember when we talked about options, options begin with a hyphen. So ls -la, that hyphen in front of la indicates that l and a are options. So we don't want to put hyphen as the first name of our file so that it never gets confused with being options. Typically, even though we can use uppercase letters, you want to stick to lower case letters in Unix and the reason why is because Unix typically is case sensitive. In other words, MyFile with capital M and F is different from myfile with lowercase m and f. They would be considered two different files in Unix. This applies to most Unix systems. Mac OS X is a special case because the default formatting for a hard drive is to use a case insensitive formatting for your hard drive and that means that then Unix on a Mac becomes case insensitive. Those myfile and MyFile would refer to the same thing. That's different from most Unix systems and it's important to know the difference because it can cause problems if you are dragging files over from another Unix system on to your Mac, because one of them is case sensitive and one of them is case insensitive. If you have two files, myfile and MyFile, on one system they are allowed to co-exist, but on your Mac they are not allowed to co-exist. They are considered the same file name. so keep that in mind, we would typically just stick with lowercase for all file names in Unix and avoid the issue altogether. The other thing is different from working the Finder is that underscores are better than spaces. It's no big deal to put spaces in your filename inside the Finder. You can certainly use them in your filename in Unix but remember spaces are how Unix can tell the difference between commands, options, and then all of the different arguments. Spaces are what help break that up and delineate the different parts. So if we have spaces in our file name, Unix can't tell that that should be one continuous filename. So every time we typed a name you have to put a backslash in front of the space to escape it, just like we have to escape those symbols. So instead of having to do that all the time, it's better just to avoid them. The other thing you can do is put quotes around names that have spaces in them and then it will know ah, this is one complete unit. I don't need to break that up. The last thing is that you want to use file endings whenever possible. They are not required but they are very helpful, .txt for text files, .html for HTML fille, and so on. It really helps you when you are looking at your listings to differentiate to what are files from commands and directories. Now there are a few other rules. For example, you can't name your file dot, or dot, dot, because obviously those have special meaning we have already talked about, either the current directory or the parent directory. You wouldn't want to name a file the same name as a Unix command. Now if you put a file ending at the end of it that won't be a problem, but you just don't want to call something a file echo, because echo is one of the commands that we're going to use and you want to make sure that Unix can tell the difference. Before we go onto creating files, let me just show you what I mean about this spaces inside the filename, just so you get an idea of that. Okay, so here I am in my Terminal and I am in my home directory. I will write cd and I am in my user directory and from here there is my library folder cd, library. Inside my library, if we do ls, you will see that there is Application Support that has a space in it. That's one of the folders that Apple created and Apple put a space in it. Perfectly legal to have a space in it, nothing wrong with it, but it creates a problem because now watch when I could do cd into Application, I will hit the Tab, you will see what the auto complete had to do. The auto complete put this backslash right here in front of the space to indicate this is all one thing. cd, don't take this as being two separate things. Look what happens if I go back here and take those out, cd Applications Support. Well you can look at it and tell what's going to happen. It's going to say "cd into Application? That's the folder? And then I don't know what I am supposed to do with Support," but it's going to try and just go in Applications and say there is no such file or directory. So it really does have to have that backslash in front of it. Application, hit Return, and you can see I went in there. You also, as I said, can put quotes around it. "Application Support" and it gets me that the same way. So those are the two ways that we have to make sure that Unix knows this one complete thing. It's one file name or one directory name. It's not supposed to be two separate things. Disregard that space.
Get unlimited access to all courses for just $25/month.Become a member
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.