UNIX Primer

Home | Primer Home


Fun With Filenames

Now that we have some tools under our belt, let's do a quick exercise. Start by logging into your account. Make a directory called 'cit593' and then make that your current working directory. You may have noticed that we can do this easily by typing 'cd cit593' and we do not have to type the complete path from the root to this directory. This feature is called using the 'relative path.'

A relative path (or relative filename) is one which starts in your current working directory. Basically, any filename that you enter that does not start with the root directory ('/') is considered to be a relative name.

An absolute path (or absolute filename) is one which starts at the root of the filesystem. These names all start with the root directory ('/'). If you type 'pwd', it shows you the absolute name of your current directory.

Some notes to keep in mind:

Before you move on, take a few minutes to play with relative vs. absolute names and tab completion.

Another special trick using filenames is that we can use characters known as 'wildcards' to identify multiple files or files whose names we do not know. The two wildcard operators are '*' and '?'. They perform the following tasks:

* represents 0 or more unknown characters
? represents 1 unknown character
Here are some examples of how we can use these using the 'ls' command:
ls *          - Lists all files (the default behavior of 'ls')
ls *.java     - Lists all files with a '.java' extension
ls h*         - Lists all files starting with the letter h
ls hw2p?      - Lists all files whose name is hw2pX where X is any character.
ls hw2*       - Lists all files whose name starts with hw2
ls hw2p*.java - Lists all files which start with 'hw2p' and end with '.java'
ls cse120     - Lists the contents of the 'cse120' directory
                (Assuming it exists under our current directory)
You can also use these wildcards with most other UNIX commands, such as the ones you will learn in the next couple of lessons.


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