UNIX Primer

Home | Primer Home


Files

A file is simply a collection of data grouped together in some order. There are many different types of files, and we will discuss some of these later. In the meantime, assume that when this primer refers to a 'file,' it is referring to a simple file, which is raw data not treated in any special way. For example, java files, which you will be creating this year, are simply files that contain text that you provide. This text has special meaning when run through a compiler, but otherwise is just stored character by character by the computer.

Files are identified by their name. A filename consists of one or more parts, separated by '.', the period character. The last part of the filename is commonly referred to as that file's 'extension.' For instance, all of the files we create that contain java code are given the extension '.java', and compiled java files have the extension '.class'

Below, you will find some commands for viewing the contents of files. These will become more useful as you continue in this tutorial.

Related Commands:

NameMeaningPurpose
cat CATenate Displays the contents of a file.
Syntax
cat <filename>
Notes
  • When called without a filename, reads from standard input (generally, the keyboard) and prints to standard output (generally, the screen). To exit, enter EOF character (CTRL-D).

NamePurpose
more Displays the contents of a file. Hit spacebar to move down a page, or enter to move down line by line.
Syntax
more <filename>
Notes
  • To exit, type 'q'
  • You cannot move backwards through the file!

NamePurpose
less Displays the contents of a file. Allows you to move backwards and forwards in the file using arrow keys, or jump by pages using the spacebar.
Syntax
less <filename>
Notes
  • Type 'q' to exit.
  • To search, type '/' and then what you want to find.

See Also:


Designed by D. Kaminsky
Edited by Diana Palsetia
© University of Pennsylvania, 2008