Main index

Introducing UNIX and Linux


Files

Overview
The UNIX directory hierarchy
Filesystems
Manipulating files
      Creating directories
      Creating files
      links
      'Dot' files
Protecting files
      Groups
      File access control
      Changing privileges
File contents
      Text files
      Comparing files
      Filtering files
      Non-text files
Printing files
File archives and file compression
Other relevant commands
Summary
Exercises

Creating directories

To create a new directory, the command mkdir ('make directory'), followed by the name you wish it to have, will make a new directory with that name. For instance, we can create a file called dir1 in the current directory:

mkdir dir1

Conversely, to destroy a directory, use rmdir ('remove directory'). Note that rmdir will only work if the directory you are trying to remove contains no user files. You should get used to structuring your home directory so that it contains structured subdirectories. If you do not, and you have more than a very small number of files, then you are likely to find difficulty keeping track of which data you have stored where. A common way of organising your filespace is to use the same conventions that are used on the system files. This involves creating directories with 'standard' names:

bin commands you have written
src source code for the commands you have written
doc documentation
tmp temporary files

Chris' directory structure

Worked example

Create a directory called tmp in your home directory.
Solution: Firstly, change your current directory to your home directory by typing cd; check that no file called tmp already exists by using ls; and then type mkdir tmp.


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck