Buy Prescription diet pills online

Unix Manuals

Unix Tutorials

NOTICE - New forum for all UNIX learners, users and programmers - click here

The UNIX® Filesystem - Introduction

The 'filesystem' is about the most important concept you must get used to in a UNIX system. It is as central to the work you will do in UNIX as, for example, your desk is probably central to your work now. Luckily, the UNIX filesystem is quite easy to learn to use - the following few segments will have you up to speed with the basics in no time.

What is the filesystem?

A UNIX system, like any other type of computer system, has some basic objectives: To store and process data. Of course, the exact type of data, and what processesing is done with it, will vary from system to system. On one system, there may a large accounting application, which will store details of financial transactions. At the other end of the scale, an individual may use a system to store private letters, or college notes. Someone else may store an address book, phone numbers, and their diary on the system. Of course, one system could be used for any or all of these applications, and endless others. They all have one thing in common: the need to store and retrieve data. The task of the filesystem is to provide a way to store data, in an organised structure, and retrieve it when requested. This is why it is so central to anything else you will ever do with a UNIX system.

Files

The basic 'unit' of the filesystem is, as you may guess, the 'file'. To understand the concept of a file, think of a blank piece of paper. At first, it contains nothing. However, you can write on it, and you can write anything. Similarly, a 'file' may be empty, or it may contain any amount of data. The data it contains can be anything, for example a list of phone numbers, a letter to a customer, or your company's accounts. In effect, a file is just like a piece of paper - the main difference is that it may store any amount of data.

The only other thing to note about files is that each one has a name. Think of this as the title at the top of the piece of paper. For example, one file may be named 'diary', while another may be named 'expenses'. This name is called the 'filename', and is simply used to determine one file from another.

Let's try an exercise now, to get to grips with the concept of files.

Exercise: Use the 'vi' editor to create a new file named 'diary'. (The command you will use for this is 'vi diary' - if you need help with vi, return to the vi tutorial and/or the vi reference guide). In the file, create a few lines which contain your schedule for the next few days, for example:
17th - AM - Continue learning Unix. PM - Draft report for new customers.
18th - AM - Get accounts up to date. PM - Organise payroll details.
When you have finished this, save the file and exit vi. Don't worry about the exact layout or contents of the file - the idea is just to get some text into a file for now!

You've just created a file called 'diary'. It contains some text, which in this case, is your schedule for the next day or two. Note however, that it could have been any text at all. You've given the file a label: 'diary'. This should help you to remember what the file is, and what it contains. Next time you need to see your schedule, you can look up that file. What you've just done is similar to taking a blank piece of paper, labeling it 'diary', and then writing on it.

How can I see what files I have?

In the previous exercise, we just created a new file. As well as that, there may (or may not) be several other files that you can access already. To list these files, use the UNIX command 'ls':

$ ls

Don't forget - the '$' is the prompt displayed by UNIX - you do not type that, but you do press ENTER or RETURN after each command.

The system will respond with a list of files, which should include your new file 'diary'. For example, the list may look a bit like this:

$ ls
diary				expenses				www-files
dictionary			todo
$

No matter how many other files are there, your file 'diary' that you created in the previous exercise should be visible. The only case where it may not be, is if your list of files is so long that some of them scroll off the top of the screen!

We already know how to create a file, and edit it (both using vi).

Exercise: Using 'vi', load the file 'diary' again. Make a few changes, for example add a line at the start that says "My Schedule for this week". Then save it and exit vi.

For now, we will learn just one more command: If we want to look at a file, but not make any changes to it, we use the command 'cat'. (This is short for 'concatenate' - the reason the command is called this dates back decades, and need not concern us here!). The command 'cat' takes a paramater - the name of the file to view. In this case, let's use the command to look at our diary file:

$ cat diary

The system will respond by displaying the whole of the file 'diary' for you. Depending on what you entered in the file, it will look something like this:

$ cat diary
My Schedule for this week
17th - AM - Continue learning Unix.  PM - Draft report for new customers.
18th - AM - Get accounts up to date.  PM - Organise payroll details.
$

Ready to move on?

This has been a fairly long segment, but you've learned some of the most useful things you will ever learn about UNIX - it really is the equivalent of learning to read and write. You now know how to create a file, put some text into it, and save it. You know how to re-load it, and make changes, using vi. You know how to look to see what files are there, and how to look at the contents of an existing file. At this stage, have a quick practice by using the following exercise:

Exercise: Create a new file named 'contacts'. In the file, start a simple list of names of your colleagues or friends. Alongside each one, put their phone number or extension number. Don't do too many - just 5 or so will do for now. Then save the file and exit vi. Use the 'ls' command to see the file listed, alongside your 'diary' file, and maybe other files. Use the 'cat' command to look at your 'diary' file, and then use the 'cat' command again to look at your new 'contacts' file.

You can now see how the file system can be used to store and retrieve basic information. In the next section, we will look at files in more detail, and learn some more useful tricks and skills.

Go to next section - More about Files

vi Reference

Home


© Copyright 2000-2003, Tom Reader, All Rights Reserved.
UNIX is a registered trademark of The Open Group in the US and other countries.
For more information on the use of the UNIX trademark, click here.
The contents of this site are not connected with or endorsed by The Open Group in any way.