Command-Line Interface

Total Page:16

File Type:pdf, Size:1020Kb

Command-Line Interface Intro to Programming ROBERT SEDGEWICK | KEVIN WAYNE COMMAND-LINE INTERFACE ‣ brief overview ‣ live demo http://introcs.cs.princeton.edu Alan Kaplan and Kevin Wayne Last updated on 2/21/17 9:31 AM COMMAND-LINE INTERFACE ‣ brief overview ‣ live demo http://introcs.cs.princeton.edu Today’s plan: command-line interface Brief overview. ・IDE vs. command line. ・Files and file systems. Live demo. ・Navigating the file system. ・Java commands (including accessing stdlib.jar). ・Redirection and piping of standard input and output. Note: you will need CLI for the Assignment 2. 3 Integrated development environment (IDE) IDE. App designed for developing software. “compile” button “run” button pseudo-command line 4 Command-line interface Command line. App where you type commands. 5 Convergence: Linux, OS X, and Windows (September 1991) 6 Convergence: Linux, OS X, and Windows (March 2001) 7 Convergence: Linux, OS X, and Windows (August 2016) 8 Software for program development: tradeoffs Command line advantages. ・More control over system. ・Approach works with any language. ・Easy to automate tasks via scripting. IDE advantages. ・More intuitive for novices. ・Language-specific features. This course. Use IDE to edit and compile; use command line to execute. Beyond. Many other platforms embrace command line. 9 Files File. Sequence of bits stored on a computer. Filename. String that uniquely identifies a file. Mac OS X. /Users/wayne/cos126/hello/HelloWorld.java note: forward vs. backward slash Windows. C:\Users\wayne\cos126\hello\HelloWorld.java 10 File system hierarchy Directory (folder). Collection of files and other folders. root directory / Users Library Applications wayne DrJava.app Firefox.app Desktop cos126 Documents Music hello loops Hello.mp4 Für Elise.mp4 readme.txt RandomWalker.class RandomWalker.java /Users/wayne/cos126/loops/RandomWalker.java 11 COMMAND-LINE INTERFACE ‣ brief overview ‣ live demo http://introcs.cs.princeton.edu Live demo of file system commands 13 Standard input and output abstractions Command-line arguments. Provide arguments (strings) to a program. Standard output stream. Abstraction for writing output (default = screen). Standard input stream. Abstraction for reading input (default = keyboard). standardstandardstandard input inputinput command-linecommand-linecommand-line argumentsargumentsarguments standardstandardstandard output outputoutput standard audio standard drawing AA bird’s-eyebird’s-eye viewview ofof aa JavaJava programprogram (revisited)(revisited) A Abird’s-eye bird’s-eye view view of ofa Javaa Java program program (revisited) (revisited) 14 Live demo of standard input and output commands 15 Navigating the file system Action Mac OS X Terminal Windows Command Prompt print current directory pwd cd list contents of ls dir current directory move down cd introcs one subdirectory move up cd .. one subdirectory move down cd introcs/hello cd introcs\hello multiple subdirectories move to cd /Users/wayne cd \Users\wayne specified directory copy, move, remove, make cp mv rm copy move del directory, remove directory mkdir rmdir mkdir rmdir cycle through <Up Arrow> <Down Arrow> command history autocomplete javac Hello<Tab> 16 Java commands Action Mac OS X Terminal Windows Command Prompt compile Java program javac HelloWorld.java execute Java program java HelloWorld compile Java program javac-introcs HelloWorld.java (with our standard libraries) execute Java program java-introcs HelloWorld (with our standard libraries) file globbing javac *.java Java compiler version javac -version Java runtime version java -version 17 Command-line arguments, redirection, and piping Action Mac OS X Terminal Windows Command Prompt command-line arguments java Program arg1 arg2 redirect standard input java Program < input.txt redirect standard input java Program > output.txt piping java Program1 | java Program2 view contents, one more < input.txt screenful at a time java Program | more java Program1 < input.txt | more combinations java Program < input.txt > output.txt java Program1 arg1 | java Program2 arg2 terminate program <Ctrl-C> signal end-of-file <Ctrl-D> <Ctrl-Z> (when typing standard input) 18.
Recommended publications
  • Unix Command Line; Editors
    Unix command line; editors Karl Broman Biostatistics & Medical Informatics, UW–Madison kbroman.org github.com/kbroman @kwbroman Course web: kbroman.org/AdvData My goal in this lecture is to convince you that (a) command-line-based tools are the things to focus on, (b) you need to choose a powerful, universal text editor (you’ll use it a lot), (c) you want to be comfortable and skilled with each. For your work to be reproducible, it needs to be code-based; don’t touch that mouse! Windows vs. Mac OSX vs. Linux Remote vs. Not 2 The Windows operating system is not very programmer-friendly. Mac OSX isn’t either, but under the hood, it’s just unix. Don’t touch the mouse! Open a terminal window and start typing. I do most of my work directly on my desktop or laptop. You might prefer to work remotely on a server, instead. But I can’t stand having any lag in looking at graphics. If you use Windows... Consider Git Bash (or Cygwin) or turn on the Windows subsystem for linux 3 Cygwin is an effort to get Unix command-line tools in Windows. Git Bash combines git (for version control) and bash (the unix shell); it’s simpler to deal with than Cygwin. Linux is now accessible in Windows 10, but you have to enable it. If you use a Mac... Consider Homebrew and iTerm2 Also the XCode command line tools 4 Homebrew is a packaging system; iTerm2 is a Terminal replacement. The XCode command line tools are a must for most unixy things on a Mac.
    [Show full text]
  • Getting to Grips with Unix and the Linux Family
    Getting to grips with Unix and the Linux family David Chiappini, Giulio Pasqualetti, Tommaso Redaelli Torino, International Conference of Physics Students August 10, 2017 According to the booklet At this end of this session, you can expect: • To have an overview of the history of computer science • To understand the general functioning and similarities of Unix-like systems • To be able to distinguish the features of different Linux distributions • To be able to use basic Linux commands • To know how to build your own operating system • To hack the NSA • To produce the worst software bug EVER According to the booklet update At this end of this session, you can expect: • To have an overview of the history of computer science • To understand the general functioning and similarities of Unix-like systems • To be able to distinguish the features of different Linux distributions • To be able to use basic Linux commands • To know how to build your own operating system • To hack the NSA • To produce the worst software bug EVER A first data analysis with the shell, sed & awk an interactive workshop 1 at the beginning, there was UNIX... 2 ...then there was GNU 3 getting hands dirty common commands wait till you see piping 4 regular expressions 5 sed 6 awk 7 challenge time What's UNIX • Bell Labs was a really cool place to be in the 60s-70s • UNIX was a OS developed by Bell labs • they used C, which was also developed there • UNIX became the de facto standard on how to make an OS UNIX Philosophy • Write programs that do one thing and do it well.
    [Show full text]
  • Libreoffice Spreadsheet Print Rows at Top
    Libreoffice Spreadsheet Print Rows At Top Elmer ingenerating goldenly. Partha remains grumbling: she keratinizing her hydroxylamines outthinking too lyrically? Epicedial and shoed Zachary descale some minxes so forwardly! Using this method will be printed page in You print page styles to printing. If you want to reed a bid number, simply copy and you. Printing Rows or Columns on opportunity Page LibreOffice Help. Go through check boxes to electronic and printed Microsoft Word documents However sure you create header rows in your Microsoft Word source documents you Apr 27 2020 The quote way to insert button Excel worksheet into word Word doc is by. Ole links at top. You as also choose to either realize a style directly to a burst or lower a template and reuse it just apply styles to multiple cells. That curve that it the files are moved to somewhere different location the connections stop working. The top row command on libreoffice spreadsheet print rows at top. Libreoffice Getting started. Using conditional formatting, and personal. Finally have to print page up rows at top row that has support this spreadsheet we can edit tab choose a fixed. Freezing Rows or Columns as Headers To promise both horizontally and vertically select such cell level is last the good and smile the right of the column here you want last freeze Choose Window scale To deactivate choose Window to again. You faint not see any visible change plan your spreadsheet. Use print page command in spreadsheets can leave the. When the column or column widths will see is a method to the edit mode with this data much again or make a sheet and notes you? With console mode, feature a yellow note type appear indicating the arguments that are expected for the function.
    [Show full text]
  • Improving Code Autocompletion with Transfer Learning
    Improving Code Autocompletion with Transfer Learning Wen Zhou Seohyun Kim Vijayaraghavan Murali Gareth Ari Aye Facebook Inc. Facebook Inc. Facebook Inc. Facebook Inc. Menlo Park, U.S.A. Menlo Park, U.S.A. Menlo Park, U.S.A. Menlo Park, U.S.A. [email protected] [email protected] [email protected] [email protected] Abstract—Software language models have achieved promising results predicting code completion usages, and several industry studies have described successful IDE integrations. Recently, accuracy in autocompletion prediction improved 12.8% [1] from training on a real-world dataset collected from programmers’ IDE activity. But what if limited examples of IDE autocompletion in the target programming language are available for model training? In this paper, we investigate the efficacy of pretraining autocompletion models on non-IDE, non-autocompletion, and different-language example code sequences. We find that these unsupervised pretrainings improve model accuracy by over 50% on very small fine-tuning datasets and over 10% on 50k labeled examples. We confirm the real-world impact of these pretrainings in an online setting through A/B testing on thousands of IDE autocompletion users, finding that pretraining is responsible for increases of up to 6.63% autocompletion usage. Index Terms—Machine learning, neural networks, software language models, naturalness, code completion, integrated de- velopment environments, software tools I. INTRODUCTION Fig. 1: Example of autocomplete in an IDE. Autocompletion is the most frequently used IDE feature [2]. Significant attention has been given to improving suggestion prediction through machine learning [3]–[6] by feeding code to models as a sequence of tokens or even AST nodes [7].
    [Show full text]
  • Linking + Libraries
    LinkingLinking ● Last stage in building a program PRE- COMPILATION ASSEMBLY LINKING PROCESSING ● Combining separate code into one executable ● Linking done by the Linker ● ld in Unix ● a.k.a. “link-editor” or “loader” ● Often transparent (gcc can do it all for you) 1 LinkingLinking involves...involves... ● Combining several object modules (the .o files corresponding to .c files) into one file ● Resolving external references to variables and functions ● Producing an executable file (if no errors) file1.c file1.o file2.c gcc file2.o Linker Executable fileN.c fileN.o Header files External references 2 LinkingLinking withwith ExternalExternal ReferencesReferences file1.c file2.c int count; #include <stdio.h> void display(void); Compiler extern int count; int main(void) void display(void) { file1.o file2.o { count = 10; with placeholders printf(“%d”,count); display(); } return 0; Linker } ● file1.o has placeholder for display() ● file2.o has placeholder for count ● object modules are relocatable ● addresses are relative offsets from top of file 3 LibrariesLibraries ● Definition: ● a file containing functions that can be referenced externally by a C program ● Purpose: ● easy access to functions used repeatedly ● promote code modularity and re-use ● reduce source and executable file size 4 LibrariesLibraries ● Static (Archive) ● libname.a on Unix; name.lib on DOS/Windows ● Only modules with referenced code linked when compiling ● unlike .o files ● Linker copies function from library into executable file ● Update to library requires recompiling program 5 LibrariesLibraries ● Dynamic (Shared Object or Dynamic Link Library) ● libname.so on Unix; name.dll on DOS/Windows ● Referenced code not copied into executable ● Loaded in memory at run time ● Smaller executable size ● Can update library without recompiling program ● Drawback: slightly slower program startup 6 LibrariesLibraries ● Linking a static library libpepsi.a /* crave source file */ … gcc ..
    [Show full text]
  • AR400 User Guide 2.7.1
    AR400 SERIES User Guide Software Release 2.7.1 AR410 AR440S AR441S AR450S AR400 Series Router User Guide for Software Release 2.7.1 Document Number C613-02021-00 REV F. Copyright © 2004 Allied Telesyn International Corp. 19800 North Creek Parkway, Suite 200, Bothell, WA 98011, USA. All rights reserved. No part of this publication may be reproduced without prior written permission from Allied Telesyn. Allied Telesyn International Corp. reserves the right to make changes in specifications and other information contained in this document without prior written notice. The information provided herein is subject to change without notice. In no event shall Allied Telesyn be liable for any incidental, special, indirect, or consequential damages whatsoever, including but not limited to lost profits, arising out of or related to this manual or the information contained herein, even if Allied Telesyn has been advised of, known, or should have known, the possibility of such damages. All trademarks are the property of their respective owner. Contents CHAPTER 1 Introduction Why Read this User Guide? ............................................................................... 7 Where To Find More Information ...................................................................... 8 The Documentation Set .............................................................................. 8 Technical support .............................................................................................. 9 Features of the Router .....................................................................................
    [Show full text]
  • The Linux Command Line
    The Linux Command Line Fifth Internet Edition William Shotts A LinuxCommand.org Book Copyright ©2008-2019, William E. Shotts, Jr. This work is licensed under the Creative Commons Attribution-Noncommercial-No De- rivative Works 3.0 United States License. To view a copy of this license, visit the link above or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042. A version of this book is also available in printed form, published by No Starch Press. Copies may be purchased wherever fine books are sold. No Starch Press also offers elec- tronic formats for popular e-readers. They can be reached at: https://www.nostarch.com. Linux® is the registered trademark of Linus Torvalds. All other trademarks belong to their respective owners. This book is part of the LinuxCommand.org project, a site for Linux education and advo- cacy devoted to helping users of legacy operating systems migrate into the future. You may contact the LinuxCommand.org project at http://linuxcommand.org. Release History Version Date Description 19.01A January 28, 2019 Fifth Internet Edition (Corrected TOC) 19.01 January 17, 2019 Fifth Internet Edition. 17.10 October 19, 2017 Fourth Internet Edition. 16.07 July 28, 2016 Third Internet Edition. 13.07 July 6, 2013 Second Internet Edition. 09.12 December 14, 2009 First Internet Edition. Table of Contents Introduction....................................................................................................xvi Why Use the Command Line?......................................................................................xvi
    [Show full text]
  • Sequence Model Design for Code Completion in the Modern IDE
    Sequence Model Design for Code Completion in the Modern IDE Gareth Ari Aye Gail E. Kaiser Google Inc., Columbia University Columbia University [email protected] [email protected] ABSTRACT 1 INTRODUCTION Code completion plays a prominent role in modern integrated de- Code completion is a tremendously popular tool for coding assis- velopment environments (IDEs). Machine learning has become tance, implemented across a wide range of programming languages ubiquitous in analogous natural language writing and search so- and environments. In An Empirical Investigation of Code Comple- ware, surfacing more relevant autocompletions and search sug- tion Usage by Professional Soware Developers, Marasoiu et al. map gestions in fewer keystrokes. Prior research has reported training out the diversity of use cases it fullls for programmers, including high-accuracy, deep neural networks for modeling source code, but correctness checking, typing assistance, and API search [24]. A lile aention has been given to the practical constraints imposed study of programmers’ behaviors within the Eclipse IDE found by interactive developer tools. that autocomplete was used up to several times per minute [28], In particular, neural language models for source code modeling as oen as copy-paste! Historically, completion suggestions have like the one described in Maybe Deep Neural Networks are the Best been based primarily on static analysis and, as a result, suered Choice for Modeling Source Code[20] are framed around code comple- from low relevance [9]. Applying the constraints imposed by a tion, but only report accuracy of next-token prediction. However, programming language’s grammar and type system produces all in order for a language model (LM) to work well within real-world valid suggestions but says nothing about which are likely.
    [Show full text]
  • BASIC UNIX COMMANDS FILES and DIRECTORIES All Information Is Stored in files
    BASIC UNIX COMMANDS FILES AND DIRECTORIES All information is stored in files. File names and COMMANDS commands are case sensitive. Case matters. Files Commands are what you type at the prompt. Com- are contained in directories. You start out in your mands have arguments on which they operate. For own home directory, and your prompt usually tells example, in rm temp, the command is rm and the ar- its name. At any given time, one of these directories gument is temp; this command removes the file called is your working directory, the one you are in. temp. Here I put arguments in UPPER CASE. Thus, You can refer to files in your working directory by words such as FILE are taken to stand for some other just their names. You can refer to a file that is in a word, such as temp. In the following list, I use [ ] for subdirectory by giving a subdirectory name, a slash, optional arguments that are not typicaly used. and the file name, e.g., Mail/baron. You can refer to Commands have options that are controlled with any file on the computer by giving its full name, start- switches, which are usually letters following a single ing with a slash, such as /home7/b/baron/mbox. dash. Usually you can write several letters after one dash. For example ls -l lists files in a long format, If the file is a program, typing its name will run it. with more information. ls -a lists all the files, in- (That is what commands do.) If the program is some- cluding those that begin with ., which are usually thing you have just written and is in the director you files used by various programs.
    [Show full text]
  • Poisoning Vulnerabilities in Neural Code Completion*
    You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completion* Roei Schuster Congzheng Song Eran Tromer Vitaly Shmatikov Tel Aviv University Cornell University Tel Aviv University Cornell Tech Cornell Tech Columbia University [email protected] [email protected] [email protected] [email protected] Abstract significantly outperform conventional autocompleters that Code autocompletion is an integral feature of modern code rely exclusively on static analysis. Their accuracy stems from editors and IDEs. The latest generation of autocompleters the fact that they are trained on a large number of real-world uses neural language models, trained on public open-source implementation decisions made by actual developers in com- code repositories, to suggest likely (not just statically feasible) mon programming contexts. These training examples are completions given the current context. typically drawn from open-source software repositories. We demonstrate that neural code autocompleters are vulner- Our contributions. First, we demonstrate that code autocom- able to poisoning attacks. By adding a few specially-crafted pleters are vulnerable to poisoning attacks. Poisoning changes files to the autocompleter’s training corpus (data poisoning), the autocompleter’s suggestions for a few attacker-chosen con- or else by directly fine-tuning the autocompleter on these files texts without significantly changing its suggestions in all other (model poisoning), the attacker can influence its suggestions contexts and, therefore, without reducing the overall accuracy. for attacker-chosen contexts. For example, the attacker can We focus on security contexts, where an incorrect choice can “teach” the autocompleter to suggest the insecure ECB mode introduce a serious vulnerability into the program.
    [Show full text]
  • Zypper Cheat Sheet Or Type M an Zypper on a Terminal
    More Information: Page 1 Zypper Cheat Sheet https://en.opensuse.org/SDB:Zypper_usage or type m an zypper on a terminal For Zypper version 1.0.9 Package Management Source Packages and Build Dependencies Basic Help Selecting Packages zypper source-install or zypper si Examples: zypper #list the available global options and commands By capability name: zypper si zypper zypper help [command] #Print help for a specific command zypper in 'perl(Log::Log4perl)' Install only the source package zypper shell or zypper sh #Open a zypper shell session zypper in qt zypper in -D zypper By capability name and/or architecture and/or version Install only the build dependencies zypper in 'zypper<0.12.10' Repository Management zypper in -d zypper zypper in zypper.i586=0.12.11 Listing Defined Repositories By exact package name (--name) Updating Packages zypper in -n ftp zypper repos or zypper lr By exact package name and repository (implies --name) zypper update or zypper up Examples: zypper in factory:zypper Examples: zypper lr -u #include repo URI on the table By package name using wildcards zypper up #update all installed packages zypper lr -P #include repo priority and sort by it zypper in yast*ftp* with newer version as far as possible By specifying a .rpm file to install zypper up libzypp zypper #update libzypp Refreshing Repositories zypper in skype-2.0.0.72-suse.i586.rpm and zypper zypper refresh or zypper ref zypper in sqlite3 #update sqlite3 or install Installing Packages Examples: if not yet installed zypper ref packman main #specify repos to be
    [Show full text]
  • Mastering Powershellpowershell
    CopyrightCopyright © 2009 BBS Technologies ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored, or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems except as permitted under Section 107 or 108 of the 1976 United States Copyright Act without the prior written permission of the publisher. For permission to use material from the text please contact Idera at [email protected]. Microsoft® Windows PowerShell® and Microsoft® SQL Server® are registered trademarks of Microsoft Corporation in the United Stated and other countries. All other trademarks are the property of their respective owners. AboutAbout thethe AuthorAuthor Dr. Tobias Weltner is one of the most visible PowerShell MVPs in Europe. He has published more than 80 books on Windows and Scripting Techniques with Microsoft Press and other publishers, is a regular speaker at conferences and road shows and does high level PowerShell and Scripting trainings for companies throughout Europe. He created the powershell.com website and community in an effort to help people adopt and use PowerShell more efficiently. As software architect, he created a number of award-winning scripting tools such as SystemScripter (VBScript), the original PowerShell IDE and PowerShell Plus, a comprehensive integrated PowerShell development system. AcknowledgmentsAcknowledgments First and foremost, I’d like to thank my family who is always a source of inspiration and encouragement. A special thanks to Idera, Rick Pleczko, David Fargo, Richard Giles, Conley Smith and David Twamley for helping to bring this book to the English speaking world.
    [Show full text]