An Introduction to Computing at MSI
Total Page:16
File Type:pdf, Size:1020Kb
An Introduction to Computing at MSI University of Minnesota Supercomputing Institute for Advanced Computational Research June 8, 2010 1 Contents 1 Setting up your account 3 2 UNIX Tutorial 3 2.1 Basic Commands, Paths and Directories . 3 2.1.1 Basic Commands . 3 2.1.2 Paths . 5 2.2 Files . 6 2.2.1 Copying, moving, removing, and renaming . 6 2.2.2 Displaying and searching . 6 2.2.3 Permissions . 6 2.3 Redirection and Pipes . 7 2.3.1 Input and Output Redirection . 7 2.3.2 Pipes . 8 2.4 Regular Expressions . 8 2.5 MSI Software . 9 2.6 Writing and Compiling Code . 10 3 Remote Computing and other FAQs 11 3.1 Access an MSI *nix machine from a Windows machine. 11 3.2 Access an MSI *nix machine from another *nix machine . 11 3.3 Access an MSI *nix machine from a Mac . 11 3.4 Access an MSI Windows server . 11 3.5 Upload files from to MSI computers . 12 3.6 Resetting your password . 12 3.7 Check the status of machine or resource . 12 3.8 Getting help . 12 2 This document contains command blocks, the monospaced typewriter fonts within a bounding box. They are an indication that the commands should be typed directly into the shell, or are the resulting screen output of such commands. The \#" char- acter represents a comment. If typed into the console or included in a script they are ignored by the shell. When commands are included inline they are presented in a bold font. 1 Setting up your account 1. Information pertaining to getting an account, access to laboratories, and/or su- percomputer resource allocations can be found at http://www.msi.umn.edu/ help/resource.html. If you do not have an MSI account you may request a temporary account from one of the instructors. 2. Type your username and password into the prompt. 3. Open a Unix terminal by right clicking the desktop and selecting \open new terminal." 4. Type passwd at the terminal prompt and follow the instructions to change your password. 5. Open your favorite text editor and create a .forward file in your home directory. If you do not have a favorite text editor use nedit or gedit. These text editors function similarly to Notepad on Microsoft Windows. cd nedit .forward Your mail will now be forwarded to the address you entered. 2 UNIX Tutorial 2.1 Basic Commands, Paths and Directories 2.1.1 Basic Commands • Open a shell. The exact procedure varies from machine to machine depending on the version and revision of the operating system running, but is usually 3 available by right clicking in the open desktop area and selecting an option such as \New Terminal." • Try a few commands out. Some basics are pwd (list the full path of your current location), ls (list the contents of the directory), date (print the current date and time), and whoami (prints your username). pwd /home/msi/nlabello date Fri Oct 31 11:39:14 CDT 2008 whoami nlabello Listing 1: A few basic commands. • Most commands can be customized by passing options, and these options and general instructions for using the command are included in a built in manual, known as the man page. Examine the man page for the commands above by entering man pwd, for example. Exit the man page by entering \:q" into the terminal. • Create the directory structure demonstrated in Figure 1. mkdir will create a new directory. cd will allow you to change into a directory. rmdir will remove an empty directory. Figure 1: An example directory structure. The tilda represents your home directory. • From your home directory use the ls command. Pass ls a few options to customize its behavior. cd # changes directly to your home dir ls # plain old listing of files ls -l # a "long" listing of the files ls -a # also list "hidden" files. # Any file can be hidden by starting # the file name with a "." ls -lrth # listing of files reverse sorted by # date of last modification Listing 2: ls 4 • Write a script to automate a few commands. Open a text editor and include create a file with contents similar to the box below. Save the file as \myscript." It is not necessary to include the comments in your script. #/ bin / bash # Tell the operating system this is a bash script. # The first line includes a '#' but IS NOT a comment. echo "This script will report the date and run a few" echo "simple commands." # Back ticks, (the key under ESC), # allow nested commands. # The output of the nested command is # included in the parent command. # For example, date # This way works fine. # But this way is fancier. echo "Script run time is `date`." # list files in the directory # direct the output to a new file ls -lrth > current_file_listing.txt Listing 3: A simple bash script. • Run the script as follows: ./myscript # That didn't work! OK, let's try chmod +x myscript ./myscript # It works now! Listing 4: Running a script. 2.1.2 Paths The UNIX environment supports explicit as well as relative paths. Explicit paths spell out the exact location on the file system. Relative paths use symbols to describe the location relative to the current working directory. ls . # indicates the current working directory ls .. # references the parent directory ls ~ # references your home directory cp ~/file1 . # copies a file1 from your home directory to your # present working directory cp ../file1 . # copies file1 from the directory above to your # present working directory 5 pwd # prints the present working directory Listing 5: Path examples. 2.2 Files 2.2.1 Copying, moving, removing, and renaming Files are copied using cp command. Directories are copied by passing the -r option. Files are removed with rm command, and directories are likewise removed with rm -r. Files and directories are moved and renamed with the mv command. Move, copy, rename, and remove the sample directories and files you have created until you are comfortable manipulating the file system. cp file1 file2 # copy file1 to file2 in the same directory cp file1 .. # copy file1 to the directory one up in the file hierarchy mv file1 supercool # rename file1 to supercool cp -r directory1 directory2 # make a copy of directory1 and all of its # contents in directory2 rm -r directory1 file1 file2 # remove the directory and files Listing 6: Moving, copying, and renaming files. 2.2.2 Displaying and searching Files can be read with the less command. Files can be searched with grep. head will display the first N lines of a file and tail will display the last N lines. cat dumps the entire file to the screen. less file1 # display file1 inareader tail file1 # print the last 10 lines of file1 to the screen tail -n 5 file1 # print the last 5 lines of file1 to the screen tail -n 100 file1 # print the last 100 lines of file1 to the screen head file1 # print the first 10 lines of file1 to the screen head -n 5 file1 # print the first 5 lines of file1 to the screen cat file1 # print allof file1 tothe screen grep "SCF ENERGY" file1 # print all lines in the file that contain "SCF ENERGY" Listing 7: Displaying and searching files. 2.2.3 Permissions Why was the chmod +x step necessary in the previous section? Every item in the UNIX file system is described by three sets of permissions. 6 1. Owner Permissions 2. Group Permissions 3. Other Permissions The permissions for a set may include read, write, or executable privileges, or any combination. By default the file we created did not have executable permission enabled for its owner (you). We added the appropriate permission, execution rights, with the chmod +x command. Consider the following examples. ls -lrth drwx------ 4 nlabello support 4.0K 2008-10-09 13:22 sandbox -rw------- 1 nlabello support 128 2008-10-31 13:07 forme.txt -rwxrwxrwx 1 nlabello support 132 2008-10-31 13:07 foreveryone.txt Listing 8: File permissions. The sandbox file is a directory, indicated by a d in the first column. The directory is readable, writeable/changeable, and executable by its owner. Note "exe- cutable" has a different meaning for directories than for files. Executable permission is required in addition to read permissions to access a directory. • Apply the following command to a file: chmod 755 file. Examine the permis- sions with ls -l. What did you do? The three numbers (7, 5, and 5) indicate permissions for the three sets described above - owner, group, and other. Read permissions have a value of 4, write permissions a value of 2, and executable permissions a value of 1 (r = 4, w = 2, x = 1). The sum of all three is 7, the highest access someone can have to a file. You gave the file owner all permis- sions (7), and anyone else only w and x access (5). While the other users who share your computer can read and/or run your scripts and code they will not be able to write or change the files in your directory. 2.3 Redirection and Pipes 2.3.1 Input and Output Redirection Input and output can be redirected away from the screen and into other commands. For example, cat as used thus far prints the contents of a file to the screen. The output from cat can be redirected. Input redirection is used more rarely, but some programs do not take command line arguments and instead require that you feed the data with redirects.