Getting Started with Linux the Extremely Illustrated Version
Total Page:16
File Type:pdf, Size:1020Kb
Lab 1: Getting Started with Linux The Extremely Illustrated Version Graham Northup Objectives ● Be familiar with the use of the terminal on Linux systems. ● Know what Linux resources on campus are available for your use. ● Understand how to submit assignments for this course. Getting a Terminal Getting a Terminal Getting a Terminal Getting a Terminal Seeing Stuff Making Files Moving Around Moving Back Editing Files ● Linux systems are usually replete with a number of text editors. ● Various users tend to have their own preferences (Google “editor war”) ● I will be teaching Vim, the vi-improved editor, but you are free to edit your assignments with whatever you feel comfortable with, including, e.g., CodeBlocks, Notepad++, etc. Starting Vim Vim Entering “Insert Mode” Typing Text Exiting “Insert Mode” Exiting Vim Back to the Terminal Displaying File Contents Copying Files Moving Files Removing Files Where you are ● For now, you have been working on the local host, which is probably one of the ITL machines. ● Work saved on these machines is accessible by anyone else who might sit there! ● For assignments, the University has dedicated servers which also provide a Linux environment, one of which is Odin. Accessing Servers Your Clarkson Full name of the server username Accessing Servers Accessing Servers Accessing Servers Where you are Servers Local host (e.g., ITL machine) Network / Internet Accessing Servers Done on server Exiting Servers Exiting Servers Done on server Done on local host Copying Files to Servers Your Server’s full name Location to Clarkson copy to username Copying Files to Servers Copying Files to Servers Copying Files to Servers Accessing Servers in Windows putty www.putty.org Copying Files to Servers in Windows WinSCP winscp.net Task 1 Create three files in your home directory (~) on Odin (odin.cslabs.clarkson.edu): ● touch one file; ● Create one file by editing it (e.g., with vim); ● Copy one file with scp. (Filenames nor contents are important.) Existence of these files will be checked and graded by the morning of Tuesday, September 6. Lab 1: Getting Started with Linux The Extremely Illustrated Version Graham Northup In today’s lab, we’ll be getting started with Linux and, perhaps more importantly, it’s terminal. As we will be using systems running Linux for many of our assignments in this class, it’s important to get a fair grasp of this early. Objectives ● Be familiar with the use of the terminal on Linux systems. ● Know what Linux resources on campus are available for your use. ● Understand how to submit assignments for this course. I hope that you’ll be able to leave with three things today: an understanding of how to use the terminal and issue commands within it, knowledge about the resources you have on campus for both use and help with the Linux systems you will be dealing with, and, of course, an understanding of how to submit assignments for this course. Getting a Terminal Without further ado, then, let’s get started! You’re probably sitting in front of a Linux machine (in the ITL), so long as no one booted into Windows. (If someone did, just restart it.) These machines have a nice, fancy graphical user interface that you’re probably quite familiar with; however, that’s mostly because they have the benefit of monitors. When we’re dealing with servers later, which don’t, dealing with a terminal will be far more useful. To start, let’s find a terminal on the machine in front of you; what I’ve found to be the most robust way to start one is with this terminal emulator entry in the application launcher menu down in the bottom left of your display—where the “Start Menu” would be on Windows... Getting a Terminal ...for the impatient, there’s a quick-launch for the terminal emulator next to the launcher, too, but it’s been known to disappear... Getting a Terminal ...as has the desktop icon, which tends to get moved around by bored students :) Getting a Terminal If all went well, you should be looking at a window that appears like this; this is your terminal! Many of them will have green on black (though some hapless students also like to change the colorscheme, font size, etc.), but the important part is the text that you should see in the top-left; this is your prompt, the system’s way of asking you what you would like to do. It contains three parts, separated by an at-sign (@) and a colon (:), and ended with a dollar sign ($), whose meaning we will go over later. Be familiar with entering text into this line; it works just like a “normal” text editor; you can insert characters, backspace, move left and right with the arrow keys, and so forth. You’ll note that the cursor is a block; if you’re more familiar with the cursor that goes between characters, just pretend it’s on the left edge of that block. Seeing Stuff It’s time to run our first command! Type “ls” and press enter. (ls is short for “list”; programmers like to abbreviate everything :) If all went well, you should see something like this, at least in the ITL. The text represents objects—files and directories (or “folders”)--that are in your working directory. In general, all of the commands I’m going to give you that work with files do so in your working directory, which is indicated by the last part of the prompt—after the colon (:). Right now, it reads “tilde” (~), which means your home directory. Whenever you start a session, you usually start there. Not all terminals have color, and not all commands support it, but in this case, both do—and ls has colored the directories blue for you. All of these are directories, so what does a file look like? Making Files The easiest way to create a file is probably the touch command. This is the first one we’ll be using which takes an argument—something that tells touch about what it should do. In this case, it takes one argument: the name of the file it should create. Separate the command and argument with one or more spaces; the argument (a file name) should not contain spaces. Press Enter when you’ve satisfactorily named your new file; I called it “filename” in these examples, but you can use your imagination. Now we can see what color a regular file is on this terminal: plain! It shows up as green because that is the default text color. Moving Around When working (creating files, editing files, etc.), it is convenient to change your working directory so that you can separate your work into different places. Conceptually, this is like creating many folders to group your files into, and your terminal (really, shell) is in only one of these folders at a time. To change working directories, use the command cd (“change directory”); it takes just one argument, the name of an existing directory to change into. I chose the “itl_chorus” directory in these examples because I knew it contained a lot of files. Here, you can see the output of “ls” in that directory; many Unix veterans will almost compulsively “ls” whenever they change directories, make directories, make files, etc.; just to see what happened. Moving Back We know that we can move into a subdirectory by naming it, but suppose that we want to move back out—Linux provides for us a very special directory name for this purpose, called “..” (two dots). Wherever you are, it always means “the parent directory” or “one directory up”. By cd’ing “into” that directory, you can move back up again. You can do this indefinitely, and even explore the whole filesystem this way; if you ever get lost, just run cd without arguments, and it will return you back home (“~”). Editing Files ● Linux systems are usually replete with a number of text editors. ● Various users tend to have their own preferences (Google “editor war”) ● I will be teaching Vim, the vi-improved editor, but you are free to edit your assignments with whatever you feel comfortable with, including, e.g., CodeBlocks, Notepad++, etc. We learned how to create files in the terminal, but it’s also arguably important to know how to edit them. For this course, I don’t expect you to create files in exactly this way—you are free to use whatever editor(s) you are comfortable with—but, in keeping with the theme of learning how to use the terminal, I will be teaching how to use an old, venerable text editor: Vim. There are a few other text editors that are easily used from the terminal, too (including Emacs, Jeanna’s favorite :), but I’m covering this one just because I think it is more streamlined and I’m much more familiar with it. Starting Vim Vim’s proper name is in Title Case, but, like most Linux commands, the command is given in all lowercase. Vim takes one argument—the name of the file you would like to edit (it need not exist, and, indeed, Vim will create it for you if it doesn’t). Vim Once you’re in Vim, you’ll notice your prompt is gone! Vim has essentially taken over your terminal in order to display the file to you and let you edit it. Right now, of course, this file is empty, so there’s nothing to display. Nonetheless, you will see some information along the bottom, and some tildes (~) along the side (blank lines past the end of the file), and the number 1 before your cursor—that’s the line number of the file you’re in, the very first.