CS 103 Lab 1 - Linux and Virtual Machines

Total Page:16

File Type:pdf, Size:1020Kb

CS 103 Lab 1 - Linux and Virtual Machines CS 103 Lab 1 - Linux and Virtual Machines 1 Introduction In this lab you will login to your Linux VM and write your first C/C++ program, compile it, and then execute it. 2 What you will learn In this lab you will learn the basic commands and navigation of Linux/Unix, its file system, the GNU C/C++ compiler and a few basic applications such as Gedit. Important: The Linux operating system and environment shares a vast majority of commands and methods with Unix. 3 Background Information and Notes 3.1 Software to Install on your PC Start by following the course virtual machine installation instructions found at the link below. http://cs103.usc.edu/tools-and-links/installing-course-vm/ Below is a list of recommended software you should install that will be helpful over multiple courses in CS and EE. These tools allow you to access remote servers, run GUI apps on those servers, and transfer files between your PC and those servers. For Windows: FileZilla FTP – Available from : https://software.usc.edu/index.aspx XWin-32 – Available from : https://software.usc.edu/index.aspx PuTTY – Available from : https://software.usc.edu/index.aspx For Mac: X Server: http://developer.apple.com/opensource/tools/runningx11.html Fetch FTP – Available from : https://software.usc.edu/index.aspx Reference: http://www.usc.edu/its/unix/ Last Revised: 8/29/2014 1 CS 103 Lab 1 - Linux and Virtual Machines 3.2 Getting Started with Unix1 and Accessing your Account Solaris vs. Unix vs. Linux UNIX was developed by AT&T Bell Labs in 1969. Later, a research group at University of California at Berkley added some very important modules to the basic “kernel” of UNIX. This version of Unix is usually referred to as the Berkley Unix. It was here that Unix really took off as the operating system of choice for developers who wanted to add functionality to the kernel so as to fit their needs. Several companies took the Unix kernel and added various features to it to suit their machines and target market. Solaris is the operating system distributed by Sun Microsystems which uses the Unix kernel. The differences between Unix and Linux, however, are more subtle and therefore, arguable. Google the phrase “differences between Unix and Linux” if you really care to find out. From a novice user’s standpoint, there are really no differences. Almost all basic Unix commands work on Linux. 4 Procedure and Reference 4.1 Starting your VM Please reference the following video that will walk you through launching your Ubuntu Linux VM and starting to use it. Below is a small text summary. http://ee.usc.edu/~redekopp/Streaming/fa13_vm_walkthru/fa13_vm_walkthru.html Launch VirtualBox from your host OS. From the VirtualBox Menu choose File..Import. Then navigate to the folder where you extracted your Ubuntu VM Image and enter that folder. You should see a file with the .ova extension. Open this file. Accept the default options. Note: In Virtual Machine terminology we refer to the 'host' OS which is the actual OS your PC is running (OS X or Windows) and the 'guest' OS which is the OS running virtually (i.e. Ubuntu). 1 Acknowledgement: Much of the material covered in this handout is taken from a tutorial produced by Bilal Zafar and user guides prepared by the Information Technology Services at the University of Southern California. Please visit www.usc.edu/its/software for more details on the topics covered. 2 Last Revised: 8/29/2014 CS 103 Lab 1 - Linux and Virtual Machines Back in the Virtual Box Manager, click on the Ubuntu Image and click 'Start'. Say 'Ok' or 'Yes' to any information messages about 'Auto capture …' and you can check the box to not show those messages again. If the VM successfully launches you should arrive at a login screen with the user 'Student' highlighted. Your username is: student Your password is: developer Double-click the Student account and enter your password. You can now use your VM by launching a Terminal and entering commands. Continue through the rest of this lab to learn the basic Linux commands and file structure. 4.2 Unix File System and Navigation Commands It is important to understand how directories are arranged in Unix/Linux. Logically, Unix files are organized in a tree-like structure (just like in Windows). '/' is the root directory (much like C: is for Windows). Underneath root are other directories/folders with a sample structure shown below: / home usr etc student bluetooth pa1 pa2 examples Shortcuts: .. = parent directory (up one level) . = current directory ~ = home directory (/home/student) robot fileio / = root directory Figure 1- Unix/Linux File System Structure Everyone's account (and associated files) is stored under their home directory (usually their USC username on shared servers such as aludra.usc.edu or parallel05.usc.edu; your username is student on Ubuntu VM's) and is located under /home (e.g. /home/student). Your home directory is where you start when you log into the system. Most Unix applications are located under /usr directory. /etc contains system configuration info and scripts that only the administrator of the system is allowed to change. Last Revised: 8/29/2014 3 CS 103 Lab 1 - Linux and Virtual Machines The cd command is used to navigate between directories. Change directory to any other sub-directory in your home directory (mail, for example) by entering the command: cd <directoryname> To return to the home directory from ANY directory, just type “cd” (without any options or arguments) or “cd ~” as the ~ is an alias for your home directory. To go to etc directory (from your home directory), type: cd /etc In Linux we often want to specify the location of a file relative to the current directory. To help, the current directory can always be referenced by “.”, the directory one level above the current is referenced by “..” whereas the home directory is referenced by “~”. For example, suppose you were in the directory home/student/examples/loops and you wanted to go up to the “examples” directory you would type: "cd ..". If you wanted to go directly to the home directory, you could type "cd ../.." to go up two directories but it would be easier to just type: "cd ~" (the shortcut for your home directory). To go from the loops directory to pa1 you could type "cd ../../pa1". List (ls) is perhaps the most commonly used Unix command. It displays (lists) the files within a directory as well as any subdirectories. Let’s give it a try. Type: ls at the prompt. Notice that we did not use any options or arguments and the system returned a simple list of all the files and folders in the current directory. Let us tweak this command with some options. Type: ls –a at the prompt. Is the list of directory contents returned by "ls –a" longer than the one returned by just "ls"? Did you notice some files starting with “.” reported by "ls –a"? This is because the option –a asks forces the system to return ALL files, including system files and hidden files, to be displayed. Now, let’s try another flavor of the same command. Type: ls -la What additional information is produced by "ls –l"? We can specify more than one option for most commands. For example, the option “-t” sorts the list by time. Let us combine this with the “-l” option. Type: ls –lt Notice the dates corresponding to the files and directories reported. 4 Last Revised: 8/29/2014 CS 103 Lab 1 - Linux and Virtual Machines We can also give a folder as argument to the list command to view the contents of that directory rather than the current directory. Look for a directory in your home directory and use the command syntax ls –lt <directory name> to see its contents. We will look at several other Unix commands and utilities later in this lab. Files and directories in Unix/Linux have “permissions”. There are three levels of permissions: user, group, and all (world). User permissions set the access to a file for you and your account. Group permissions apply to other users in your group (usually all students in the course). All or world permissions apply to any user of the system. Within each level you can set the read, write, and executable permissions. To view the permissions, simply type "ls –l". At the beginning of each line will be listing of the user, group, and all permissions in that order. A dash means the permission is not set while the letter ‘r’, ‘w’, or ‘x’ indicates the permission is set. Most data files will only be readable and writable from your user level (no one else should be able to see or modify your files). Executable files (including all directories) should be marked with the user executable permission to allow you to run them (or enter them in the case of directories). In some cases you may need to change the permissions of a file. For example, when setting up your student web page, you want the world (all) to have permission to read your files. In this case you may set the permission to allow all to read and execute the page but not write your files. The chmod program will be used for this and is explained later. Text Editors Most Unix/Linux systems provide several text editors. vi (short for “visual editor”), nano, gedit and emacs are the most common editors. ‘gedit’ is perhaps the most user-friendly of these three editors while ‘emacs’ is the most powerful.
Recommended publications
  • Openvms: an Introduction
    The Operating System Handbook or, Fake Your Way Through Minis and Mainframes by Bob DuCharme VMS Table of Contents Chapter 7 OpenVMS: An Introduction.............................................................................. 7.1 History..........................................................................................................................2 7.1.1 Today........................................................................................................................3 7.1.1.1 Popular VMS Software..........................................................................................4 7.1.2 VMS, DCL................................................................................................................4 Chapter 8 Getting Started with OpenVMS........................................................................ 8.1 Starting Up...................................................................................................................7 8.1.1 Finishing Your VMS Session...................................................................................7 8.1.1.1 Reconnecting..........................................................................................................7 8.1.2 Entering Commands..................................................................................................8 8.1.2.1 Retrieving Previous Commands............................................................................9 8.1.2.2 Aborting Screen Output.........................................................................................9
    [Show full text]
  • Filesystem Hierarchy Standard
    Filesystem Hierarchy Standard LSB Workgroup, The Linux Foundation Filesystem Hierarchy Standard LSB Workgroup, The Linux Foundation Version 3.0 Publication date March 19, 2015 Copyright © 2015 The Linux Foundation Copyright © 1994-2004 Daniel Quinlan Copyright © 2001-2004 Paul 'Rusty' Russell Copyright © 2003-2004 Christopher Yeoh Abstract This standard consists of a set of requirements and guidelines for file and directory placement under UNIX-like operating systems. The guidelines are intended to support interoperability of applications, system administration tools, development tools, and scripts as well as greater uniformity of documentation for these systems. All trademarks and copyrights are owned by their owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark. Permission is granted to make and distribute verbatim copies of this standard provided the copyright and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this standard under the conditions for verbatim copying, provided also that the title page is labeled as modified including a reference to the original standard, provided that information on retrieving the original standard is included, and provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this standard into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the copyright holder. Dedication This release is dedicated to the memory of Christopher Yeoh, a long-time friend and colleague, and one of the original editors of the FHS.
    [Show full text]
  • Consolidate Home Directories to Improve Workforce Productivity
    Solution brief Consolidate home directories to improve workforce productivity HPE 3PAR File Persona Software Empower and enable users while increasing security Efficient: Improve your primary storage efficiency and control • One-third the data center footprint and significant power savings • One converged capacity eliminates Challenge Truly converged storage for wasted block or file space reservation home directory consolidation Localized user data with inadequate and Effortless: Simplify your storage inefficient protection and control HPE 3PAR StoreServ is highly efficient, deployment and administration Every IT organization has a need to store • Autonomic provisioning of all capacity flash-optimized storage engineered for and manage user-generated data such as the true convergence of block, file, and • Single, simple, and streamlined business documents, images, audio, and administration of block, file, and object access. HPE 3PAR Operating System object access video files. Traditionally, this has been done and converged controllers incorporate in local home directories on individual users’ multi-protocol support into the heart Bulletproof: Deploy your file shares laptops and desktops resulting in higher of the system architecture. This unique with confidence than necessary client device costs, ineffective • Resilient Mesh-Active architecture solution delivers tightly integrated, truly and intrusive backup processes, complex converged storage for provisioning both • Mission-critical proven HPE file system and time-consuming restore processes, and block volumes for server workloads and file poor data governance. IT needs a solution and object shares for client workloads such that maximizes workforce productivity while as home directory consolidation—efficiently, ensuring that data is effectively protected, effortlessly, and without compromise. secured, and controlled—all with minimal cost and effort.
    [Show full text]
  • MS-DOS Basics.Pdf
    MS-DOS Basics The Command Prompt When you first turn on your computer, you will see some cryptic information flash by. MS-DOS displays this information to let you know how it is configuring your computer. You can ignore it for now. When the information stops scrolling past, you'll see the following: C:\> This is called the command prompt or DOS prompt. The flashing underscore next to the command prompt is called the cursor. The cursor shows where the command you type will appear. Type the following command at the command prompt: ver The following message appears on your screen: MS-DOS version 6.22 Viewing the Contents of a Directory To view the contents of a directory 1. Type the following at the command prompt: dir A list similar to the following appears: Changing Directories To change from the root directory to the WINDOWS directory To change directories, you will use the cd command. The cd command stands for "change directory." 1. Type the following at the command prompt: cd windows The command prompt changes. It should now look like the following: C:\WINDOWS> Next, you will use the dir command to view a list of the files in the DOS directory. Viewing the Contents of WINDOWS Directory To view a list of the files in the WINDOWS directory 1. Type the following at the command prompt: dir Changing Back to the Root Directory To change to the root directory 1. Type the following at the command prompt: cd \ Note that the slash you type in this command is a backslash (\), not a forward slash (/).
    [Show full text]
  • The Complete Freebsd
    The Complete FreeBSD® If you find errors in this book, please report them to Greg Lehey <grog@Free- BSD.org> for inclusion in the errata list. The Complete FreeBSD® Fourth Edition Tenth anniversary version, 24 February 2006 Greg Lehey The Complete FreeBSD® by Greg Lehey <[email protected]> Copyright © 1996, 1997, 1999, 2002, 2003, 2006 by Greg Lehey. This book is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike 2.5” license. The full text is located at http://creativecommons.org/licenses/by-nc-sa/2.5/legalcode. You are free: • to copy, distribute, display, and perform the work • to make derivative works under the following conditions: • Attribution. You must attribute the work in the manner specified by the author or licensor. • Noncommercial. You may not use this work for commercial purposes. This clause is modified from the original by the provision: You may use this book for commercial purposes if you pay me the sum of USD 20 per copy printed (whether sold or not). You must also agree to allow inspection of printing records and other material necessary to confirm the royalty sums. The purpose of this clause is to make it attractive to negotiate sensible royalties before printing. • Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. • For any reuse or distribution, you must make clear to others the license terms of this work. • Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above.
    [Show full text]
  • MS-DOS Lecture
    MS-DOS 2017 University of Babylon College of Engineering Electrical Department Learning Basics of MS-DOS Assis. Lec. Abeer Abd Alhameed | 1 MS-DOS 2017 Outcomes: By the end of this lecture, students are able to: Define the MS-DOS system Log in MS-DOS commands system Display MS-DOS information on your computer Type basic commands of MS-DOS system (view directory contents, change directory, make directory) Assis. Lec. Abeer Abd Alhameed | 2 MS-DOS 2017 Learning of MS-DOS Basics: Definition - What does Microsoft Disk Operating System (MS- DOS) mean? The Microsoft Disk Operating System (MS-DOS) is an operating system developed for PCs (personal computers) with x86 microprocessors. It was the first widely-installed operating system in personal computers. It is a command-line-based system, where all commands are entered in text form and there is no graphical user interface. The Command Prompt: When you first turn on your computer, you will see some information flash by. MS-DOS displays this information to let you know how it is configuring your computer. You can ignore it for now. When the information stops scrolling past, you'll see the following: C:\> This is called the command prompt or DOS prompt. The flashing underscore next to the command prompt is called the cursor. The cursor shows where the command you type will appear. Typing a Command: This section explains how to type a command at the command prompt and demonstrates the "Bad command or file name" message. • To type a command at the command prompt 1. Type the following at the command prompt (you can type the command in either uppercase or lowercase letters): nul If you make a typing mistake, press the BACKSPACE key to erase the mistake, and then try again.
    [Show full text]
  • Filesystem Hierarchy Standard
    Filesystem Hierarchy Standard Filesystem Hierarchy Standard Group Edited by Rusty Russell Daniel Quinlan Filesystem Hierarchy Standard by Filesystem Hierarchy Standard Group Edited by Rusty Russell and Daniel Quinlan Published November 4 2003 Copyright © 1994-2003 Daniel Quinlan Copyright © 2001-2003 Paul ’Rusty’ Russell Copyright © 2003 Christopher Yeoh This standard consists of a set of requirements and guidelines for file and directory placement under UNIX-like operating systems. The guidelines are intended to support interoperability of applications, system administration tools, development tools, and scripts as well as greater uniformity of documentation for these systems. All trademarks and copyrights are owned by their owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark. Permission is granted to make and distribute verbatim copies of this standard provided the copyright and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this standard under the conditions for verbatim copying, provided also that the title page is labeled as modified including a reference to the original standard, provided that information on retrieving the original standard is included, and provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this standard into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the copyright holder. Table of Contents 1. Introduction........................................................................................................................................................1 1.1.
    [Show full text]
  • Downloading and Installing the Mobile Map for IOS, Android, Or Windows Device (See * Below) Common to All Devices: 1
    Downloading and Installing the Mobile Map for IOS, Android, or Windows device (See * below) Common to all devices: 1. Open your browser (see ** below) and return to www.mobilehuntingmaps.com, login and your My Account page will open. 2. On the left side, click on Orders. 3. Your order will appear on the right side of the page. 4. At the end of the order row, click on View to open the details of your order. 5. Beneath the name of the State you will see Download: Download Now and the password needed to open the map file with the CarryMap app. 6. Write down the password then click on Download Now. IOS Devices: (see ** below) 1. Dependent on your version of IOS (Apple operating system) you might be asked a second time to confirm the download. 2. How the download progress is displayed on your phone’s screen varies dependent on the IOS version on your phone. On IOS 12.0 or newer, a blue circle with a down pointing arrow inside will appear and a tiny blue line will move from left to right just under the circle as the download is in progress. Be patient as some of the map data files are large. Dependent on your internet speed and your WIFI strength, the download can take several minutes. Do not try to download a file using a cell phone service, more than likely it will drop before the download is complete. 3. Once the download progress is complete (the blue circle moves up and down and the blue line disappears), the file has been downloaded.
    [Show full text]
  • Introduction to Unix From
    Introduction to Unix from http://cnl.web.arizona.edu Index • Operating Systems • Files • Unix File System o The Path • Ownership and Permissions o Ownership o Permissions • Copy, Move and Remove Files and Directories • Archiving and Zipping • Viewing and Editing Text Files • Size • Unix Help • Tips and Tricks o Cut and Paste o Filename Completion o Find Command o History • Clients and Servers • Communicating across machines Related Resources • Glossary • Printing • Shell Scripts Operating Systems An Operating System (e.g., Windows 95, Windows 98 etc. from Microsoft; Unix systems like Linux, Irix, and Solaris) organizes your files and talks to the hardware. This means the OS translates from the very crude organization system that really exists on your hard drive to the hierarchical system that it presents to you. Essentially, it works like this: The Hard Drive has an area set aside that holds a table of addresses or "pointers" to blocks of information on the rest of the HD. The table's content and organization, the number and size of blocks on the HD etc. are dependent upon the particular OS. Although Unix systems are not exactly the same as each other, they are very similar to one another; just as Windows 95 and Windows 98 are very similar to one another. Files (A Comparison of Windows and Unix) Under Microsoft Windows, file names consist of two parts: a main part and an extension, separated by a special character, the dot (e.g., bird.jpg, fred.xls). The extension tells Windows which program to use to open the file (e.g., *.xls files are opened by MS Excel).
    [Show full text]
  • How to Load Vista Or Windows 7 Onto a Bootable Thumb Drive
    STAR Watch Statewide Technology Assistance Resources Project A publication of the Western New York Law Center,Inc. Volume 15 Issue 5 Sept-Oct 2011 How to Load Vista or Windows 7 onto a Bootable Thumb Drive Ever since the capacity of USB thumb more robust. What happens when a drives rose into the multi-gigabyte range, DVD gets scratched? computer geeks have been trying to use them to create bootable devices that • Some of the latest computers don’t could be used in an emergency to boot have DVD drives, but they do have a up a failed computer. It was a wonderful USB port. idea, except for one detail: The driver • It takes less time to re-install needed to read the Windows install files Windows from a thumb drive could not be accessed. With the release of Vista and Windows 7 operating Find yourself a suitable thumb drive. It systems, the drivers needed to read the might be possible to shoehorn the files have been made more accessible. It Windows software onto a 4GB thumb is now possible to create a bootable drive, but that would leave no room for thumb drive that can be used to boot up anything else (It might be nice to have a computer and install Windows. copies of the install programs for things like printer drivers or other software that So, what is the big deal? Isn’t a DVD good enough? For many people, a DVD is quite adequate. Just store it in a safe In this issue… place and pull it out when it is needed.
    [Show full text]
  • Linux File System and Linux Commands
    Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers Review of the Linux File System and Linux Commands 1. Introduction Becoming adept at using the Linux OS requires gaining familiarity with the Linux file system, file permissions, and a base set of Linux commands. In this activity, you will study how the Linux file system is organized and practice utilizing common Linux commands. Objectives • Describe the purpose of the /bin, /sbin, /etc, /var/log, /home, /proc, /root, /dev, /tmp, and /lib directories. • Describe the purpose of the /etc/shadow and /etc/passwd files. • Utilize a common set of Linux commands including ls, cat, and find. • Understand and manipulate file permissions, including rwx, binary and octal formats. • Change the group and owner of a file. Materials • Windows computer with access to an account with administrative rights The Air Force Cyber College thanks the Advanced Cyber Engineering program at the Air Force Research Laboratory in Rome, NY, for providing the information to assist in educating the general Air Force on the technical aspects of cyberspace. • VirtualBox • Ubuntu OS .iso File Assumptions • The provided instructions were tested on an Ubuntu 15.10 image running on a Windows 8 physical machine. Instructions may vary for other OS. • The student has administrative access to their system and possesses the right to install programs. • The student’s computer has Internet access. 2. Directories / The / directory or root directory is the mother of all Linux directories, containing all of the other directories and files. From a terminal users can type cd/ to move to the root directory.
    [Show full text]
  • Permissions and Ownership
    Getting Started with Linux: Novell’s Guide to CompTIA’s Linux+ Objective 1 Understand User and Group Configuration Files Information on users and groups on a Linux system is kept in the following files: ■ /etc/passwd ■ /etc/shadow ■ /etc/group Whenever possible, you should not modify these files with an editor. Instead, use the Security and Users modules in YaST or the command line tools described in the next objective, “Manage User Accounts and Groups from the Command Line” on 7-12. Modifying these files with an editor can lead to errors (especially in /etc/shadow), such as a user—including the user root—no longer being able to log in. To ensure consistency of these files, you need to understand how to ■ Check /etc/passwd and /etc/shadow ■ Convert Passwords to and from Shadow /etc/passwd The file /etc/passwd stores information for each user. In the past, UNIX and Linux users were handled in a single file: /etc/passwd. The user name, the UID, the home directory, the standard shell, and the encrypted password were all stored in this file. The password was encrypted using the function crypt (man 3 crypt). In principle, the plain text password could not be deciphered from the encrypted password. 7-2 Version 2 Use the Command Line Interface to Administer the System However, there are programs (such as john) that use dictionaries to encrypt various passwords with crypt, and then compare the results with the entries in the file /etc/passwd. With the calculation power of modern computers, simple passwords can be “guessed” within minutes.
    [Show full text]