Reading and manipulating files

Similar documents
5/8/2012. Exploring Utilities Chapter 5

Advanced training. Linux components Command shell. LiLux a.s.b.l.

Practical Session 0 Introduction to Linux

Week Overview. Simple filter commands: head, tail, cut, sort, tr, wc grep utility stdin, stdout, stderr Redirection and piping /dev/null file

Introduction to Linux

5/20/2007. Touring Essential Programs

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Introduction. File System. Note. Achtung!

Open up a terminal, make sure you are in your home directory, and run the command.

Lab 2: Linux/Unix shell

ITST Searching, Extracting & Archiving Data

A Brief Introduction to the Linux Shell for Data Science

bash, part 3 Chris GauthierDickey

Introduction: What is Unix?

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Chapter-3. Introduction to Unix: Fundamental Commands

EECS2301. Lab 1 Winter 2016

Linux Bootcamp Fall 2015

Introduction to UNIX command-line II

CS 25200: Systems Programming. Lecture 11: *nix Commands and Shell Internals

MBV4410/9410 Fall Bioinformatics for Molecular Biology. More Unix

Bioinformatics? Reads, assembly, annotation, comparative genomics and a bit of phylogeny.

Linux Tutorial #4. Redirection. Output redirection ( > )

Linux environment. Graphical interface X-window + window manager. Text interface terminal + shell

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Unix Tools / Command Line

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

Module 8 Pipes, Redirection and REGEX

Linux Command Line Primer. By: Scott Marshall

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Chapter 4. Unix Tutorial. Unix Shell

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

Utilities. September 8, 2015

Command Line Interface The basics

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

UNIX files searching, and other interrogation techniques

Getting your department account

Operating Systems and Using Linux. Topics What is an Operating System? Linux Overview Frequently Used Linux Commands

Linux Command Line Interface. December 27, 2017

Linux Introduction Martin Dahlö Valentin Georgiev

Introduction to Linux

Linux II and III. Douglas Scofield. Crea-ng directories and files 18/01/14. Evolu5onary Biology Centre, Uppsala University

Lab Working with Linux Command Line

Unix/Linux Operating System. Introduction to Computational Statistics STAT 598G, Fall 2011

Chapter 1 - Introduction. September 8, 2016

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Introduction to Unix: Fundamental Commands

Introduction to UNIX. Introduction EECS l UNIX is an operating system (OS). l Our goals:

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

COMS 6100 Class Notes 3

Common File System Commands

Project 4: File System Implementation 1

File Commands. Objectives

The input can also be taken from a file and similarly the output can be redirected to another file.

Review of Fundamentals

Introduction to Linux Spring 2014, Section 02, Lecture 3 Jason Tang

Mills HPC Tutorial Series. Linux Basics I

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

COSC UNIX. Textbook. Grading Scheme

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

Files

CSC 2500: Unix Lab Fall 2016

CS160A EXERCISES-FILTERS2 Boyd

Unix Tutorial Haverford Astronomy 2014/2015

IMPORTANT: Logging Off LOGGING IN

UNIX, GNU/Linux and simple tools for data manipulation

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Linux Text Utilities 101 for S/390 Wizards SHARE Session 9220/5522

Introduction to Linux Environment. Yun-Wen Chen

Parts of this tutorial has been adapted from M. Stonebank s UNIX Tutorial for Beginners (

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

Advanced Linux Commands & Shell Scripting

find starting-directory -name filename -user username

Lab #2 Physics 91SI Spring 2013

85321, Systems Administration Chapter 6: The shell

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash

Linux Shell Script. J. K. Mandal

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

Scripting Languages Course 1. Diana Trandabăț

- c list The list specifies character positions.

Unix basics exercise MBV-INFX410

Part III. Shell Config. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

CENG 334 Computer Networks. Laboratory I Linux Tutorial

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

Shell Programming Overview

CST Algonquin College 2

Linux II and III. Douglas Scofield. Crea-ng directories and files 15/08/16. Evolu6onary Biology Centre, Uppsala University

Creating a Shell or Command Interperter Program CSCI411 Lab

Unix/Linux Primer. Taras V. Pogorelov and Mike Hallock School of Chemical Sciences, University of Illinois

LING 408/508: Computational Techniques for Linguists. Lecture 5

Introduction. Let s start with the first set of slides

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

Introduction to Unix

commandname flags arguments

Connecting to ICS Server, Shell, Vim CS238P Operating Systems fall 18

STATS Data Analysis using Python. Lecture 15: Advanced Command Line

Transcription:

Reading and manipulating files

Goals By the end of this lesson you will be able to Read files without using text editors Access specific parts of files Count the number of words and lines in a file Sort data within files Examine the diference between files Determine what type a file is Redirect input and output with respect to files

Types of files There are multiple types of files Text files contain human-readable text Binary files mainly consist of encoded machine code that is not readable by humans Most commands for reading files in Linux can or should only be used on text files

Displaying a file Three primary commands: cat filename dump file to terminal (without filename, just echos what you type ctrl-c to exit) more filename page-by-page look at file Enter to go down a little Space to go down a page b to go up q or ctrl-c to exit less filename page-by-page look at file Similar to above, but more intuitive keys q to exit

Displaying beginning & end of file Two commands head filename show first 10 lines of file tail filename show last 10 lines of file Other options exist (use the man page!), but the most useful is -n to change from the default number of lines

File diferences diff filea fileb can be used to find the diferences in files No output indicates the files are identical If output is generated, it will provide details about the specific lines Options exist for: Displaying diferences side-by-side instead of sequentially Ignoring diferences in whitespace and case Many other things You can also provide two directories to compare files within

Counting lines, words, and bytes wc filename displays the number of lines, words, and bytes, in that order, for a file Lines are delimited by newline characters Words are delimited by spaces Bytes are delimited by characters If you don t need all that information, options are useful Don t forget the wildcard * use it to count all the lines in the current directory

File information file filename will tell you what type of file it is Not guaranteed to be accurate, but usually is Want to know how it works? Check the man page

touch touch filename will do two primary things: If filename does not exist, it will create the file and it will be empty If filename does exist, it will update the access & modification time to the current time touch can also be used to change the access and modification times individually as well as set them to any arbitrary time

Sorting a text file sort filename will display the file with lines sorted By default lines are sorted according to the first character (if they match, it compares the second character, etc.) Numbers come before letters Modify the sort using options to sort in reverse Use -o option to output to a file sort inputfile -o outputfile (these can be the same!) You can give multiple input files and it will sort all of the data: sort filea fileb

Redirecting output to a file If want to have output go to a file instead of to the terminal you can redirect the output using > (angle bracket or greater than) Example: ls -l > filelist.txt cat filea > fileb (efectively cp) sort file > output (efectively sort file -o output)./a.out > output cat > filename (use ctrl-c to exit and save) Use >> to append to the file instead

Redirecting input If a command or program would typically require input from the keyboard you can redirect input from a file instead using < It s somewhat common to use this to provide input to a program that you write, either for general use or testing purposes if lots of keyboard input would be cumbersome to type out Another option for taking input from a file into a program you write is to open & process the file from within the program

Redirecting output to a command/program We ve investigated redirecting output to a file, but what if we d rather have the output of one command/program to the input of another command/program? Piping with the character will accomplish this It is typically above the enter key on your keyboard Examples: Count the number of characters in a directory listing (ls and wc) Examine a long directory listing one page at a time (ls and less)

Exploration When is it better/easier to use cat versus less? Examine various files using file Become familiar with redirecting input and output as well as piping these are critical tools for efectively using Linux and programming