Unix Tutorial & Environment Setup

Total Page:16

File Type:pdf, Size:1020Kb

Unix Tutorial & Environment Setup Unix Tutorial & Environment Setup 1 Walkthrough 1. Open your terminal application (Mac and Linux) or download and install puTTY (Windows). Linux and Mac users, go to step 2; Windows users should follow along with the CUIT instructions and then return to step 2. SSH into CUNIX by typing the command \ssh <UNI>@cunix.columbia.edu" (without the quotes), where <UNI> is your UNI (I would type ssh [email protected]. You will be prompted for your password and a message about authenticity of the host (type `yes') 3. You are now in a UNIX terminal running a BASH shell. Congratulations! 4. a. See what directory you're in by entering pwd - this should be your home directory b. Make a new directory using the mkdir command, mkdir cprog c. cd (change directory) into that directory with cd cprog d. run pwd again to make sure you made it into the new directory e. run ls (you won't see much); touch test.txt and ls again f. move back to your home directory, cd .. g. get rid of the test file with rm cprog/test.txt 5. Get exploring and work on the problems in section 2. 6. When you're all done, you can logout of the session. Contents 1 Walkthrough 1 2 Practice Problems & Challenges2 3 What is UNIX? 2 4 The TTY/Shell (bash) and the Command Prompt2 4.1 bash.......................................................2 4.2 The Prompt...................................................3 5 man 3 6 ssh 3 7 Environment Variables, Editors, and the $PATH 3 7.1 File Paths....................................................3 7.2 Environment Variables and the PATH .....................................4 7.3 Editors......................................................4 8 Useful Commands 4 9 Redirection and stdio 4 1 2 Practice Problems & Challenges Write up and submit your answers to challenges 1 and 2; continue to work on 3, 4, and 5 throughout the semester. 1. a. What are . and ..? Why are they useful? b. Why doesn't root have a .. directory? 2. a. Write a bash script called `backup' to backup a file (ie. make a new file with the same content but a new name) that takes the file’s name and the new backup name as arguments. try it out (hint: what permissions does it need to run?) b. What does #!/bin/bash mean? what is ./ doing? c. Why doesn't our script need an extension? what might it be if we wanted to give it one? d. Make the script handle user error 3. a. Customize the command prompt, add some color, show the pwd, go nuts and add anything you find useful. b. Change the prompt based on the success/failure of the last command; show how long the command took to run. c. Add some command aliases for frequent commands. d. How would you make these changes permanent? 4. Setup ssh keys so you don't have to type in your password every time you ssh. 5. Pick a version control system and try to start using it - here's a simple git tutorial to tickle your fancy: git- tutorial.pdf 3 What is UNIX? UNIX is an operating system first written at Bell Labs 1970 (the epoch). It is primarily written in C and another (less abstract) language called Assembly and it is the basis for Mac OS X, Linux, Chrome OS, Android, iOS, and even Microsoft Windows. 4 The TTY/Shell (bash) and the Command Prompt When multi-user and multi-threaded computing was emerging (computers only ran a single program at a time for a single user before that) computer setups consisted of a single central computer and several terminals (the screen and keyboard part { no mouse) wired to it. These terminals provided a command prompt to let users run programs, just not graphical programs that you're used to. 4.1 bash The Bourne Again SHell (bash) is one of those programs that run in a terminal { it's called a ?shell' program and is the default shell on OS X and most Linux variants. What this means is that it runs as a command interpreter, allowing you to enter commands that run in the terminal. When you open up or ssh into (that's in the next section) a terminal, it will already be running a shell program { you can check this out by running the ps command and looking for the ?bash' process. Shell programs also allow you to write scripts (programs) using the commands (bash uses a C-like programming language) *some other shell options include the popular zsh, as well as ksh, the Bourne shell (sh) for which bash is named, tcsh, and its predecessor, the C-shell (csh). 4.2 The Prompt The command-line prompt is usually signified by a $, #, or > and maybe some other info like the current user, directory/folder, or the computer hostname { don't worry too much about that info, it's just there to help you get your bearings as you work. The prompt waits for commands from you that it can process and run { these usually consist of C or Assembly programs which you run by entering the command name (like ps) and hitting `ENTER'. Many programs will take arguments, or extra data, and some optional flags { take the ls (list) command: running 2 ls with no arguments will list the files and directories that are sitting inside the current directory; if you want to see what's in some other directory, you could run the command with that directory's name, ls SomeOtherFolder/; ls can also take some optional flags like -a and -l (ls -a, ls -l, or even ls -al) which will show hidden files and extended information, respectively. *usually, `ctrl-c' will interrupt and terminate the current process, so if you get stuck try it out. `ctrl-d' will also simulate EOF, or end-of-file, which can be useful too. *if you're on a Mac, the built-in ?terminal' application is a terminal emulator that runs bash by default; if you're on windows, the Command Prompt has a similar function, but different commands { consider getting a UNIX terminal emulator like puTTY if you'd like to be able to work locally. 5 man The first UNIX program you will come to love is man, short for manual. It is your guidebook and it will reveal the wonders of the UNIX and C universes to you. It is the command manual and most programs and commands will have a ?man page' { that means you can run man ls or man ps to find out what the ls or ps programs do, how you use them, and what are valid arguments and flags. Another useful tool is a program's own help command: many programs are willing to offer you some help if you'll just ask. You can usually do this by adding a -help, -h, --help, or --h flag to the command. Most programs will also print their usage instructions for you if you use them wrong, this can be just as helpful. *by default, man uses a program called less to display pages - you can navigate using the up and down arrow keys and typing q to exit. *try running man man. 6 ssh Many computers are set up to allow remote access { often this is in the form of a terminal that you can connect to over a network and run commands on. One of these is called CUNIX (Columbia UNIX) and is set up to provide you with a standard UNIX environment to work in over the course of this semester. The way you will connect to a virtual terminal on CUNIX is by using a program called ?Secure SHell', or ssh. Use man to figure out how to use the ssh command to access cunix.columbia.edu (the teacher will provide you with your user name). *logout will log you out of the remote session. *if you're on PC, you will need to get a program called puTTY to ssh into CUNIX. 7 Environment Variables, Editors, and the $PATH 7.1 File Paths UNIX filesystems are structured like a tree - there is a ?root' directory, or folder, in which files and other directories reside; those directories can contain their own files and subdirectories and so on { you're probably used to this structure by now, but maybe not the fact that there is a single ?root' directory (/) in which everything else sits. In UNIX, everything is a file (even directories) and file paths are built up using forward-slashes, / { paths can either be absolute (starting from root: /users/me) or relative (starting from where you are now: just /me if you're already in the users directory. Note that every directory (except for root) has `.' and `..' subdirectories (see Practice Problem 1). *check out the pwd and cd commands. 7.2 Environment Variables and the PATH In your shell, there are some useful pieces of data hanging around called environment variables. In bash, these tend to be all upper-case and can be accessed with a $. One of these environment variables is called ?PATH' { try running echo $PATH to see yours. The PATH is a list of filepaths, separated by colons, where executables (programs) can be found. This PATH is why you can run commands like ls or echo without having to specify the full path from root to where they are (/bin/ls). You can (and probably will) add your own environment variables and add directories to the path to help make your life a little easier. There are also two useful shortcuts: tilde-expansion, which expands the to your home directory (on a shared environment like CUNIX, you won't have access to the whole filesystem, and other users won't have access to your 3 home directory { it's where you'll do most of your work); and the `*' wildcard, a regular expression that assumes all possible expansions (/users/myhome/* would mean everything in the myhome directory and ls /*.txt would list all the files in my home directory with the extension `.txt').
Recommended publications
  • Program #6: Word Count
    CSc 227 — Program Design and Development Spring 2014 (McCann) http://www.cs.arizona.edu/classes/cs227/spring14/ Program #6: Word Count Due Date: March 11 th, 2014, at 9:00 p.m. MST Overview: The UNIX operating system (and its variants, of which Linux is one) includes quite a few useful utility programs. One of those is wc, which is short for Word Count. The purpose of wc is to give users an easy way to determine the size of a text file in terms of the number of lines, words, and bytes it contains. (It can do a bit more, but that’s all of the functionality that we are concerned with for this assignment.) Counting lines is done by looking for “end of line” characters (\n (ASCII 10) for UNIX text files, or the pair \r\n (ASCII 13 and 10) for Windows/DOS text files). Counting words is also straight–forward: Any sequence of characters not interrupted by “whitespace” (spaces, tabs, end–of–line characters) is a word. Of course, whitespace characters are characters, and need to be counted as such. A problem with wc is that it generates a very minimal output format. Here’s an example of what wc produces on a Linux system when asked to count the content of a pair of files; we can do better! $ wc prog6a.dat prog6b.dat 2 6 38 prog6a.dat 32 321 1883 prog6b.dat 34 327 1921 total Assignment: Write a Java program (completely documented according to the class documentation guidelines, of course) that counts lines, words, and bytes (characters) of text files.
    [Show full text]
  • DC Console Using DC Console Application Design Software
    DC Console Using DC Console Application Design Software DC Console is easy-to-use, application design software developed specifically to work in conjunction with AML’s DC Suite. Create. Distribute. Collect. Every LDX10 handheld computer comes with DC Suite, which includes seven (7) pre-developed applications for common data collection tasks. Now LDX10 users can use DC Console to modify these applications, or create their own from scratch. AML 800.648.4452 Made in USA www.amltd.com Introduction This document briefly covers how to use DC Console and the features and settings. Be sure to read this document in its entirety before attempting to use AML’s DC Console with a DC Suite compatible device. What is the difference between an “App” and a “Suite”? “Apps” are single applications running on the device used to collect and store data. In most cases, multiple apps would be utilized to handle various operations. For example, the ‘Item_Quantity’ app is one of the most widely used apps and the most direct means to take a basic inventory count, it produces a data file showing what items are in stock, the relative quantities, and requires minimal input from the mobile worker(s). Other operations will require additional input, for example, if you also need to know the specific location for each item in inventory, the ‘Item_Lot_Quantity’ app would be a better fit. Apps can be used in a variety of ways and provide the LDX10 the flexibility to handle virtually any data collection operation. “Suite” files are simply collections of individual apps. Suite files allow you to easily manage and edit multiple apps from within a single ‘store-house’ file and provide an effortless means for device deployment.
    [Show full text]
  • Programmable AC/DC Electronic Load
    Programmable AC/DC Electronic Load Programming Guide for IT8600 Series Model: IT8615/IT8615L/IT8616/IT8617 /IT8624/IT8625/IT8626/IT8627/IT8628 Version: V2.3 Notices Warranty Safety Notices © ItechElectronic, Co., Ltd. 2019 No part of this manual may be The materials contained in this reproduced in any form or by any means document are provided .”as is”, and (including electronic storage and is subject to change, without prior retrieval or translation into a foreign notice, in future editions. Further, to A CAUTION sign denotes a language) without prior permission and the maximum extent permitted by hazard. It calls attention to an written consent from Itech Electronic, applicable laws, ITECH disclaims operating procedure or practice Co., Ltd. as governed by international all warrants, either express or copyright laws. implied, with regard to this manual that, if not correctly performed and any information contained or adhered to, could result in Manual Part Number herein, including but not limited to damage to the product or loss of IT8600-402266 the implied warranties of important data. Do not proceed merchantability and fitness for a beyond a CAUTION sign until Revision particular purpose. ITECH shall not the indicated conditions are fully be held liable for errors or for 2nd Edition: Feb. 20, 2019 understood and met. incidental or indirect damages in Itech Electronic, Co., Ltd. connection with the furnishing, use or application of this document or of Trademarks any information contained herein. A WARNING sign denotes a Pentium is U.S. registered trademarks Should ITECh and the user enter of Intel Corporation. into a separate written agreement hazard.
    [Show full text]
  • Program That Runs Other Programs Unix/Linux Process Hierarchy Shell
    shell: program that runs other programs Building a Shell 1 5 Unix/Linux Process Hierarchy shell program that runs other programs on behalf of the user sh Original Unix shell (Stephen Bourne, AT&T Bell Labs, 1977) [0] bash “Bourne-Again” Shell, widely used default on most Unix/Linux/Mac OS X systems others.. init [1] while (true) { Print command prompt. Daemon Login shell Read command line from user. e.g. httpd Parse command line. If command is built-in, do it. Child Child Child Else fork process to execute command. in child: Execute requested command with execv. (never returns) Grandchild Grandchild in parent: Wait for child to complete. } 6 7 1 terminal ≠ shell Background vs. Foreground User interface to shell and other programs. Users generally run one command at a time Graphical (GUI) vs. command-line (CLI) Type command, read output, type another command Command-line terminal (emulator): Input (keyboard) Some programs run “for a long time” Output (screen) $ emacs fizz. txt # shell stuck until ema cs exi ts. A “background” job is a process we don't want to wait for $ emacs boom. txt & # em acs ru ns in backg round [1] 9073 # wh ile sh ell i s... $ gdb ./ umbre lla # im mediat ely r eady f or nex t com mand don't do this with emacs un l es s u si n g X wi nd o ws vers i o n 8 9 Managing Background Jobs Signals Signal: small message notifying a process of event in system Shell waits for and reaps foreground jobs.
    [Show full text]
  • Student Batch File Layout – Version 1.0
    Student Batch File Layout – Version 1.0 This document shall set forth the layout of the Student Batch File that will be used for feeding student records into the Uniq-ID System for id assignment and/or student information updates. The Student Batch File should contain three different types of records. The three types of records are: (1) Header record (2) Detail Record (3) Trailer Record. The Header and Trailer record should be delimited by a single tab or space character. The Detail records can be either tab or comma delimited and the Header record should identify which type is being used (in the delimiter field). All records should be delimited from each by the source operating system’s end of line character or character sequence. In the Uniq-ID System, errors in the Student Batch File will be handled in two different ways. One way is to flag the particular record and allow the user to repair it in the “Fix Errors” stage. The other way is to reject the entire Student Batch File and require that the user resubmit it. Rejection of a Student Batch File will occur if: 1. One or more record types are missing. 2. One or more fields have been omitted from a record. 3. The “Number of Records” field in the trailer record is incorrect. 4. The “Transmission ID” fields in the header and trailer records do not match. 5. The maximum allowable number of detail record errors has been exceeded. 6. The maximum allowable number of records in the entire file has been exceeded.
    [Show full text]
  • DC Load Application Note
    DC Electronic Load Applications and Examples Application Note V 3032009 22820 Savi Ranch Parkway Yorba Linda CA, 92887-4610 www.bkprecision.com Table of Contents INTRODUCTION.........................................................................................................................3 Overview of software examples........................................................................................................3 POWER SUPPLY TESTING.......................................................................................................4 Load Transient Response.................................................................................................................4 Load Regulation................................................................................................................................5 Current Limiting................................................................................................................................6 BATTERY TESTING...................................................................................................................7 Battery Discharge Curves.................................................................................................................7 Battery Internal Resistances.............................................................................................................8 PERFORMANCE TESTING OF DC LOADS...........................................................................10 Slew Rate.......................................................................................................................................10
    [Show full text]
  • Cash Valves Ls Series Pressure Reducing and Regulating Valves
    CASH VALVES LS SERIES PRESSURE REDUCING AND REGULATING VALVES High pressure single-seated, spring loaded, direct acting diaphragm type regulators for inlet pressures to 2400 psig (165.5 barg) FEATURES • Automatically reduce high inlet pressures to lower outlet pressures within close limits regardless of fluctuations. • Designed for use on air, water, oil, oxygen, carbon-dioxide and other gases and fluids. • Designed and built to meet the rugged requirements of high pressure regulation and reduction. • Exceptional flow characteristics. • Stainless steel piston/piston assemblies, cylinders, seat ring and strainer screens as standard. • NBR diaphragm and O-rings. • Self-renewable seat ring is simply flipped over and re-installed rather than replaced. • NPTF ‘Dryseal’ threaded ends as standard. • Closing cap or T-handle adjusting screw options available. GENERAL APPLICATION TECHNICAL DATA Type LS Series regulators are recommended Materials: Bronze for use on high pressure test rigs and pressure Sizes: ⅜”, ½”, ¾” (10.5, vessel or casting test equipment, hydraulic 15, 19 mm) cylinders and air tanks. Also available for Connections: Threaded NPTF cryogenic service. Inlet pressure range: 500 to 2400 psig (34.5 to 165.5 barg) Reduced pressure range: 40 to 500 psig (2.8 to 34.5 barg) Temperature range: -320° to 180°F (-195° to 82°C) Emerson.com/FinalControl © 2017 Emerson. All Rights Reserved. VCTDS-00513-EN 17/07 CASH VALVES LS SERIES PRESSURE REDUCING AND REGULATING VALVES MODELS OVERVIEW Type LS-3 is furnished with a modified cylinder and no strainer screen for applications All LS Series valves are designed and built involving heavy or high viscosity fluids. to meet the rugged requirements of a high pressure regulating and reducing valve with a Type LS-4 is constructed for cryogenic service bronze body, spring chamber and bottom plug.
    [Show full text]
  • Software II: Principles of Programming Languages
    Software II: Principles of Programming Languages Lecture 6 – Data Types Some Basic Definitions • A data type defines a collection of data objects and a set of predefined operations on those objects • A descriptor is the collection of the attributes of a variable • An object represents an instance of a user- defined (abstract data) type • One design issue for all data types: What operations are defined and how are they specified? Primitive Data Types • Almost all programming languages provide a set of primitive data types • Primitive data types: Those not defined in terms of other data types • Some primitive data types are merely reflections of the hardware • Others require only a little non-hardware support for their implementation The Integer Data Type • Almost always an exact reflection of the hardware so the mapping is trivial • There may be as many as eight different integer types in a language • Java’s signed integer sizes: byte , short , int , long The Floating Point Data Type • Model real numbers, but only as approximations • Languages for scientific use support at least two floating-point types (e.g., float and double ; sometimes more • Usually exactly like the hardware, but not always • IEEE Floating-Point Standard 754 Complex Data Type • Some languages support a complex type, e.g., C99, Fortran, and Python • Each value consists of two floats, the real part and the imaginary part • Literal form real component – (in Fortran: (7, 3) imaginary – (in Python): (7 + 3j) component The Decimal Data Type • For business applications (money)
    [Show full text]
  • Lab 2: Using Commands
    Lab 2: Using Commands The purpose of this lab is to explore command usage with the shell and miscellaneous UNIX commands. Preparation Everything you need to do this lab can be found in the Lesson 2 materials on the CIS 90 Calendar: http://simms-teach.com/cis90calendar.php. Review carefully all Lesson 2 slides, even those that may not have been covered in class. Check the forum at: http://oslab.cis.cabrillo.edu/forum/ for any tips and updates related to this lab. The forum is also a good place to ask questions if you get stuck or help others. If you would like some additional assistance come to the CIS Lab on campus where you can get help from instructors and student lab assistants: http://webhawks.org/~cislab/. Procedure Please log into the Opus server at oslab.cis.cabrillo.edu via port 2220. You will need to use the following commands in this lab. banner clear finger man uname bash date history passwd whatis bc echo id ps who cal exit info type Only your command history along with the three answers asked for by the submit script will be graded. You must issue each command below (exactly). Rather than submitting answers to any questions asked below you must instead issue the correct commands to answer them. Your command history will be scanned to verify each step was completed. The Shell 1. What shell are you currently using? What command did you use to determine this? (Hint: We did this in Lab 1) 2. The type command shows where a command is located.
    [Show full text]
  • Freebsd Command Reference
    FreeBSD command reference Command structure Each line you type at the Unix shell consists of a command optionally followed by some arguments , e.g. ls -l /etc/passwd | | | cmd arg1 arg2 Almost all commands are just programs in the filesystem, e.g. "ls" is actually /bin/ls. A few are built- in to the shell. All commands and filenames are case-sensitive. Unless told otherwise, the command will run in the "foreground" - that is, you won't be returned to the shell prompt until it has finished. You can press Ctrl + C to terminate it. Colour code command [args...] Command which shows information command [args...] Command which modifies your current session or system settings, but changes will be lost when you exit your shell or reboot command [args...] Command which permanently affects the state of your system Getting out of trouble ^C (Ctrl-C) Terminate the current command ^U (Ctrl-U) Clear to start of line reset Reset terminal settings. If in xterm, try Ctrl+Middle mouse button stty sane and select "Do Full Reset" exit Exit from the shell logout ESC :q! ENTER Quit from vi without saving Finding documentation man cmd Show manual page for command "cmd". If a page with the same man 5 cmd name exists in multiple sections, you can give the section number, man -a cmd or -a to show pages from all sections. man -k str Search for string"str" in the manual index man hier Description of directory structure cd /usr/share/doc; ls Browse system documentation and examples. Note especially cd /usr/share/examples; ls /usr/share/doc/en/books/handbook/index.html cd /usr/local/share/doc; ls Browse package documentation and examples cd /usr/local/share/examples On the web: www.freebsd.org Includes handbook, searchable mailing list archives System status Alt-F1 ..
    [Show full text]
  • C Programming Tutorial
    C Programming Tutorial C PROGRAMMING TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i COPYRIGHT & DISCLAIMER NOTICE All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] ii Table of Contents C Language Overview .............................................................. 1 Facts about C ............................................................................................... 1 Why to use C ? ............................................................................................. 2 C Programs .................................................................................................. 2 C Environment Setup ............................................................... 3 Text Editor ................................................................................................... 3 The C Compiler ............................................................................................ 3 Installation on Unix/Linux ............................................................................
    [Show full text]
  • Uniq-ID Student Batch File Layout
    Uniq-ID Student Batch File Layout (Version 1.0) Nebraska Student and Staff Record System (NSSRS) www.education.ne.gov/nssrs Nebraska Department of Education 2011-02-18 The purpose of the Uniq-ID system is to assign each student one, and only one, NDE Student ID. This system is not utilized for student reporting. It is a benefit to all users if student information is updated each school year; resolving near-matches is easier when school and grade information is current. Student First Name and Last Name The following guidelines should be followed regarding student names. 1) Values provided for First Name and Last Name should correspond to the values under which the student’s education records are stored. 2) Suffixes should only appear in Name Suffix; suffixes should be removed from Last Name and First Name. Check for the standard suffixes like Jr, Sr, I, II, III, IV, V, and VI. These may be in upper case, lower case, or mixed case. 3) Remove parenthesis. 4) Remove all special characters (e.g., periods, commas, asterisks, exclamation points). Filenames Filenames may contain upper- or lower-case alphanumeric characters, periods, underscores, or hyphens. Spaces and other special characters are not permitted. Delimiters 1) Fields on both the Header and Trailer record must be delimited by a single tab or space character. The same delimiter (tab or space) used on the Header record must be used on the Trailer record. 2) Detail records can be either tab or comma delimited and the Header record should identify which type is being used (in the delimiter field).
    [Show full text]