From Beocat
Jump to: navigation, search
(Connection settings maybe?)
(Nearly done with initial creation)
Line 10: Line 10:
** OS-X has SSH a built-in application called "Terminal". It's not great, but it will work for most Beocat users.
** OS-X has SSH a built-in application called "Terminal". It's not great, but it will work for most Beocat users.
** [http://www.iterm2.com/#/section/home iTerm2] is the terminal application we prefer.
** [http://www.iterm2.com/#/section/home iTerm2] is the terminal application we prefer.
* Linux
** Linux has SSH built-in as the command <tt>ssh</tt>. It can be used from any [[wikipedia:Terminal emulator|Terminal emulator]].
* Others
* Others
** There are [[wikipedia:Comparison_of_SSH_clients|many SSH clients]] for many different platforms available. While we don't have experience with many of these, any should be sufficient for access to Beocat.
** There are [[wikipedia:Comparison_of_SSH_clients|many SSH clients]] for many different platforms available. While we don't have experience with many of these, any should be sufficient for access to Beocat.


{| class="wikitable"
You'll need to connect your client (via the SSH protocol, if your client allows multiple protocols) to beocat.cis.ksu.edu.
 
For command-line tools, the command to connect is
ssh ''username''@beocat.cis.ksu.edu
 
Your username is your [http://eid.ksu.edu K-State eID] name and the password is your eID password.
 
'''Note:''' When you type your password, nothing shows up on the screen, not even asterisks.
 
You'll know you are successfully logged in when you see a prompt that says
(''machinename'':~) ''username''%
where ''machinename'' is the name of the machine you've logged into (currently either 'athena' or 'minerva') and ''username'' is your eID username
 
== Transferring files (SCP or SFTP) ==
Usually, one of the first things people want to do is to transfer files into or out of Beocat. To do so, you need to use [[wikipedia:Secure_copy|SCP]] (secure copy) or [[wikipedia:SSH_File_Transfer_Protocol|SFTP]] (SSH FTP or Secure FTP). Again, there are multiple programs that do this.
* Windows
** Putty (see above) has PSCP and PSFTP programs (both are included if you run the installer). It is a command-line interface (CLI) rather than a graphical user interface (GUI).
** MobaXterm (see above) has a built-in GUI SFTP client that automatically changes the directories as you change them in your SSH session.
** [https://filezilla-project.org/ FileZilla] (client) has an easy-to-use GUI. Be sure to use 'SFTP' mode rather than 'FTP' mode.
** [http://winscp.net/eng/index.php WinSCP] is another easy-to-use GUI.
** Cygwin (see above) has CLI scp and sftp programs.
* Macintosh
** [https://filezilla-project.org/ FileZilla] is also available for OS-X.
** Within terminal or iTerm, you can use the 'scp' or 'sftp' programs.
* Linux
** FileZilla also has a GUI linux version, in additon to the CLI tools.
 
=== Using a Command-Line Interface (CLI) ===
You can safely ignore this section if you're using a graphical interface (GUI). We highly recommend using a GUI when first learning how to use Beocat.
 
<u>First test case</u>: transfer a file called myfile.txt in your current folder to your home directory on Beocat. For these examples, I use bold text to show what you type and plain text to show Beocat's response
 
Using SCP:
'''scp myfile.txt ''username''@beocat.cis.ksu.edu:'''
Password: '''(type your password here, it will not show any response on the screen)'''
myfile.txt                                                                            100%    0    0.0KB/s  00:00
 
Note the colon at the end of the 'scp' line.
 
Using SFTP
'''sftp ''username''@beocat.cis.ksu.edu'''
Password: '''(type your password here, it will not show any response on the screen)'''
Connected to beocat.cis.ksu.edu.
sftp> '''put myfile.txt'''
Uploading myfile.txt to /homes/kylehutson/myfile.txt
myfile.txt                                                                            100%    0    0.0KB/s  00:00
sftp> '''exit'''
 
SFTP is interactive, so this is a two-step process. First, you connect to Beocat, then you transfer the file. As long as the system gives the <code>sftp> </code> prompt, you are in the sftp program, and you will remain there until you type 'exit'.
 
<u>Second test case:</u> transfer a file called myfile.txt in your current folder to a diretory named 'mydirectory' under your home directory on Beocat.
 
Here we run into one of the problems with scp - there is no easy way of creating 'mydirectory' if it doesn't already exist. If it does not already exist, you must login via ssh (as seen above) and create the directory using the 'mkdir' command (see Common Linux Commands) below.
 
'''scp myfile.txt ''username''@beocat.cis.ksu.edu:mydirectory'''
Password: '''(type your password here, it will not show any response on the screen)'''
myfile.txt                                                                            100%    0    0.0KB/s  00:00
An alternative version. If the colon is immediately followed by a slash, the directory name is taken from the root, rather than your home directory. So, given that your home directory on Beocat is /homes/''username'', we could instead type
'''scp myfile.txt ''username''@beocat.cis.ksu.edu:/homes/''username''/mydirectory'''
Password: '''(type your password here, it will not show any response on the screen)'''
myfile.txt                                                                            100%    0    0.0KB/s  00:00
 
Using SFTP:
sftp ''username''@beocat.cis.ksu.edu
Password: '''(type your password here, it will not show any response on the screen)'''
Connected to beocat.cis.ksu.edu.
sftp> '''mkdir mydirectory'''
[Note, if this directory already exists, you will get the response "Couldn't create directory: Failure"]
sftp> '''cd mydirectory'''
sftp> '''put myfile.txt'''
Uploading myfile.txt to /homes/''username''/mydirectory/myfile.txt
myfile.txt                                                                            100%    0    0.0KB/s  00:00
sftp> '''quit'''
 
<u>Third test case:</u> copy myfile.txt from your home directory on Beocat to your current folder.
 
Using scp:
scp ''username''@beocat.cis.ksu.edu:myfile.txt .
Password: '''(type your password here, it will not show any response on the screen)'''
myfile.txt                                                                            100%    0    0.0KB/s  00:00
 
Using SFTP:
'''sftp ''username''@beocat.cis.ksu.edu'''
Password: '''(type your password here, it will not show any response on the screen)'''
Connected to beocat.cis.ksu.edu.
sftp> '''get myfile.txt'''
Fetching /homes/''username''/myfile.txt to myfile.txt
myfile.txt                                                                            100%    0    0.0KB/s  00:00
sftp> '''exit'''
 
== Basic Linux Commands ==
Again, this guide is very limited, mostly limited to directory navigation and basic file commands. [http://www.ee.surrey.ac.uk/Teaching/Unix/ Here] is a pretty decent tutorial if you want to dig deeper. If you want more, entire books have been written on the subject.
 
=== The Lingo ===
{|
!''Term''
!''Definition''
|-
|Directory
|A "Folder" in Windows or OS-X terms. A location where files or other directories are stored. The current directory is sometimes represented as `.` and the parent directory can be referenced as `..`
|-
|Shell
|The interface or environment under which you can run commands. There is a section below on shells
|-
|SSH
|Secure Shell. A protocol that encrypts data and can give access to another system, usually by a username and password
|-
|SCP
|Secure Copy. Copying to or from a remote system using part of SSH
|-
|-
! colspan="2" | Connection Settings
|path
|The list of directories which are searched when you type the name of a program. There is a section below on this
|-
|-
! Hostname
|ownership
| style="text-align:right" | beocat.cis.ksu.edu
|Every file and directory has an user and a group attached to it, called its owners. These affect permissions.
|-
|-
! Port
|permissions
| style="text-align:right" | 22
|The ability to read, write, and/or execute a file. Permissions are based on ownership
|-
|-
! Username
|switches
| style="text-align:right" | <tt>eID</tt>
|Modifiers to a command-line program, usually in the form of -(letter) or --``(word). Several examples are given below, such as the '-a' on the 'ls' command
|-
|-
! Password
|pipes and redirects
| style="text-align:right" | <tt>eID Password</tt>
|Changes the input (often called 'stdin') and/or output (often called stdout) to a program or a file
|}
|}
== Transferring Files ==
There are many ways to transfer files into and out of Beocat. We generally suggest a [[wikipedia:Secure Copy|SCP]] program, of which there are many.
* Windows
** [http://mobaxterm.mobatek.net/ MobaXterm] as mentioned above handles SCP/SFTP.
** [https://filezilla-project.org/ File-Zilla] is a cross-platform application to handle file transfers over many protocols.
* Macintosh
** OS-X has a built-in [https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/scp.1.html scp application] from the "Terminal" application. It can also be used from [http://www.iterm2.com/#/section/home iTerm2].
** [http://cyberduck.io/ CyberDuck] is a decent Graphical application that can handle file transfers over many protocols.
** [https://filezilla-project.org/ File-Zilla] is a cross-platform application to handle file transfers over many protocols.
* Linux
** Linux has a built-in [http://linux.die.net/man/1/scp scp application] that can be used from any [[wikipedia:Terminal emulator|Terminal emulator]].
** [https://filezilla-project.org/ File-Zilla] is a cross-platform application to handle file transfers over many protocols.
* Others
** There are others for many different platforms. Above are some of the ones that we have experience with.


{| class="wikitable"
=== Linux Command Line Cheat Sheet ===
|-
*TODO
! colspan="2" | Connection Settings
 
|-
=== Editing Text Files ===
! Hostname
If you're new to Linux, the editor you will probably want to use is 'nano'. It works much the same as 'Notepad' in Windows or 'textedit' on OS-X. Note that you cannot use your mouse to change position within the document as you can with your local computer. You must use the arrow keys, instead.
| style="text-align:right" | beocat.cis.ksu.edu
 
So, if I wanted to edit my .bashrc (as shown below), and I was already in my home directory (see above), I would type
nano .bashrc
 
While in nano, there is a list of actions you can take at the bottom of the screen. <Ctrl> is represented by a caret (`^`), so to exit (labeled as `^`X at the bottom of the screen), I would type <ctrl>-x. This action prompts you whether you want to save and exit (Y), lose changes and exit (N), or cancel and go back to editing (<ctrl>-c).
 
If you do a significant amount of text editing in Linux, you'll probably want to switch to a more powerful editor, such as vim. The usage of vim is beyond the scope of this document. It is not at all intuitive to the beginning user, but with a little practice it becomes a much faster way of editing text files. If you're interested in using vim, [http://www.openvim.com/tutorial.html|there is a nice tutorial here].
 
=== Shells ===
*TODO
=== Changing your PATH ===
Typically, you don't have to change your PATH, but it is useful to know what your PATH is and what it does. The PATH is the list of directories which are searched when you type the name of a program. Note that by default the current directory is NOT included in the path, so if you were wanting to run a program called My``Program in the current directory, you could NOT simply type 'My``Program', you would instead type './My``Program' (where the '.' represents the current directory).
 
To find your PATH, we need to identify which shell you are using. If you do not know, run the following:
ps | awk '/sh/ {print $4}'
 
==== tcsh ====
You'll need to edit a file in your home directory called .tcshrc, replacing /usr/local/bin with the directory that you want added to your PATH using a text editor as shown above.
setenv PATH /usr/local/bin:$PATH
 
==== bash ====
You'll need to edit a file in your home directory called .bashrc, replacing /usr/local/bin with the directory that you want added to your PATH using a text editor as shown above.
export PATH=/usr/local/bin:$PATH
 
==== zsh ====
You'll need to edit a file in your home directory called .zshrc, replacing /usr/local/bin with the directory that you want added to your PATH using a text editor as shown above.
export PATH="/usr/local/bin:$PATH"
 
=== Ownership and Permissions ===
Every file and directory has a user and group associated with it. You can view ownership information by using the '-l' switch on ls. By default on Beocat, files you create have a user ownership of your username (i.e., your eID) and a group ownership of your username_users. So, if I were logged in as 'myusername' and I had a single file in my home directory called My``Program, the result of typing 'ls -l' would be something like this:
total 0
-rwxr-x--- 1 myusername myusername_users 79 May 31  2011 MyProgram
This tells us several things.
* The first column ('-rwxr-x---') is permissions (covered below)
* The second column ('1') is the number of links to this file. You can safely ignore this (unless you're both masochistic and interested in filesystem details)
* The third column ('myusername') shows the user ownership
* The fourth column ('myusername_users') shows the group ownership
* The fifth column ('79') gives the size of the file in bytes
* The next columns ('May 31  2011'), as you have probably guessed, gives the date the file was last changed
* The final column ('MyProgram') is the name of the file
 
So why is this interesting to us? Because whenever things ''don't'' work, it's usually because of file ownership or permissions. Looking at these often gives us some useful diagnostic information.
 
The permissions field shows us who has permissions to do what with this file. It is always 10 characters. The first character (-) is usually either a '-' for a regular file or a 'd' for a directory. The next 9 characters are broken into three groups of three, with each group showing read (r), write (w), and execute (x) permissions for the owner, group, and world, in that order.
* The first group (rwx) shows permissions for the owner (myusername). The owner here has read, write, and execute permissions
* The next group (r-x) shows permissions for the group (myusername_users). The group here has read and execute permissions, but cannot write.
* The last group (---) shows permissions for the rest of the world. The world has no permissions to read, write, or execute.
 
When you create a shell script with a text editor, and sometimes when you copy programs to Beocat via SCP, the execute flag is not set. The permissions string may look more like (-rw-r--r--). To change this, you need to give yourself permission to execute this program. This is done with the 'chmod' (change mode) command. 'chmod' can have a long and confusing syntax, but since by far the most common problem is to give yourself execute permissions, here is the command to change that:
chmod u+x MyProgram
This changes the permissions so that the user ('u', i.e., the owner) adds ('+') execute permission ('x').
 
For more complex ownership or permissions changes, please feel free to contact the Beocat staff.
 
=== Manual (man) pages ===
Most commands have a complex set of switches that will modify the amount or type of information they display. To find out what switches are available, or how a program expects data, you can use the manual pages by typing "`man` ''command''". Using one of the most common Linux commands, take a look the output of 'man ls'. It shows that it has over 50 switches available, ranging from which files to include, to how to display file sizes, to sort order and more. (I'm not pasting it here, because it's over 200 lines long!) To navigate a 'manpage', use the up-arrow and down-arrow keys. Press 'q' to quit.
 
=== Pipes and Redirects ===
Typically a Linux program takes data from the keyboard and outputs data to the screen. In Unix and Linux terminology, the keyboard is the default 'stdin' (pronounced "standard in") and the screen is the default 'stdout' (pronounced "standard out"). Many times, we want to take data from somewhere else (like a file, or the output of another program) and send it to yet another location. These redirectors are:
{|
|cmd > filename
|Redirect output from cmd to filename ||
|-
|-
! Port
|cmd >> filename
| style="text-align:right" | 22
|Redirect output from cmd and append to filename
|-
|-
! Username
|cmd < filename
| style="text-align:right" | <tt>eID</tt>
|Redirect input from cmd to filename
|-
|-
! Password
| cmd1 &#124; cmd2
| style="text-align:right" | <tt>eID Password</tt>
| Use the output from cmd1 as the input to cmd2
|}
|}
== How to get help ==
Here is a quick example. Let's say I have a thousands of files in a directory, and I want a list of those that end in '.sh'
There are many sources of help for most Linux systems.
'ls' by itself scrolls so far I can't see even a fraction of them. So, I redirect the output to a file
=== Unix man pages ===
ls > ~/filelist.txt
Linux provides man pages (short for manual pages). These are simple enough to call, for example: if you need information on submitting jobs to Beocat, you can <tt>man qsub</tt>. This will bring up the manual for qsub.
That gives me all the files in the current folder and saves them in my home directory in 'filelist.txt'.
=== GNU info system ===
A quick look through the file in my favorite editor tells me this is still going to take too long, so I need another step. The 'grep' program is a commonly-used program to perform pattern matching. The syntax of 'grep' is beyond the scope of this document, but take my word for it that
Not all applications have "man pages." Most of the rest have what they call info pages. For example, if you needed information on finding a file you could use <tt>info find</tt>.
grep '\.sh$'
=== This documentation ===
will return all lines that end in .sh.
This documentation is very thoroughly researched, and has been painstakingly assembled for your benefit. Please use it.
 
=== Contact support ===
We can now redirect the input from grep to the file we just created:
Support can be contacted [mailto:beocat@cis.ksu.edu here.] Please include detailed information about your problem, including the job number, applications you are trying to run, and the current directory that you are in.
grep '\.sh$' < ~/filelist.txt
Great! We now have our list. However, we wanted to save this as filelist.txt, and instead we have another list that we have to copy-and-paste. Instead of redirecting to a file, we'll use the vertical bar '|' (which we often term a "pipe") to send the output of one command to another.
ls | grep '\.sh$' > ~/filelist.txt
This time the output of 'ls' is ''not'' redirected to a file, but is redirected to the next command (grep).  The output of grep (which is all our .sh files) instead of being sent to the screen is redirected to the file ~/filelist.txt.
 
This example is a very simple demonstration of how pipes and redirects work. Many more examples with complex structures can be found at http://www.ibm.com/developerworks/linux/library/l-lpic1-v3-103-4/index.html

Revision as of 13:56, 21 April 2014

Disclaimer: This is a very large topic, and much too broad to be covered on a single support page. There are many other sites (yes, entire sites) which cover the topic in more detail. We'll link so some of them below. This page is meant to be just the essentials.

Logging in for the first time

To login to Beocat, you first need an "SSH Client". SSH (short for "secure shell") is a protocol that allows secure communication between two computers. We recommend the following.

  • Windows
    • PuTTY is by far the most common SSH client, both for Beocat and in the world.
    • MobaXterm is a fairly new client with some nice features, such as being able to SCP/SFTP (see below), and running X (which isn't terribly useful on Beocat, but might be if you connect to other Linux hosts).
    • Cygwin is for those that would rather be running Linux but are stuck on Windows. It's purely a text interface.
  • Macintosh
    • OS-X has SSH a built-in application called "Terminal". It's not great, but it will work for most Beocat users.
    • iTerm2 is the terminal application we prefer.
  • Others
    • There are many SSH clients for many different platforms available. While we don't have experience with many of these, any should be sufficient for access to Beocat.

You'll need to connect your client (via the SSH protocol, if your client allows multiple protocols) to beocat.cis.ksu.edu.

For command-line tools, the command to connect is

ssh username@beocat.cis.ksu.edu

Your username is your K-State eID name and the password is your eID password.

Note: When you type your password, nothing shows up on the screen, not even asterisks.

You'll know you are successfully logged in when you see a prompt that says

(machinename:~) username%

where machinename is the name of the machine you've logged into (currently either 'athena' or 'minerva') and username is your eID username

Transferring files (SCP or SFTP)

Usually, one of the first things people want to do is to transfer files into or out of Beocat. To do so, you need to use SCP (secure copy) or SFTP (SSH FTP or Secure FTP). Again, there are multiple programs that do this.

  • Windows
    • Putty (see above) has PSCP and PSFTP programs (both are included if you run the installer). It is a command-line interface (CLI) rather than a graphical user interface (GUI).
    • MobaXterm (see above) has a built-in GUI SFTP client that automatically changes the directories as you change them in your SSH session.
    • FileZilla (client) has an easy-to-use GUI. Be sure to use 'SFTP' mode rather than 'FTP' mode.
    • WinSCP is another easy-to-use GUI.
    • Cygwin (see above) has CLI scp and sftp programs.
  • Macintosh
    • FileZilla is also available for OS-X.
    • Within terminal or iTerm, you can use the 'scp' or 'sftp' programs.
  • Linux
    • FileZilla also has a GUI linux version, in additon to the CLI tools.

Using a Command-Line Interface (CLI)

You can safely ignore this section if you're using a graphical interface (GUI). We highly recommend using a GUI when first learning how to use Beocat.

First test case: transfer a file called myfile.txt in your current folder to your home directory on Beocat. For these examples, I use bold text to show what you type and plain text to show Beocat's response

Using SCP:

scp myfile.txt username@beocat.cis.ksu.edu:
Password: (type your password here, it will not show any response on the screen)
myfile.txt                                                                            100%    0     0.0KB/s   00:00

Note the colon at the end of the 'scp' line.

Using SFTP

sftp username@beocat.cis.ksu.edu
Password: (type your password here, it will not show any response on the screen)
Connected to beocat.cis.ksu.edu.
sftp> put myfile.txt
Uploading myfile.txt to /homes/kylehutson/myfile.txt
myfile.txt                                                                            100%    0     0.0KB/s   00:00
sftp> exit

SFTP is interactive, so this is a two-step process. First, you connect to Beocat, then you transfer the file. As long as the system gives the sftp> prompt, you are in the sftp program, and you will remain there until you type 'exit'.

Second test case: transfer a file called myfile.txt in your current folder to a diretory named 'mydirectory' under your home directory on Beocat.

Here we run into one of the problems with scp - there is no easy way of creating 'mydirectory' if it doesn't already exist. If it does not already exist, you must login via ssh (as seen above) and create the directory using the 'mkdir' command (see Common Linux Commands) below.

scp myfile.txt username@beocat.cis.ksu.edu:mydirectory
Password: (type your password here, it will not show any response on the screen)
myfile.txt                                                                            100%    0     0.0KB/s   00:00

An alternative version. If the colon is immediately followed by a slash, the directory name is taken from the root, rather than your home directory. So, given that your home directory on Beocat is /homes/username, we could instead type

scp myfile.txt username@beocat.cis.ksu.edu:/homes/username/mydirectory
Password: (type your password here, it will not show any response on the screen)
myfile.txt                                                                            100%    0     0.0KB/s   00:00

Using SFTP:

sftp username@beocat.cis.ksu.edu
Password: (type your password here, it will not show any response on the screen)
Connected to beocat.cis.ksu.edu.
sftp> mkdir mydirectory
[Note, if this directory already exists, you will get the response "Couldn't create directory: Failure"]
sftp> cd mydirectory
sftp> put myfile.txt
Uploading myfile.txt to /homes/username/mydirectory/myfile.txt
myfile.txt                                                                            100%    0     0.0KB/s   00:00
sftp> quit

Third test case: copy myfile.txt from your home directory on Beocat to your current folder.

Using scp:

scp username@beocat.cis.ksu.edu:myfile.txt .
Password: (type your password here, it will not show any response on the screen)
myfile.txt                                                                            100%    0     0.0KB/s   00:00

Using SFTP:

sftp username@beocat.cis.ksu.edu
Password: (type your password here, it will not show any response on the screen)
Connected to beocat.cis.ksu.edu.
sftp> get myfile.txt
Fetching /homes/username/myfile.txt to myfile.txt
myfile.txt                                                                            100%    0     0.0KB/s   00:00
sftp> exit

Basic Linux Commands

Again, this guide is very limited, mostly limited to directory navigation and basic file commands. Here is a pretty decent tutorial if you want to dig deeper. If you want more, entire books have been written on the subject.

The Lingo

Term Definition
Directory A "Folder" in Windows or OS-X terms. A location where files or other directories are stored. The current directory is sometimes represented as `.` and the parent directory can be referenced as `..`
Shell The interface or environment under which you can run commands. There is a section below on shells
SSH Secure Shell. A protocol that encrypts data and can give access to another system, usually by a username and password
SCP Secure Copy. Copying to or from a remote system using part of SSH
path The list of directories which are searched when you type the name of a program. There is a section below on this
ownership Every file and directory has an user and a group attached to it, called its owners. These affect permissions.
permissions The ability to read, write, and/or execute a file. Permissions are based on ownership
switches Modifiers to a command-line program, usually in the form of -(letter) or --``(word). Several examples are given below, such as the '-a' on the 'ls' command
pipes and redirects Changes the input (often called 'stdin') and/or output (often called stdout) to a program or a file

Linux Command Line Cheat Sheet

  • TODO

Editing Text Files

If you're new to Linux, the editor you will probably want to use is 'nano'. It works much the same as 'Notepad' in Windows or 'textedit' on OS-X. Note that you cannot use your mouse to change position within the document as you can with your local computer. You must use the arrow keys, instead.

So, if I wanted to edit my .bashrc (as shown below), and I was already in my home directory (see above), I would type

nano .bashrc

While in nano, there is a list of actions you can take at the bottom of the screen. <Ctrl> is represented by a caret (`^`), so to exit (labeled as `^`X at the bottom of the screen), I would type <ctrl>-x. This action prompts you whether you want to save and exit (Y), lose changes and exit (N), or cancel and go back to editing (<ctrl>-c).

If you do a significant amount of text editing in Linux, you'll probably want to switch to a more powerful editor, such as vim. The usage of vim is beyond the scope of this document. It is not at all intuitive to the beginning user, but with a little practice it becomes a much faster way of editing text files. If you're interested in using vim, is a nice tutorial here.

Shells

  • TODO

Changing your PATH

Typically, you don't have to change your PATH, but it is useful to know what your PATH is and what it does. The PATH is the list of directories which are searched when you type the name of a program. Note that by default the current directory is NOT included in the path, so if you were wanting to run a program called My``Program in the current directory, you could NOT simply type 'My``Program', you would instead type './My``Program' (where the '.' represents the current directory).

To find your PATH, we need to identify which shell you are using. If you do not know, run the following:

ps | awk '/sh/ {print $4}'

tcsh

You'll need to edit a file in your home directory called .tcshrc, replacing /usr/local/bin with the directory that you want added to your PATH using a text editor as shown above.

setenv PATH /usr/local/bin:$PATH

bash

You'll need to edit a file in your home directory called .bashrc, replacing /usr/local/bin with the directory that you want added to your PATH using a text editor as shown above.

export PATH=/usr/local/bin:$PATH

zsh

You'll need to edit a file in your home directory called .zshrc, replacing /usr/local/bin with the directory that you want added to your PATH using a text editor as shown above.

export PATH="/usr/local/bin:$PATH"

Ownership and Permissions

Every file and directory has a user and group associated with it. You can view ownership information by using the '-l' switch on ls. By default on Beocat, files you create have a user ownership of your username (i.e., your eID) and a group ownership of your username_users. So, if I were logged in as 'myusername' and I had a single file in my home directory called My``Program, the result of typing 'ls -l' would be something like this:

total 0
-rwxr-x--- 1 myusername myusername_users 79 May 31  2011 MyProgram

This tells us several things.

  • The first column ('-rwxr-x---') is permissions (covered below)
  • The second column ('1') is the number of links to this file. You can safely ignore this (unless you're both masochistic and interested in filesystem details)
  • The third column ('myusername') shows the user ownership
  • The fourth column ('myusername_users') shows the group ownership
  • The fifth column ('79') gives the size of the file in bytes
  • The next columns ('May 31 2011'), as you have probably guessed, gives the date the file was last changed
  • The final column ('MyProgram') is the name of the file

So why is this interesting to us? Because whenever things don't work, it's usually because of file ownership or permissions. Looking at these often gives us some useful diagnostic information.

The permissions field shows us who has permissions to do what with this file. It is always 10 characters. The first character (-) is usually either a '-' for a regular file or a 'd' for a directory. The next 9 characters are broken into three groups of three, with each group showing read (r), write (w), and execute (x) permissions for the owner, group, and world, in that order.

  • The first group (rwx) shows permissions for the owner (myusername). The owner here has read, write, and execute permissions
  • The next group (r-x) shows permissions for the group (myusername_users). The group here has read and execute permissions, but cannot write.
  • The last group (---) shows permissions for the rest of the world. The world has no permissions to read, write, or execute.

When you create a shell script with a text editor, and sometimes when you copy programs to Beocat via SCP, the execute flag is not set. The permissions string may look more like (-rw-r--r--). To change this, you need to give yourself permission to execute this program. This is done with the 'chmod' (change mode) command. 'chmod' can have a long and confusing syntax, but since by far the most common problem is to give yourself execute permissions, here is the command to change that:

chmod u+x MyProgram

This changes the permissions so that the user ('u', i.e., the owner) adds ('+') execute permission ('x').

For more complex ownership or permissions changes, please feel free to contact the Beocat staff.

Manual (man) pages

Most commands have a complex set of switches that will modify the amount or type of information they display. To find out what switches are available, or how a program expects data, you can use the manual pages by typing "`man` command". Using one of the most common Linux commands, take a look the output of 'man ls'. It shows that it has over 50 switches available, ranging from which files to include, to how to display file sizes, to sort order and more. (I'm not pasting it here, because it's over 200 lines long!) To navigate a 'manpage', use the up-arrow and down-arrow keys. Press 'q' to quit.

Pipes and Redirects

Typically a Linux program takes data from the keyboard and outputs data to the screen. In Unix and Linux terminology, the keyboard is the default 'stdin' (pronounced "standard in") and the screen is the default 'stdout' (pronounced "standard out"). Many times, we want to take data from somewhere else (like a file, or the output of another program) and send it to yet another location. These redirectors are:

cmd > filename Redirect output from cmd to filename
cmd >> filename Redirect output from cmd and append to filename
cmd < filename Redirect input from cmd to filename
cmd1 | cmd2 Use the output from cmd1 as the input to cmd2

Here is a quick example. Let's say I have a thousands of files in a directory, and I want a list of those that end in '.sh' 'ls' by itself scrolls so far I can't see even a fraction of them. So, I redirect the output to a file

ls > ~/filelist.txt

That gives me all the files in the current folder and saves them in my home directory in 'filelist.txt'. A quick look through the file in my favorite editor tells me this is still going to take too long, so I need another step. The 'grep' program is a commonly-used program to perform pattern matching. The syntax of 'grep' is beyond the scope of this document, but take my word for it that

grep '\.sh$'

will return all lines that end in .sh.

We can now redirect the input from grep to the file we just created:

grep '\.sh$' < ~/filelist.txt

Great! We now have our list. However, we wanted to save this as filelist.txt, and instead we have another list that we have to copy-and-paste. Instead of redirecting to a file, we'll use the vertical bar '|' (which we often term a "pipe") to send the output of one command to another.

ls | grep '\.sh$' > ~/filelist.txt

This time the output of 'ls' is not redirected to a file, but is redirected to the next command (grep). The output of grep (which is all our .sh files) instead of being sent to the screen is redirected to the file ~/filelist.txt.

This example is a very simple demonstration of how pipes and redirects work. Many more examples with complex structures can be found at http://www.ibm.com/developerworks/linux/library/l-lpic1-v3-103-4/index.html