Skip to Main Content

How Docs


Use Files and Directories in UNIX

NOTE: This document refers to software or hardware that is not currently supported by the University of Wyoming Information Technology Client Support Services. Although the information is believed to be correct, be aware that since no support is available, this information may be out-of-date or possibly no longer valid.


A directory is a collection of files and information about those files. The information about a file includes its name as well as various attributes of the file, such as permissions and size. By default, at login you are placed in what is termed your home directory, the top-most level directory of your username. In a listing of files in one's directory, a subdirectory is flagged with a slash (/ ) after its name.

Below are the UNIX commands necessary to create, delete, and change directories in your account. Remember, UNIX is case sensitive. For more complete information consult the UNIX man pages for each particular command.

The UNIX file structure is all based on the system root directory (referred to as /). From there, subdirectories comprise the rest of the system.

UNIX tree file structure example

Note: This is an example and does not comprise the whole file structure.

There are two ways to reference a file or directory in UNIX. One way is called an Absolute Path. That is a reference to a file from the system root directory. An example would be /ftp/etc/motd. This is the Absolute Path name for the FTP Message Of The Day file. You can use this reference no matter where you are in the file structure. Absolute Paths always begin with a slash (/).

The second way to reference files is called the Relative Path name. The relative path name is a reference to a file or directory based on where you are in the file system. If, for instance, you are in the /home/cowboyjoe directory and want to read a file in the /home/cowboyjane directory called data.txt using the more command you could type more ../cowboyjane/data.txt.

In this illustration, the directories cowboyjoe and cowboyjane are subdirectories, or child directories of the directory home.


List the contents of a directory by entering ls as in the example:


Note: Files with a slash (/) after their names are subdirectories. Files with an at sign (@) after their names are links to a file or a directory in another directory. Files with an asterisk (*) after their names are executables.

To create a subdirectory, enter mkdir Directory_name

For example, let us say our directory name is MYDIR.

frontier:˜>mkdir mydir

A subdirectory named mydir is created in the current directory.

To move down to a subdirectory, enter cd Directory_name

For example, to move down more than one level at a time the directory names may be put one after the other separated by slashes

frontier:˜> cd Directory_name1/Directory_name2

To move up a directory level, enter cd ..

  • The number of periods (..) separated by slashes (/) used indicates the number of levels to move up. To move up three levels, enter: frontier:˜> cd ../../..
  • The use of periods (..) and directory names may be combined.

frontier:˜> cd ../Directory_name

This command will move up one directory and down another.

To copy a file, enter cp source_pathname target_pathname

To copy a file called data.txt to backup.txt one would type:

frontier:˜> cp data.txt backup.txt

To move a file, enter mv filename

To move a file called data.txt to a subdirectory called datafiles one would type:

frontier:˜> mv data.txt datafiles

Note: If a subdirectory named datafiles does not exist as a child of the current directory, the file data.txt will be RENAMED to a file called datafiles.

To delete a file, enter rm filename

To delete a file called data.txt, one would type:

frontier:˜> rm data.txt

To delete a directory, enter rmdir directory_name

To delete a directory, ensure you're in the parent directory and type:

frontier:˜> rmdir directory_name

Note: If the directory is not empty, this command will fail. If you use the flag -r you can recursively delete all subdirectories beneath the directory listed as directory_name.

An example of this type of deletion is:

frontier:˜> rmdir -r directory_name

Note: Be very careful you know exactly what you are doing if you type this command!


Reviewed: 0706 By: CD

Additional help with the installation and configuration of
UW-supported software is available:
Contact the IT Help Desk at 766-HELP (4357), option 1
Contact your IT user consultant

Contact the IT Help Desk at 766-HELP (4357), option 1
Come to the student computer lab in the lobby of the
Information Technology Center.

Footer Navigation

University of Wyoming
1000 E. University Ave. Laramie, WY 82071 // UW Operators (307) 766-1121 // Contact Us