User Tools

Site Tools


playground:playground

This is an old revision of the document!


Linux Tutorial

This tutorial is intended to be a practical and brisk tutorial of many of the basics of using Linux for people who have never used it before. Setting up a website, compiling LaTeX, firing up MatLAB, and other typical tasks math grads would want from the department computers are covered quickly.

By using the related tools mentioned here, you can do things such as modify your webpage, retrieve/send files, turn LaTeX files into PDFs, and all other tasks you can do on the department computers from where ever you have internet access!

Connecting to a Linux computer

If you are using one of the Ubuntu computers in the computer lab or in your office, there is nothing special you have to do. Just open the “terminal” application and you are ready to start typing unix commands.

If you are on your own computer, you first need to connect to the math's computers. Just as you need a web browser (like Firefox) to connect to a web server (like www.gmail.com), you need an SSH client to connect to an SSH server. To connect, you need your username, password, and a SSH client.

Some good SSH clients include

  • Windows: PuTTY
  • Mac: See the Mac program “Terminal”. Then type “ssh username@math-server” and hit enter.

For details on how to connect to a math server, see the computer FAQ here and here and here.

The Basics

The first thing you should do is watch this youtube video that covers the core set of unix commands that a Linux user would use almost every day. Then search online/youtube for “basic unix commands” and work through the examples. An important set of basic unix commands you should look up include

  • ls (for listing a directory)
  • pwd (printing current path)
  • cd (for moving around in folders)
  • mkdir (making folders)
  • mv (moving things)
  • rm (removing things)
  • cp (copy things)

<p><h3>How this tutorial is organized</h3>

Just as you need a web browser (like Firefox) to connect to a web server (like www.gmail.com), you need an SSH client to connect to an SSH server. To connect, you need your username (in the examples we use <span class=“codeview”>egalois</span>), your password, and the name of the SSH server you wish to connect to (such as <span class=“codeview”>point.math.ucdavis.edu</span> or <span class=“codeview”>line.math.ucdavis.edu</span>).</p> <p>For <b>Windows</b>, download <a href=“http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html”>PuTTY</a>, a free SSH client. On the opening window, you only type your username the SSH server name. You enter the password after clicking to connect. (NOTE: As of Spring 2007, several PuTTY users have reported trouble in trying to SSH to <span class=“codeview”>math.ucdavis.edu</span>. After entering your username and password, PuTTY disappears. Try logging in to a specific server such as <span class=“codeview”>round.math.ucdavis.edu</span> instead of <span class=“codeview”>math.ucdavis.edu</span>.)</p> <p>For <b>Mac</b>, an SSH client is provided. Start the Mac program “Terminal” and type <span class=“codetype”>ssh <span class=“nospam1”>&#101galois<!– foobar –></span>&#64;<span class=“nospam2”>point.math.ucdavi&#115;&#46;edu</span></span>, then press Enter. Then the Mac asks you for your password.</p> <p><hr></p> <p><a name=“afterconnecting”></a><h2>2. After you're connected: Some basics</h2> Once you successfully connect, you are given a prompt where you can type commands. This section is devoted to introducing everyday commands. In what follows, when in doubt, Linux is typically case-sensitive!</p> <p><h3>The folder system and your home directory</h3> Like on your own computer, Linux has a folder (sometimes called a directory) structure. Any folder can contain any number of files. A folder can also have any number of folders called subfolders (and these folders can in turn have the same kind of content). When you log in, you are brought to your what is called your “home directory”. Your home directory is a subfolder of some other folder (called its parent directory).</p> <p>Some special directories have special symbols. The current directory is given the symbol <span class=“code”>.</span>, the parent directory of the current directory is given the symbol <span class=“code”>..</span>, and your home directory is given the tilde symbol <span class=“code”>~</span>.</p> <p><h3>Navigating directories</h3> To see what directory you're in at a given moment, you can type <span class=“codetype”>pwd</span> and press Enter. This tells you your “present working directory”. You can see a listing of the contents in the present directory by typing the command <span class=“codetype”>ls</span> and pressing Enter. (You might have colors set up automatically, in which case folders in the listing are shown in blue.)</p> <p>To move to a different directory, use the command <span class=“codetype”>cd</span> with an additional parameter. For example, to go to the parent directory of the current directory, type <span class=“codetype”>cd ..</span> and press Enter. You can try this again and again to get all the way to the top-level directory, the unique directory with no parent. All along the way, you can check where you are with the command <span class=“codetype”>pwd</span>.</p> <p>To get back to your home directory, use <span class=“codetype”>cd ~</span> or the shortcut <span class=“codetype”>cd</span>.</p> <p><h3>Creating, deleting, moving, and renaming directories</h3></p> <p>In your home directory, suppose you want to create a subdirectory (to store, for example, the scratch work of the rest of this tutorial). If you wish to make a directory called <span class=“codeview”>learnlinux</span> in the current directory, type <span class=“codetype”>mkdir learnlinux</span>. Now you can use <span class=“codetype”>cd learnlinux</span> to get into it and <span class=“codetype”>cd ..</span> to get back.</p> <p>To delete the directory <span class=“codeview”>learnlinux</span>, type <span class=“codetype”>rmdir learnlinux</span>. As a safety feature, <span class=“codetype”>rmdir learnlinux</span> only works if the folder you wish to delete has nothing in it.</p> <p>Now try creating two folders, one called <span class=“codeview”>test1</span> and one called <span class=“codeview”>test2</span>. You can move <span class=“codeview”>test1</span> into <span class=“codeview”>test2</span> by typing <span class=“codetype”>mv test1 test2</span>. Now, <span class=“codeview”>test1</span> is a subfolder of <span class=“codeview”>test2</span>. You can rename <span class=“codeview”>test2</span> to <span class=“codeview”>test3</span> by typing <span class=“codetype”>mv test2 test3</span>.</p> <p><h3>Creating, deleting, moving, and renaming files</h3> To create a blank file called <span class=“codeview”>myfile.txt</span> in the current directory, type <span class=“codetype”>touch myfile.txt</span>. Similarly, to create a blank text file called <span class=“codeview”>mytheorem.tex</span>, you'd type <span class=“codetype”>touch mytheorem.tex</span>. You can move this file into the folder <span class=“codeview”>test3</span> by typing <span class=“codetype”>mv myfile.txt test3</span>.</p> <p>If you've followed along exactly, the folder <span class=“codeview”>test3</span> should have in it one folder and one file. Change into <span class=“codeview”>test3</span>. To rename the text file, type <span class=“codetype”>mv myfile.txt renamed-file.txt</span>. To delete the file that is now called <span class=“codeview”>renamed-file.txt</span>, type <span class=“codetype”>rm renamed-file.txt</span>.</p> <p><h3>Editing text files directly</h3></p> <p>You have two basic ways of modify files. One option is to use the tools mentioned in the section “Transferring Files”. This is good for when you want to make large changes and prefer the interface of your own computer, or you know that you won't have access to the internet (and thus SSH) for a while. You copy over the files you plan to modify, do the changes on your own computer, and then replace the files on the SSH server with your updated ones.</p> <p>Your other basic way to modify files is directly using a text-based text editor. This makes sense for quick and minor edits. It also may help you keep your files in order, because you only have one version of a file floating around.</p> <p>The three most-popular text editors on Linux are called “pico”, “vi”, and “emacs”. You just have to pick one and stick with it. Here, we mention the basics of pico, because it is by far the easiest of the three. Later, you may want to try vi and/or emacs because they are much more powerful (though much more difficult to use). You may find that you like “gedit”, the graphical text-editor. This is nice to use in the department, and there is a way to use it via SSH (see the section on X Windows), but it may run slowly over a slow Internet connection, and for this reason alone, it may be useful to learn how to open, edit, and save a file in pico.</p> <p>To edit a file in the present directory called <span class=“codeview”>myfile.txt</span> with pico, type <span class=“codetype”>pico myfile.txt</span>. Even if no file by the name <span class=“codetype”>myfile.txt</span> exists in the current directory, this will work. In other words, you do not have to first run <span class=“codetype”>touch myfile.txt</span>, though you can if you want.</p> <p>The text editor pico starts and shows you the contents of the file, with some cheat info at the bottom. You can use the arrow keys to move around the cursor and start typing. In pico, saving is called “WriteOut”, so to save, the cheat tells us to hit Control and “O”. To quit, use Control and “X”.</p> <p>You can see the contents of a file without the hassle of running pico. To see all of the text in <span class=“codeview”>myfile.txt</span> run <span class=“codetype”>cat myfile.txt</span>. You might see too much stuff run by because there are too many lines in the file. If the scroll bar doesn't work (these things are sometimes buggy), you can run <span class=“codetype”>more myfile.txt</span>, which will show you a page at a time (scroll along by hitting the space bar).</p> <p><h3>Using LaTeX</h3></p> <p>Suppose you have a valid LaTeX file called <span class=“codeview”>mytheorem.tex</span> in the present working directory. To make a PDF, you can run <span class=“codetype”>pdflatex mytheorem.tex</span>. If you want to make a PostScript file instead, run <span class=“codetype”>latex mytheorem.tex</span> to make a DVI file and then run <span class=“codetype”>dvips mytheorem.dvi mytheorem.ps</span> to convert the DVI into a PS file.</p> <p>If your LaTeX file is invalid, you will not reach the normal prompt and instead be given a question mark. You can type a capital

X

to quit. After fixing your file using pico, emacs, vi, or re-uploading your file using the method described in “Transferring Files”, you can try to recompile.</p> <p><h3>A word on file permissions</h3> Type <span class=“codetype”>ls -l</span> to see all the files in the present directory along with their permissions. To fill in later…</p> <p><h3>Setting up a webpage</h3> To setup a website with the main address <span class=“code”><a href=“http://www.math.ucdavis.edu/~egalois”>http://www.math.ucdavis.edu/~egalois</a></span>, create a subfolder in your home directory called <span class=“codeview”>public_html</span> (note, that is an underscore character). In the folder <span class=“codeview”>public_html</span>, you can create a file called <span class=“codeview”>index.html</span> and edit it using pico or any other text editor. For the content, follow along in the HTML/Webpage tutorial.</p> <p>Note: You will need to make sure that <span class=“codeview”>public_html</span> and all its subdirectories are world-executable and all files are world-readable (or else visitors to your website will see a “403 Forbidden” error). See the previous section on file permissions.</p> <p><hr></p> <p><a name=“transferring”></a><h2>3. Transferring files</h2> <!– <h3>Using SCP</h3> –> If you wish to transfer files between your computer and the math department machines, you could always attach files and send them to your personal e-mail address. This will clog up your e-mail address. The better alternative is to use a nice mouse-based tool.</p> <p>For Windows, use <a href=“http://winscp.net/eng/index.php”>WinSCP</a>. For Macintosh, use <a href=“http://rsug.itd.umich.edu/software/fugu/”>Fugu</a>.</p> <p><hr></p> <p><a name=“xwindows”></a><h2>4. Using X Windows</h2></p> <p>Up until now, the tutorial has focused on running text-based programs. However, one can use all of the graphical programs via X Windows. Some of the programs you can use once you set up X Windows include: MatLAB, Maple, Mathematica, gedit, and a nicer version of the Emacs text editor.</p> <p><h3>Using Cygwin/X on Windows</h3></p> <p>You will need to download and install <a href=“http://www.cygwin.com/”>Cygwin</a>. After downloading and installing, you have to install Cygwin/X. According to <a href=“http://x.cygwin.com/”>http://x.cygwin.com</a>, Cygwin/X is installed via Cygwin's setup.exe : After running setp.exe, select the “xinit” package from the “X11” category.</p> <p>To start Cygwin/X, run Cygwin and run the command <span class=“codetype”>startx</span>.</p> <p><h3>Using X Windows on the Mac</h3></p> <p>Install X11 from the Apple Mac installation CD. Start up your X Windows software by running the application X11 from the Dock.</p> <p><h3>Using X Windows</h3></p> <p>In your SSH Client (whether PuTTY or something else), you must enable tunneling of X connections. On the Mac, instead of the normal ssh command, you need to run <span class=“codetype”>ssh -CY <span class=“nospam1”>&#101galois<!– foobar –></span>&#64;<span class=“nospam2”>round.math.ucdavi&#115;&#46;edu</span></span>. The use of the “Y” specifies that you wish to tunnel X11 connections.</p> <p>Once you've started your X Windows software and connected via SSH, you can run <span class=“codetype”>xclock</span> to test your connection. A new window will appear with a clock that is not text-based. If this works, you can close xclock and try <span class=“codetype”>xmaple</span>, <span class=“codetype”>matlab</span>, <span class=“codetype”>emacs</span>, <span class=“codetype”>gedit</span>, <span class=“codetype”>evince</span>, and so on.</p> <p><h3>Using the ampersand to retain the command line</h3></p> <p>When you run something like <span class=“codetype”>xclock</span>, you will lose the ability to use the SSH window until you close xclock. You can start a new SSH connection, but this is annoying. If you have an X-based program that you will be running for a while, you can use the ampersand to keep your SSH window working. For example, if you knew you want to keep the clock running for a while, you can type <span class=“codetype”>xclock &</span>.</p> <p><hr></p> <p><a name=“advanced”></a><h2>5. After you're connected: More advanced stuff</h2> This section is filled with several odds and ends. Nothing beyond this point in the tutorial is absolutely necessary, but each thing here has been suggested by one or more math graduate student. Once you are comfortable with the other stuff, you can come back to this section to learn one tidbit at a time that will further speed up your Linux use.</p> <p><h3>Tab completion</h3></p> <p>To fill in later…</p> <p><h3>Checking mail</h3></p> <p>Use <span class=“codetype”>pine</span>, which is easy to use and based on the text editor pico. The main disadvantage in pine is the poor searching features. For this, <span class=“codetype”>mutt</span> is a better e-mail program, but harder to use. Please ensure that your WebMail is not up when running either of these programs.</p> <p><h3>Setting up e-mail forwarding</h3></p> <p>To fill in later…</p> <p><h3>Downloading web content</h3></p> <p>Use <span class=“codetype”>wget</span>. To fill in later…</p> <p><h3>Command history</h3></p> <p>In BASH, you can use Ctrl-R. In general, you can also type <span class=“codetype”>history</span>.</p> <p><h3>Using SCP and SFTP</h3></p> <p>The commands <span class=“codetype”>scp</span> and <span class=“codetype”>sftp</span> are text-based tools you can use to transfer files. They are an alternative to using WinSCP or Fugu.</p> <p><hr></p> <p><a name=“resources”></a><h2>6. Additional resources</h2></p> <p><h3>Getting more help</h3></p> <p>In the section on file permissions, we introduced <span class=“codetype”>ls -l</span>, which is just one of many ways to use the ls command. To view a complete manual of ls, run <span class=“codetype”>man ls</span>. Similarly, for a manual of mv, run <span class=“codetype”>man mv</span>.</p> <p>Suppose you are looking for a command related to calendars, but you can't remember the exact name of what you're looking for. You can search on all of the command manual headline texts using “apropos”. Run <span class=“codetype”>apropos calendar</span>. Among this list, you see that “cal” displays calendars. Then, you can run <span class=“codetype”>man cal</span> to get full details on how to run cal.</p> <p><h3>Links to other tutorials</h3></p> <p><ul> <li><a href=“http://www.ee.surrey.ac.uk/Teaching/Unix/”>UNIX/Linux Tutorial for Beginners</a> has eight lessons. The last six cover some nice conveniences.</li>

playground/playground.1462861917.txt.gz · Last modified: 2016/05/09 23:31 by bedutra