Introduction to UNIX – Part I Logging in

This section assumes that you have already installed (or are using a machine that has) SSH Secure Shell program. Double click the icon depicted below to start the SSH program.

Host: killdevil.unc.edu (if you do not have a killdevil account then use isis.unc.edu) User Name: Onyen Password: Onyen password Click on the “Quick connect” button. You will be presented with the following window.

You may get a pop-up window asking if you would like to store the server ID key in the local database. Click on “ok” to do so (in future you will not be prompted once you save the key). Note: If you are logging in for the first time a system program (“ssh-keygen”) will automatically run. Accept the defaults by pressing “return”. There will be a prompt for setting a password. Do *not* set a password (just press return) for this one-time key generation. These “keys” are required for cluster job submissions. It should only take a moment for this process to complete.

Once you log in successfully you are in a “shell” – your conduit for interaction with the operating system.

System commands are in “courier” font in text below First UNIX command (for at least some of you) Let us check to see where you landed after logging in – “pwd” (print working directory). [KillDevil-login2]$ pwd /nas02/home/k/e/kelkar (your “home” directory will be different) This directory is for configuration files. We are not going to put data here. Anything you put in this directory counts towards your disk quota (set at 10GB for ITS systems). More info about disk quotas is here: http://help.unc.edu/CCM3_034877.

Help with UNIX commands “Man” and “Info” commands [KillDevil-login2]$ man pwd [KillDevil-login2]$ info pwd Tip: “q” will allow you to exit from the man/info help pages.

Available file systems on the server [KillDevil-login2]$ df -kh “df” command output. Make a note of the options for the df command. Make a note of the “h” option. If no “arguments” are specified then information is provided for all user accessible file systems.

Changing Directories [KillDevil-login2]$ cd /netscr/”onyen” “/netscr” denotes a “scratch” file system that is used for temporary storage of data while you run jobs on the killdevil cluster (Tip: This file system is available across ITS-Research Computing clusters).

Note: If a “/netscr/ONYEN” directory does not exist then we can create one by issuing this command. [KillDevil-login2]$ cd /netscr [KillDevil-login2]$ mkdir “onyen”

Changing directories Paths for directories are relative (more on that later). For now, let us change to directory where we are going to work today. [KillDevil-login2]$ cd /netscr/ONYEN (replace your onyen here) (Can you check what directory you are actually in at the moment?) Tip: Anything data/files you store in the “/netscr/ONYEN” directory does not count towards your disk quota. At the same time you should not be keeping anything important here since this area is considered “scratch” space i.e. for temporary use while a job is running. Files left in the “/netscr/onyen” area are automatically deleted when they are not modified in last 21-days. It is your responsibility to copy data out of “/netscr/ONYEN” area that you want to store long term.

Working with a directory hierarchy We are now going to make a hierarchical directory structure. Organizing your work into discrete folders is a good way to manage the files/data. Tip: Getting into the habit of using logical names for new directories is helpful in the long run. Make sure you are in the “/netscr/ONYEN” directory before issuing the following commands (how do you check what directory you are in at any given time?) We are trying to create a directory hierarchy that will eventually look like this:

[killdevil-login2]$ cd linux/ [killdevil-login2]$ mkdir my_project [killdevil-login2]$ cd my_project/ [killdevil-login2]$ ls [killdevil-login2]$ mkdir arrays next_gen_seq rt_pcr [killdevil-login2]$ cd arrays/ [killdevil-login2]$ mkdir jun12 aug12 oct12 [killdevil-login2]$ cd ../ [killdevil-login2]$ mkdir next_gen_seq/jun12 next_gen_seq/oct12 [killdevil-login2]$ tree /netscr/kelkar/linux/

How to delete a directory [KillDevil-login2]$ mkdir deleteme [KillDevil-login2]$ rmdir deleteme [KillDevil-login2]$ rm –r deleteme

“shell”, “path” and “environment” variables The command “echo” is used for printing information to screen/terminal. [KillDevil-login2]$ echo Hello Hello If a variable is provided to the “echo” command then the value contained in that variable is printed to screen. [KillDevil-login2]$ echo $SHELL SHELL variable describes default “shell” for the account. [KillDevil-login2]$ echo $PATH PATH variable describes *all* directory paths that are automatically searched every time a program is executed. Some of these are “system” paths that are common for most users. One can easily change/append additional directories to the $PATH variable. For “tcsh” shell: set PATH = ($PATH /usr/sbin

/usr/local/bin /netscr/ONYEN)

For “bash” shell: export PATH=$PATH:/usr/sbin/:/usr/local/bin:/netscr/ONYEN

[KillDevil-login2]$ env This command will print out the contents of several variables that are associated with your current working environment.

Working with files 1. Let us copy a file from the class resource site. We are going to use a utility called “curl” to do so. We will learn other options for transferring files in part II of this class. Make sure you are in the “/netscr/ONYEN” directory (how would you check this?). [killdevil-login2]$ curl http://www.unc.edu/~kelkar/HSL12_fall/unix/test.fa -o test_file.fa

Running UNIX programs/commands Generally UNIX command line has the following syntax (things in {} are optional parameters): [KillDevil-login2]$ {path_to}command name {command line arguments} {input file(s)} {output file(s)} 2. Check to make sure the file got copied to your working directory (use “ls”). 3. What kind of a “file” is this? You can do a few different things to find out this info. But first we should find out if this file is “human readable”. [KillDevil-login2]$ file test_file.fa test_file.fa: ASCII text You can list the contents of this file in more than one way. I am going to list a few below. [KillDevil-login2]$ more test_file.fa [KillDevil-login2]$ head test_file.fa [KillDevil-login2]$ tail test_file.fa [KillDevil-login2]$ cat test_file.fa

File/Directory Permissions

There are multiple levels of file/directory permissions that allow a very fine-grained access control. Permissions are split into three major categories. “user” , “group” and “all” (names are self-explanatory). Each category has independent attributes for “read/write/execute” permissions. Tip: Be careful about file permissions specially when changing them. It is possible to lock yourself out preventing access to files/directories you own by setting incorrect access attributes.

Useful UNIX commands •

nano – simple text editor



date



cal



whoami



finger