A Quick Introduction to Unix/Files and Processes
Everything in Unix is a file or a process. In Unix a file is just a destination for or a source of a stream of data. Thus a printer, for example, is a file and so is the screen.
A process is a program that is currently running. So a process may be associated with a file. The file stores the instructions that are executed for that process to run.
Another way to look at it is that file is a collection of data that can be referred to by name. Files are created by users either directly (using text editors, running compilers etc.) or indirectly (by running some program - like processing a text input file to produce a formatted file for printing).
Examples of files include:
- a text document;
- a program written in a programming language such as C++ or Java;
- a jpeg;
- a directory: directories can be thought of as the analogue of Windows’ folders. Directories are files that contain files.
The standard input and output and the standard error stream
There two files that have somewhat opaque names, stdin and stdout. These names refer to default sources of and destinations for data. Consider the process initiated by the command ls. The default output of this process is a list of files in the current working directory and we have seen that the output is displayed on screen. This illustrates the default output stdout which is nothing but the screen. The standard input by contrast is the keyboard - thus also known as stdin.
In shell programming it is often useful to prevent error messages from Unix commands from being displayed on screen but to either suppress them or send them to a file. This is done by redirecting the error messages to a filename or to /dev/null - the null device or destination. To use these streams (stdin, stdout, stderr) in the shell we don't refer to them by name but by the numerical descriptors
For the beginning user, the important thing to grasp is that commands effectively take their input from and direct their output to files, and by default the output file is the screen and the input file is the keyboard.
- Shells and subshells
- Directory Structure
- Files and Processes
- Listing Files and Directories
- Exercises 1
- Creating Directories
- Creating Files
- Changing Directories
- Special Directories
- Exercises 2
- Copying Files
- Moving Files
- Deleting Files
- Exercises 3
- Searching Text Files
- Permissions on Files and Directories
- Editing Text
- Exercises 4
- My First Shell Script
- Job Control
- Environment Variables