Tutorial 2 | Files and Directories
2.1 Creating Directories
When you want to store files in a new directory, you use the mkdir command to create a directory. To create a directory:
- First, type in the ls command to make sure that the planned name is not same as an existing directory or filename.
- Then, type in the mkdir command followed by a directory name to create a new directory. So, for example, type in
mkdir Tutorials to create a new directory named Tutorials. - If you want to make sure that the directory was created, type in the ls -l command to look at the listing for the new directory. Here, the -l flag specifies a long format. (See 2.3 for more detail.) In the listing, the d at the far left for the new directory tells you that it's a directory and not a file.
- When you try to create a directory with a file or directory name that already exist, you'll be told that a file or directory by that name already exists. Unix will not overwirte the existing file or directory. You should try again with a different name.
- When naming directories or files, you should keep in mind that the difference in capitalization makes each name unique.
- If you want to use special characters when naming directories or files, you can use either periods (.) or underscores (_). All other characters should not be included.
- If you want to create several directories and subdirectories at once, you can do it by using -p flag. So, for example, if you want to create a new directory called Tutorials that contains a subdirectory called Computer with a subdirectory called Programming, type in mkdir -p Tutorials/Computer/Programming.
