Unix Environment Input Output 2  List Content (ls) ◦ ls (list current directory) ◦ ls –all (include hidden files/folders)  Make directory (mkdir) ◦

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

CS1020 Week 3: 29th January 2015.
A Guide to Unix Using Linux Fourth Edition
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey.
Program Development Tools IDE vs point tools Two tool flavors exist for developing embedded software: -IDEs: (Integrated Development Environments) i.e.,
VIM: The basics Tang Wai-Chung, Matthew (MaFai) 29/12/2006.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Chapter 5 Editing Text Files
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
Strings as objects Strings are objects. Each String is an instance of the class String They can be constructed thus: String s = new String("Hi mom!");
CS1020: Intro Workshop. Topics CS1020Intro Workshop Login to UNIX operating system 2. …………………………………… 3. …………………………………… 4. …………………………………… 5. ……………………………………
Starting Vi Opening an existing file vi filename Creating a new file vi filename In your workshop directory, create a new file called mysong vi mysong.
1 CSE 142 Lecture Notes Interactive Programs with Scanner Chapter 4 Suggested reading: Suggested self-checks: Section 4.10 #1-4 These lecture.
Editing Java programs with the BlueJ IDE. Working environments to develop (= write) programs There are 2 ways to develop (write) computer programs: 1.Using.
CSCI 330 T HE UNIX S YSTEM Editing files. E DITOR C ONCEPTS Editing a file is to modify the content of a file Text editor: Enter and modify text in a.
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Chapter 3 Mastering Editors
Basic Text Processing, Redirection and Pipes. 222 Lecture Overview  Basic text processing commands head, tail, wc  Redirection and pipes  Getting to.
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
The UNIX development environment CS 400/600 – Data Structures.
T HE VI EDITOR. vi has 2 modes: command mode (initial or "default" mode) insert mode [Esc] is used to switch to command mode. In general, vi commands:
Console Input & Output CSS 161: Fundamentals of Computing Joe McCarthy 1.
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
UNIX Intro vi  vi is the standard UNIX text editor v Contents 1.Why use vi ? 2. vi Basics 3.Moving Around 4.Inserting Text.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
Text editors Why should I use an editor ? It is very important to able to use at least one text mode editor a text mode editor is so useful on remote machines.
Unix Editors. u Editors in Unix come in two general flavours: –modal editors have "modes" v generally input mode and command mode –input mode allows entry.
Tony Kombol.  Why text edit?  Many programs and features require configuration ▪ Configuration is kept in files ▪ Usually in the /etc directory  Changes.
Unix Session IV.
Text Editing February 2 nd, 2004 Class Meeting 3.
Chapter Three Text Editing1 System Programming Text Editing.
VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file.
1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Linux Class #03. File Access Permissions Types of users in Linux: Local User (u) Group User (g) Other User (o) Each User can have 3 types of permissions:
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
THE vi EDITOR. Introduction There are three editors available in almost all versions of Unix: ed, ex and vi. The ed program is the original editor that.
Text editing and more basic commands CS 2204 Class meeting 3 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session.
Agenda Using vi Editor Starting vi Session Command / Input Modes
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
 Simple UNIX commands  I/O techniques in C++  Solutions to Lab#0 problems  Solutions to Lab#1 problems 1.
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
Purdue Linux Users Group Presents Linux 201: Session 1 Everything you ever wanted to do in VIM Thor Smith.
CS:414 introduction to Unix and Linux
Introduction to programming in java
Input/Output.
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
Vi Editor.
Vim.
Vi Introduction Tony Kombol.
Linux 104 Training Module File Editing.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Technical University of Kosice
Program Development with Vim
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
Java Intro.
Introduction to Java Brief history of Java Sample Java Program
Review of Previous Lesson
CSCI The UNIX System Editing files
Presentation transcript:

Unix Environment Input Output 2

 List Content (ls) ◦ ls (list current directory) ◦ ls –all (include hidden files/folders)  Make directory (mkdir) ◦ mkdir[directory name]  Change Directory (cd) ◦ cd [directory name] ◦ Use [Tab] button for auto-completion  Remove Directory Entries (rm) ◦ rm [file/folder name]  Java Compile (javac) ◦ javac *.java (shortcut to compile all java files) ◦ Similar effect as make command 3

 Edit File in VIM (vim) ◦ vim [file name]  Running Java Program (java) ◦ java [program name without extension] ◦ java [class name] [output file] (input/output redirection)  Checking for Difference (diff) ◦ diff [file name] [file name] ◦ Difference in a single space or an extra line will be noted  Manual (man) ◦ man [command name] ◦ When you are not sure what the command does, or what parameter it expects 4

  3 main modes ◦ Normal/Command mode (default)  For navigation and manipulation of text  Everything the user types is interpreted as commands  e.g. “h” to move left, “x” to remove a character ◦ Insert mode (i, I, a, A, o, O)  For inserting new text  Exit Insert mode to normal mode using Esc ◦ Visual mode  For highlighting texts (useful for copy and paste) 5

 Cursor movement (Only in command mode!) ◦ h: move cursor left ◦ j: move cursor down ◦ k: move cursor up ◦ l: move cursor right ◦ 0: jump to start of line ◦ $ jump to end of line ◦ G: end of file ◦ 5G: go to line 5 6

 Insert mode – insert/append text  From command mode ◦ i: insert before cursor ◦ I: insert at the beginning of the line ◦ a: append after cursor ◦ A: append at the end of line ◦ o: open a new line below the current line ◦ O: open a new line above the current line ◦ ea: append at end of word 7

 Editing ◦ s: delete character and substitute text ◦ cc: replace(change) entire line ◦ cw: replace(change) to end of word ◦ c$: replace(change) to end of line ◦ x: cut character ◦ u: undo ◦ r: replace one character ◦ R: replace all character until ESC 8

 Visual mode ◦ v: start visual mode, mark lines, then yank (y) ◦ V: linewise ◦ Ctrl-v: visual block mode  Copy and Pasting ◦ Copy/yank: y  Copy one line: yy, 2 lines: 2yy, to end of line: y$, one word: yw ◦ Cut/delete: d  Cut one line: dd, 2 lines: 2dd, to end of line: d$, one word: dw ◦ Paste: p 9

 Search ◦ /[pattern] → Search for the pattern ◦ n → Search next in the same direction ◦ N → Search next in the opposite direction  Saving and quitting ◦ Save (write): :w ◦ Save and quit: :wq ◦ Quit without saving: :q!  Tip ◦ Open 2 windows, one to code, other to compile ◦ gg=G : indent all lines 10

 Write a Java program that prints “Hello World” out to the console  In Vim  Compile and execute the program  vim [name of file].java 11

Unix Environment Input Output 12

 Scanner Class ◦ Initialization: Scanner sc = new Scanner (System.in); ◦ hasNext() and variants  Check if there exists another input ◦ next() and variants  Get the next input ◦ Variants: Int, Line, Double example: hasNextInt() and nextLine() ◦ There is NO nextChar() and hasNextChar() variant 13

 Finds and returns the next complete token from this scanner.  A complete token is preceded and followed by input that matches the delimiter pattern.  By default: delimiter pattern is whitespace 14

 next() ◦ reads the next token as a string  nextInt() ◦ reads the next token as an integer. If it is not: error  nextLine() ◦ Advance scanner, read and return all in current line (until next newline character) 15

 Input: 1 fish 2 fish 3 fish 4 fish /n end  next(): ◦ 1 (as a string)  nextInt(): ◦ error  next(): ◦ fish  nextInt(): ◦ 2 (as an integer)  nextLine(): ◦ fish 3 fish 4 fish 16

o Type 1: Number of Operations is specified o Type 2: Read until Terminating Special Character o Type 3: Read until End of File 17

public static void main(String[] args) { // … Code Section Omitted // … Other Initialization Scanner sc = new Scanner(System.in); int numOps = sc.nextInt(); for (int i=0; i<numOps; i++) { // Read Other Inputs } // … Code Section Omitted } 18

 Steps: 1. Initialize the Scanner Class 2. Read the First Input 3. Loop until Terminating Special Character encountered 4. Read into tempInput again 19 Scanner sc = new Scanner(System.in); String tempInput = sc.next(); while (!tempInput.equals(TERMINATING_CHAR)) { // Read Other Input (if exist) // Step 4 Here } tempInput = sc.next();

20 public static void main(String[] args) { // … Code Section Omitted // … Other Initialization Scanner sc = new Scanner(System.in); String tempInput = sc.next(); while (!tempInput.equals(TERMINATING_CHAR)) { // Read Other Input tempInput = sc.next(); } // … Code Section Omitted }

 Steps: 1. Initialize the Scanner Class 2. Loop until End of File 21 Scanner sc = new Scanner(System.in); while (sc.hasNext()) { // Read Other Input }

22 public static void main(String[] args) { // … Code Section Omitted // … Other Initialization Scanner sc = new Scanner(System.in); while (sc.hasNext()) { // Read Other Inputs } // … Code Section Omitted }

 Combines two or more different input types into a single program ◦ e.g.: Type 3 Input on the Outside, Type 1 Input on the Inside. 23 public static void main(String[] args) { // … Code Section Omitted // … Other Initialization Scanner sc = new Scanner (System.in); while (sc.hasNext()) { int numOps = sc.nextInt(); for (int i=0; i<numOps; i++) { // Read Other Inputs } // … Code Section Omitted }

Unix Environment Input Output 24

 With Extra Line at the End  Without Extra Line at the End 25 System.out.println("Output String Here"); System.out.print("Output String Here"); System.out.print("Output String Here\n");

 One per Line, Terminate with End Line  One per Line, Terminate without End Line 26 for (int i=0; i<numOutput; i++) { System.out.println(outputString); } System.out.print(outputString); for (int i=1; i<numOutput; i++) { System.out.println(); System.out.print(outputString); }

 Matrix Type, End Space  Matrix Type, End Not Space 27 for (int i=0; i<numLine; i++) { for (int j=0; j<numOut; j++) { System.out.print (output + " "); } System.out.println(); } for (int i=0; i<numLine; i++) { System.out.print (output); for (int j=1; j<numOut; j++) { System.out.print (" " + output); } System.out.println(); }

END OF FILE