z/OS Unix
Part One

Unix System Services (USS) is an integral part of z/OS and is tightly woven into the operating system. Back in 1993, a previous version of z/OS called MVS/ESA OpenEdition was released that supported POSIX and other industry standards. This release included about 1 million new lines of code. OpenEdition ushered in a new era of interoperability for the mainframe by enabling a platform for existing Unix applications to be ported, and new Unix applications to be developed. When OS/390 was released in 1995, OpenEdition was renamed to Unix System Services.

Many of the modern capabilities of z/OS today would not be possible without the functionality provided by Unix System Services. Because it is so tightly integrated, most tasks that are performed in TSO or ISPF can also be achieved through USS. Conversely, many Unix tasks that are normally achieved through USS can be achieved through TSO/ISPF. This gives users an option to work inside USS or ISPF, depending on their comfort level and knowledge. For this challenge, you will use the instructions for Connecting to z/OS SSH in the Connectivity Guide to use a SSH client similar to what many Unix programmers would use.

Prepare yourself to dive into the shell and learn some basic commands!

Log onto z/OS Unix

Note: Many aspects of z/OS are not case sensitive; meaning you can enter commands and data in either UPPER or lower case. This is not so in USS. You must type commands in the proper case (usually lower).

When logging onto USS, you may enter your user ID and password in either UPPER or lower case. Your user ID and password is the same as the one you use for TSO/ISPF. They both use the same highly secure database and software that resides on z/OS.

The Connection Instructions page of the Connectivity Guide describes the steps required to connect to Unix System Services. Once you've connected successfully, you will be presented with a password prompt:

Enter your password (you just changed it in the previous section!) to complete the log in procedure. You have successfully logged into Unix when you see the a message about bash in z/OS, followed by a prompt.

Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh). source: bash(1) man page

Fundamental Unix Commands

Once logged in, you are automatically placed into your home directory and presented a command prompt. Your home directory is yours and yours alone. You are free to create, modify and delete any file or sub-directory contained within. No one else will be able to view or alter the contents of your home directory.

What follows is a list of Unix commands that every user should be familiar with. Run each of these commands as indicated.


"man" displays the manual for any command. If you are not sure how to use a given command or are curious as to what else it might be able to do, just type "man COMMAND". When viewing man pages, you can page forward by pressing the spacebar and Enter. Jumping to a specific page is possible by typing the page number and Enter. It's also possible to search an opened man page by typing a forward slash "/" followed by a regular expression and pressing Enter. Type the Q key and Enter to quit and return to the command prompt.

Run the following command:

man man

We recommend that you run "man COMMAND" for each of the commands listed in this section.


"ls" lists the contents of the current directory. Since you are in your home directory, running ls now will show you every file and sub-directory contained there.

Run the following command:

ls -l

"ls -l" and "ls -la" are important variations of ls; try running them and see if you can tell what the difference is. Confirm your hypothesis by checking "man ls".


"cat" concatenates a list of files and prints their contents to the shell. Very often cat is used to quickly display the contents of a single file. Notice the README file that was listed before? Print the contents of the README file now.

Run the following command:


"more" is used to browse the contents of a file. While cat is useful to view short files, it doesn't work well with long files. more to the rescue! The navigation inside more is very much like that of man, so you can use the same navigation tricks you just learned about for moving around inside the file. Use more to view the README file now.

Run the following command:


"mkdir" makes new directories. Just like the directories in other operating systems, directories in Unix are used to provide a heirarchical organization to the file system. To make a new directory, you simply pass the directory name as the first argument to the mkdir command. Make a new directory in your home directory named "bin".

Run the command:

mkdir bin

Use the "ls" command to ensure the new directory is created.


"cd" changes the working directory. Your home directory can be simply referenced with a tilde or "~". To return to your home directory from anywhere else in the file system, simply execute "cd ~".

Run the commands:

cd bin
cd ~

"cp" is used to copy a file or directory from one location to another. Try copying the README file to the bin directory, and rename it at the same time.


Use the "cd" and "ls" commands to ensure that the file was copied successfully.


"echo" displays a given line of text. This is useful for prompting users for input or for displaying the contents of environment variables. For example, there is an environment variable named $USER that contains your user ID. Let's have Unix say hello to you.

Run the command:

echo Hello $USER

Note that $USER is in all CAPS.

Relative vs. Absolute Paths

Every location or node in the Unix file system can be indicated by a path. For example, the path to your home directory is "/z/CC#####", where CC##### is your user ID. This is called an absolute path because it describes a path that begins at "/", or the file system root directory. The path then goes into the z directory, inside which the CC##### directory is found. Note that your user ID in USS is all lowercase, including your home directory name.

Another way to describe locations in Unix is with a relative path. At any given time, there is always a "current working directory". A single period "." is a shorthand way to indicate the current working directory and two periods ".." describes the parent directory. If you ever wish to refer to a file or directory inside your current working directory, you can prefix the path with "./" (dot-slash). Likewise, if you wish to reference a file in the parent directory you would prefix the path with "../" (dot-dot-slash). Using relative paths enable you to traverse the file system quickly without having to always express the full path.

Note: The absolute path to the current working directory can always be known by checking the $PWD environment variable, or by running the pwd command.

File Permissions and the $PATH Variable

Time for another new command:


"which" will report the absolute path to any executable file that the shell can find.

Run the following commands:

which ls
which java
which iconv

How does the shell know where to search for executable files? Introducing the $PATH. The $PATH variable contains a colon separated list of paths to various directories in the file system that contain executable files. Take a look at the contents of the $PATH variable now.

echo $PATH

Whenever you enter a command, Unix searches each one of the directories in the $PATH list, in order, until it finds the command or reaches the end of the list. If a command exists in more than one PATH directory, the first directory in the list is used.

Notice that one of the paths in the list is the bin directory inside your home. This means that any program you place in your ~/bin directory can be executed without having to specify the path! Let's try this out.

Run the command:

cp /z/public/partone/finish-p1.sh ~/bin

This copies the finish-p1.sh file from /z/public/partone to your bin directory. List the contents of ~/bin to ensure that you have made a copy of the file and that it is in the correct location.

To finish this section of the contest, you must run the finish-p1.sh program. Try doing so now with the command:


Uh oh, permission denied! Let's take a moment to discuss how Unix file permissions work.

Each file and directory in Unix has three user-based permission groups:

  • owner: The owner permissions apply only to the single user that owns the file.
  • group: The group permissions apply to all users in the group that owns the file.
  • others: The others permissions apply to everyone else on the system.

There are three types of permissions:

  • r = Read: Permission to view the contents of a file
  • w = Write: Permission to alter the contents of a file
  • x = eXecute: Permission to run a file

Each of these three groups can have any combination of the three types of permissions. The command ls -l will display the file permissions for all files and directories in the current directory, along with the owning user and group.

For example:

-rw-r--r--.  1 CC#####  IPGROUP      270 Aug  1 20:50 finish-p1.sh
  ^  ^  ^
  |  |  |__: Other
  |  |_____: Group
  |________: Owner

Here, the CC##### is the owner, and IPGROUP is the group. CC##### has permission to read and write the file, but group and other access is limited to read only.

Your copy of finish-p1.sh should also have the same permissions, except it will be owned by your user ID. Since you are the owner, you can modify it's permissions. Time for another command!


"chmod" changes the file mode bits, which are used to describe file permissions. Without going into further detail, the following command will change the mode bits to allow you to execute the finish-p1.sh file:

chmod u+x ~/bin/finish-p1.sh

Check the man pages for chmod for additional details. If you run "ls -l" on the file again, you should see that the owner permissions are now "rwx". Try again to execute the finish-p1.sh file and pay close attention to any error messages you might receive.

If all works as designed, you will see some output indicating that your MVS data set "CC#####.P1.OUTPUT" was updated. Feel free to check it out sometime.

In preparation to complete Part One, return to ISPF via your 3270 client to perform some final actions. To exit and log off of USS, enter the command exit.

Next: Completing Part One