Linux/Unix Tutorial

Document Sample
Linux/Unix Tutorial Powered By Docstoc
					Linux/Unix Tutorial
2008
This document in intended to introduce students to the Linux/Unix operating system used on computers in the Department of Statistical Science at Duke University. If you need help with computing you can always ask other students, faculty, or send an email to help@stat.duke.edu.

1

Setting Up Your Account

Prior to your arrival, the systems administrator will have assigned you a username and password. You will need to obtain these before you can log on to the department system by visiting room 220 Old Chemistry or sending an email to Lance Brown at help@stat.duke.edu. Once you have obtained these, use them to log into the system. Linux and Unix environments work primarily from the command shell window. While it is possible to set up your Linux environment to work similar to windows or Mac OS X, the majority of your work will be done through the command line in the command shell window. To open a command shell, click the K Menu icon in the bottom left hand corner of the screen, select system, then Terminal. Once you have opened a command shell, you should see “[USERNAME@compname ∼]$” and your cursor which means Linux is waiting for you to give it a command. As you will be using the command shell a lot, it would be a smart idea to create a quick link from your desktop to the command shell by dragging the icon to your desktop. The first thing you need to do once you have logged in is to change your password from the one assigned to you by the Systems Administrator to one of your choosing. In the command shell window type kpasswd and follow the instructions on your screen. You will now use this password to log on to all department machines. Note that is password is used to log on to all department machines. If you are using a computer in the library, for example, you would use your NetID and password to log on. To logout, first type exit in your command shell, click the K menu icon in the lower left corner of your screen, select logout.

2

Commonly Used Commands

Almost everything you will need to do can be done from the terminal (shell) window. For example, from the terminal window you can create directories, run programs, compile programs, open an internet browser, open a text editor, etc. This section provides a list of some of the most commonly used commands in the Linux environment along with the syntax required for their use. If you forget the exact syntax for any of these commands, you can type man commandname to open the Linux help menu for commandname. For example, man lpr will open then help menu for the command lpr. To exit the help menu, type q. 1. firefox - opens a firefox web browser. 2. mozilla - opens a mozilla web browser. 3. R - opens R. 4. matlab - opens MATLAB. 1

5. acroread filename - opens filename in Adobe acrobat. 6. gv filename - opens filename in ghostview. 7. xdvi filename - previews a device independent (dvi) file. 8. pwd - prints your current working directory. 9. mkdir directoryname - creates a directory with name directoryname. 10. cd directorypath - changes the current working directory. For example, if you are in “./home/” and you want to change directories to “./home/school/” type cd school. 11. emacs filename - open the file filename in emacs (this will create the file if it doesn’t yet exist). 12. rm filename - removes the file filename. 13. rmdir directory - removes an empty directory. If there are files in the directory, this command will return and error. 14. rm -r director - removes a directory AND all files in the directory. 15. ls -a - lists all (that is what the “a” stands for) files in the current working directory. 16. ls -la - outputs a detailed list of all files in the directory. 17. chmod -rwx filename - changes the permission of filename. For example, chmod +rwx thesis.tex will allow anyone to read, write, and delete your thesis file (if they want to). 18. date - displays the current date and time. 19. up and down arrows - scrolls through previous commands you typed, this can be very handy so you don’t have to retype everything. Notice that typing a command such as acroread mydocument.pdf will open Adobe reader and occupy the command shell. Often you will want to run the program independently of the command shell so you can still use the command shell while having a Internet browser open, for example. To do this, add the “&” sign to the end of the command. For example, the command acroread mydocument.pdf & will open mydocument.pdf in Adobe reader while allowing you to still use the command shell.

3

Printing

Several printers are available for student use. You are asked to please use the department resources wisely by not wasting paper, ink, or printing excessively. To print a document, first change your default printer to the printer in your office by opening the file .cshrc by typing: emacs .cshrc in the terminal window. Look for the section of the document that looks like: #setenv #setenv #setenv #setenv #setenv PRINTER PRINTER PRINTER PRINTER PRINTER mono112 mono211 mono214 mono222 mono223

2

and delete the “#” symbo on the line which matches the printer in your office. A list of printer names and locations can be found at http://stat.duke.edu/comp/printing.html. To print, type: lpr filename and the file will print to your default printer. If you type: lpr -P printer filename then the document will print to the printer specified by printer. If you want to print from a personal laptop, you will need to send an email to help@stat.duke.edu and ask before you can set it up. More detail about printing can be found at http://stat.duke.edu/comp/ printing.html.

4

The top Environment and Running Processes

Anytime you tell the terminal window to run a program you are telling it to run a process. If the process you are going to be running is going to take a long time (a few hours, days, or even weeks) then you MUST nice your process. “Nicing” a process, intuitively means to run the program at a lower priority so if someone is on the computer then you won’t make their computer run too slowly. The levels of nice run from 0 (not nice) to 20 (very nice). Before beginning a process, it is a good habit to see what is already running on your computer. To see what programs are running on your computer, type top into the terminal window. This will list all the process id’s (pid), users (the person running the process), the nice level, and how long it has been running. If you want to kill one of these processes to free up space so you can run your process faster, type k pid where pid is the process id listed in the top environment. Now that you have checked to see what is running on your computer, you are ready to run your process. To illustrate how to nice a process consider the following example. Say you have a program, metropolis.C which is going to take a LONG time to run. You don’t want to slow your (or anyone else’s) computer down so you should nice the process. Typing: nice -n 10 ./metropolis will run the metropolis program at a priority level of 10. Say, now, that you forgot to nice your process but don’t want to stop the program to reset the nice level. You should use the renice command. Continuing with the above example, the command renice 15 -p pid will renice the process specified by pid to level 15 where pid is the process id listed in the top environment. You can also use the top environment to renice processes. To do this, in the top environment type: r10 pid which will renice pid to level 10 (or whatever number you put there). If you notice that your computer is running slowly, go to the top enviroment to see if anyone is running something on your computer. If they are and you want them to nice it to a higher level, write them an email. DO NOT KILL ANYONE ELSE’S PROCESS!

5

Accessing Departmental Desktops

You can access any desktop in the department from any other desktop using ssh - which stands for secure shell. By typing: 3

ssh computername@stat.duke.edu into your terminal window. You will then be logged in to the desktop computername just as if you were sitting at that computer. A list of computer names, the computers primary user, room number, and computer specificiations can be found on the statistics computing website. To exit your login to another computer type exit. Any student is allowed to use up to three computers for running processes at a given time. If you need more computers than this you should ask for permission before using more than 3.

5.1

Accessing Department Computers from a Remote Computer

You can access department computers from non-department computers using ssh (if you have a Linux shell) or you can set up virtual network computing (VNC). If you want to use ssh, then from the terminal window of the computer you are using, type: ssh USERNAME@computername.stat.duke.edu enter your password and you are logged in. The terminal window on your computer will act just like the terminal window on the computer you just logged in to. A more flexible way to access department computers from a remote computer is to set up a virtual computing network. In computing, Virtual Network Computing (VNC) is a graphical desktop sharing system which remotely controls another computer. It transmits the keyboard and mouse events from one computer to another, relaying the graphical screen updates back in the other direction, over a network. In order to use VNC, you need to set up a VNC server first, which can be viewed as a background desktop on your computer. Then you need to use the VNC client to access this remote desktop. A few benefits of using VNC include: you get a graphical interface, if you set up the resolution correctly, and use the full screen mode, you feel like you are just working on the remote computer; when you close your VNC window, or you lose your internet signal, your work will still be there, and the next time you connect with you VNC window, all the opened sessions and programs are exactly the same as you left last time.

5.2

Setting up a VNC

The following instructions will work in setting up a VNC but a separate set of instructions provided by Lance can be found at http://wiki.stat.duke.edu/SecureVNC. VNC servers are installed by default on the department computers, however, you need to set up a profile and start up your server session manually. In your home directory, create a directory called .vnc by typing: makedir .vnc Next, create a shell script file named xstartup.sh in the .vnc directory by typing emacs xstartup.sh & . which will create the file and open it in emacs. Copy the following code to xstartup.sh: #!/bin/sh [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup ˙ ˙ [ −r $HOME/Xresources ] && xrdb $HOME/Xresources xsetroot -solid grey exec startkde save and quit. Next, make the file xstartup.sh an executable file by typing: chmod +x xstartup.sh then create an active VNC session by typing: 4

vncserver -geometry 1024x768 -depth 24 in the terminal window. You can set up the resolution by the geometry argument, and the depth of the color by the depth argument. If you expect slow internet connect at your remote computer, use a small value of depth, such as 8. If it is the first time to set up the VNC session, it will prompt you for a password. It could be different than your computer password, and it is used to access the VNC desktop remotely. You may need to type it twice to confirm the password. If you want to change the password in the future, delete the file passwd in the .vnc directory, and re-start the VNC session using the same command above. Notice that you should see a PID associated with the session, which is typically 1, unless there are already active VNC sessions on the computer. You can set up multiple VNC desktop sessions on one computer, but you need to keep track of those PID numbers. To kill an active VNC session, type vncserver -kill :1 in the terminal window and the command should look for computername.isds.duke.edu:1.pid in .vnc directory, and obtain the program ID, then kill it. Of course, if you have multiple sessions, change 1 to the corresponding session id you would like to kill. To see the session id, use the ls command within the .vnc directory. After you have an active VNC session on the department desktop, you are ready to access the computer remotely. There are two main ways to access the remote desktops. One is to use a VNC client software, and the other is to use web-browser. You need to enable JAVA for your web-browser, but it is not enabled by default on the departmental computers. The VNC viewing software vncviewer is installed by default on the departmental computers. To access your VNC desktop from a department computer, just run vncviewer :1 if the computer you are using is exactly the one you set up the VNC session. Otherwise, run vncviewer computername.stat.duke.edu:1 and a window will pop up and ask for your VNC password. After that, you are good to go. If you want to access your VNC desktop from a computer in which you don’t want to install anything (like library computers for example), then type the following address in a web browser (such as firefox): http://computername.stat.duke.edu:5801 Notice that the port number begins with 58. If the VNC session you have set up on the department computers is not 01 then change the last two digits accordingly. The web browser will have the basic functions, but you won’t be able to run it in full screen mode, for example. If you have a personal computer or laptop and you want to access the department computers from your laptop then it is better to use a dedicated VNC viewer software. There are couple of open-sourced softwares, for example, tightvnc is available for both linux and windows users at http://www.tightvnc.com/. If you are a Mac user, then download and install Chicken of the VNC at http://sourceforge.net/projects/ cotvnc/. You only need to download the viewer software, not the server part.

5


				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:59
posted:10/2/2009
language:English
pages:5
Description: Linux/Unix Tutorial