Recommended Resources
Abstract
An introduction to the fundamental basics of UNIX/LINUX shell including configuration, navigation and troubleshooting messages such as "sh: java: command not found" or "bash: db2: command not found" is returned.
Content
This site has lots of good examples
Learn UNIX in 10 minutes
http://freeengineer.org/learnUNIXin10minutes.html
What is a Shell?
When you login to the Unix console it will automatically start up a "shell" which is a command interpreter to process your commands.
There are many different flavors of shells, each of them interpret commands slightly differently when writing a shell script. More on this later. However for general use they behave the same way. Most operating systems (OS) will have all the shells available but their default shell will differ depending on the operating system. The system administrator can change the default shell used when an account is added to the system.
Shell | Location of Shell | Commonly set as default on |
| Default Shell | /usr/sh | |
| Korn Shell | /usr/ksh | AIX |
| Bash Shell | /usr/bash | Redhat Linux |
| C Shell | /usr/csh | ?? |
What happens during login to the UNIX/LINUX console ?
Depending on the shell configured for the user, it will execute all the commands listed in the hidden customization file in the user's home directory ($HOME). Any customisation commands are placed in this file.
Shell | Customisation File |
| Default Shell | $HOME/.profile |
| Korn Shell | $HOME/.kshrc |
| Bash Shell | $HOME/.bash_profile or $HOME/.bashrc |
| C Shell | ?? |
What happens when a command is executed in the UNIX/LINUX console?
Under the covers, it looks at all the locations set in the $PATH environment variable. To see what values are set execute:
$ echo $PATH
When a command cannot be found and it has been installed, it means the location to the command was not set in $PATH.
Navigating the shell
Go to a directory: cd /home
Go to a directory one level above: cd ..
Go to a user's home directory shortcut: cd ~/sqllib
This automatically goes to /home/db2inst1/sqllib
Display contents of current directory: ls
View contents of a text file: more readme.txt
Edit contents of a text file: vi readme.txt
vi reference
http://www.unix-manuals.com/refs/vi-ref/vi-ref.htm
Common Problems
/home/db2inst1: java
-bash: java: command not found
Java may be installed, but the java executable is not in your $PATH environment variable. When a command is executed, the shell searches $PATH to find the command. In our case the location to java is not in $PATH. To resolve, add the location of java to the PATH environment variable by editing the shell's customization file (e.g. .profile)
/home/db2inst1: db2
-bash: db2: command not found
This means the .profile for the DB2 instance userid did not "source" the environment variables used to run DB2. Ensure the cutomization file for your DB2 userid contains the lines below to source the db2profile script which sets up the environment variables.
For example on a Linux system using .bashrc it contains the following:
# The following three lines have been added by UDB DB2.
if [ -f /home/db2inst1/sqllib/db2profile ]; then
. /home/db2inst1/sqllib/db2profile
fi
Useful Commands
Check the built in manual pages to get instructions on how to use a command.
Example:
man ls
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
If you are looking for the location of an existing command like "ls" use the which command. This command will not work if the command you are searching for is not in your $PATH environment variable.
$ which ls
/bin/ls
To search for a file or executable, use the "find" command to see where the Java compiler (javac) is located use the command below. The command tells the find command to start searching from root (/), this may not be a good idea if your file system is very large.
$ find / -name javac -print 2>/dev/null &
View environment variables set.
$ env
View a specific environment variable
$ echo $PATH
Append the location of java and javac on your system to PATH, this change is not permanent since it was not added to the customization file. This example assumes the Java commands are in /opt/java/bin.
$ set $PATH=/opt/java/bin:$PATH
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21589801