Files

Similar documents
CSCI 2132 Software Development. Lecture 4: Files and Directories

5/8/2012. Creating and Changing Directories Chapter 7

Chapter-3. Introduction to Unix: Fundamental Commands

UNIX File Hierarchy: Structure and Commands

Chapter 1 - Introduction. September 8, 2016

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Files and Directories

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

Week 2 Lecture 3. Unix

Unix Handouts. Shantanu N Kulkarni

Mills HPC Tutorial Series. Linux Basics I

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

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

commandname flags arguments

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

Introduction to Unix: Fundamental Commands

Introduction: What is Unix?

CS Unix Tools. Lecture 2 Fall Hussam Abu-Libdeh based on slides by David Slater. September 10, 2010

Basic Unix Command. It is used to see the manual of the various command. It helps in selecting the correct options

Introduction to Linux

CS246 Spring14 Programming Paradigm Notes on Linux

A Brief Introduction to Unix

Operating Systems, Unix Files and Commands SEEM

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Getting your department account

SECTION -C. Getting Started with UNIX

Filesystem and common commands

The Unix Shell. Pipes and Filters

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

Introduction to UNIX I: Command Line 1 / 21

Essential Linux Shell Commands

Linux & Shell Programming 2014

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

Course 144 Supplementary Materials. UNIX Fundamentals

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

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Linux Shell Script. J. K. Mandal

Practical 4. Linux Commands: Working with Directories

Introduction of Linux

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

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

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

Introduction to the Linux Command Line

-1- csh cd. cd alias!! ; set prompt=" pwd % " 16 cd. 17 cd.. 18 his /home% set prompt. alias. yasuoka : root :

18-Sep CSCI 2132 Software Development Lecture 6: Links and Inodes. Faculty of Computer Science, Dalhousie University. Lecture 6 p.

Software I: Utilities and Internals. What is UNIX?

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

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

Introduc)on to Linux Session 2 Files/Filesystems/Data. Pete Ruprecht Research Compu)ng Group University of Colorado Boulder

Files (review) and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

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

Lab 2: Linux/Unix shell

Introduction to Linux

CSC UNIX System, Spring 2015

LOG ON TO LINUX AND LOG OFF

Introduction to Linux Workshop 1

Unix Workshop Aug 2014

Physics REU Unix Tutorial

A Brief Introduction to the Linux Shell for Data Science

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Perl and R Scripting for Biologists

Introduction to Linux

Permission and Ownership

Commands are in black

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

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

Common UNIX Commands. Unix. User Interfaces. Unix Commands Winter COMP 1270 Computer Usage II 9-1. Using UNIX. Unix has a command line interface

An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories

This is Lab Worksheet 3 - not an Assignment

CSC209. Software Tools and Systems Programming.

Working with Basic Linux. Daniel Balagué

Assume that username is cse. The user s home directory will be /home/cse. You may remember what the relative pathname for users home directory is: ~

Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

5/20/2007. Touring Essential Programs

Computer Systems and Architecture

LAB 8 (Aug 4/5) Unix Utilities

Introduction to Linux

LAB 8 (Aug 4/5) Unix Utilities

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

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

Basic Linux Commands. Srihari Kalgi M.Tech, CSE (KReSIT), IIT Bombay. May 5, 2009

Std: XI CHAPTER-3 LINUX

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

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

Introduction to Linux

Introduction to Linux

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

Scripting Languages Course 1. Diana Trandabăț

Unix Introduction to UNIX

CS4350 Unix Programming. Outline

CSCI 2132 Software Development. Lecture 5: File Permissions

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

Lec 1 add-on: Linux Intro

ACS Unix (Winter Term, ) Page 92

Computer Systems and Architecture

Transcription:

http://www.cs.fsu.edu/~langley/cop3353-2013-1/reveal.js-2013-02-11/02.html?print-pdf 02/11/2013 10:55 AM Files A normal "flat" file is a collection of information. It's usually stored somewhere reasonably non-volatile when you turn off your power, it's nice to still have your files around when you power back up.

http://www.cs.fsu.edu/~langley/cop3353-2013-1/reveal.js-2013-02-11/02.html?print-pdf 02/11/2013 10:59 AM You can reasonably view a Unix file as a stream of bytes; as Kernighan and Pike put it in the The Unix Programming Environment, "A file is a sequence of bytes.... No structure is imposed on a file by the system, and no meaning is attached to its contents the meaning of the bytes depends solely on the programs that interpret the file.... Magnetic tapes, mail messages, characters typed on the keyboard, line printer output, data flowing in pipes each of these files is just a sequence of bytes as far as the system and the programs in it are concerned." (page 41)

http://www.cs.fsu.edu/~langley/cop3353-2013-1/reveal.js-2013-02-11/02.html?print-pdf 02/11/2013 11:00 AM Although this seems quite normal to us these days, back in the early days of Unix, such a simple view of files was not the norm; instead, many files were structured in some manner, generally by some sort of "record" scheme, though there were many other ideas floating around.

http://www.cs.fsu.edu/~langley/cop3353-2013-1/reveal.js-2013-02-11/02.html?print-pdf 02/11/2013 11:01 AM So what are some of the common ways that we interpret the contents of a file? The simplest of course for human being is simply as a text file. The simplest for a computer might be as a binary program, where its contents are loaded into memory and directly executed by a processor. Other types include PDF files, spreadsheets, SVG files, database files, and a host of other types.

http://www.cs.fsu.edu/~langley/cop3353-2013-1/reveal.js-2013-02-11/02.html?print-pdf 02/11/2013 11:01 AM But isn't there some way to indicate what the purpose of a file is? Some operating systems, for instance, have used the idea of indicating types in the file names: "letter.pdf", for instance, in such a scheme, would be a PDF file. But Unix doesn't use that sort of scheme. Instead, it has the idea of a "magic number" at the beginning of a file to indicate the file type.

http://www.cs.fsu.edu/~langley/cop3353-2013-1/reveal.js-2013-02-11/02.html?print-pdf 02/11/2013 11:02 AM We aggregate these files into what we call "directories". Directories are recursive structures, since they can also contain other directories.

02/11/2013 11:09 AM

02/11/2013 11:10 AM Pathnames We need to be able to name the locations of our files.

02/11/2013 11:11 AM The "root" is the starting point, referred to with "/"

02/11/2013 11:12 AM Sub-directories identified by name, separated by "/"

02/11/2013 11:12 AM Absolute pathnames always start with the "root" (i.e., the slash character)

02/11/2013 11:13 AM Relative pathnames are from current directory

02/11/2013 11:13 AM Going up the directory tree ".." refers to directory above "." refers to the current working directory

02/11/2013 11:13 AM Referencing user directories: ~USER represents the absolute path to USER's home directory "~/" represents the absolute path to your own home directory

02/11/2013 11:14 AM Directory Structure The leading item is called the "root", written simply as "/" Items in a subgraph are "contained" by the directories in the path leading back to the root

02/11/2013 11:14 AM Pathnames Absolute pathnames simply give directions on how to get to a node Examples of absolute pathnames: "/bin/emacs" "/home/carol/mail/" Relative pathnames are relative to the current working directory Examples of relative pathnames "Mail/" "../../bin/emacs"

02/11/2013 11:14 AM Commands When you type an initial element at a shell prompt, you might be doing one of three things: Starting some sort of aggregation, such as a loop or an "if/then" structure Invoking a "built-in", such as cd Calling a program, such as emacs

02/11/2013 11:15 AM COMMANDNAME [FLAGS] [PARAMETERS] FLAGS: Commands often accept one or more flags after command name. Each flag starts with "-" or with "--", and is separated from other flags by spaces. Individual flags often may be combined with a single "-". ls -l -a ls -la Typical command structure: PARAMETERS: Commands often accept one or more parameters. Parameters are often pathnames representing files or directories. Parameters are separated by spaces. cp -a /home/carol/mail /home/carol/mail-backup

02/11/2013 11:15 AM Finding commands Generally, you don't want to type the entire pathname for a program like Perl: /usr/bin/perl

02/11/2013 11:15 AM Instead, it would be nice to use the "relative" syntax of simply perl but you don't want to have to also first cd to /usr/bin either.

02/11/2013 11:15 AM How do we solve this dilemma? A fundamental construct of most shells is the idea of a PATH variable. The PATH variable simply lists a number of directories that we will search for commands that have no explicit path information.

02/11/2013 11:15 AM $ echo $PATH /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin This PATH means that each of the paths /usr/kerberos/bin, /usr/local/bin, /bin, and /usr/bin will be searched when an unadorned command name is invoked.

02/11/2013 11:16 AM Operating on files Command Purpose ls List files and directories cat Output a bytestream less Paginate a bytestream pr Paginate a bytestream touch Update the timestamp on a file; if the file does not exist, it is created cd Change the shell's current working directory (built-in)

02/11/2013 11:16 AM Command Purpose cp Copy files and directories mv Move files and directories rm Remove files and directories rmdir Remove empty directories mkdir Create directories

02/11/2013 11:16 AM Command Purpose wc Count lines, words, and characters in a file grep Search a file sort Sort a file head Show the initial lines of a file tail Show the terminal lines of a file cmp Find the first difference in two files diff Find the differences in two files

02/11/2013 11:16 AM Three very useful additional commands Command Purpose man Read the fine manual date Find date and time who List the people logged in

02/11/2013 11:17 AM Permissions Every file and directory has a set of permissions associated with it.

02/11/2013 11:17 AM $ ls -l /etc/hosts -rw-r--r-- 1 root root 905 Jun 16 2010 /etc/hosts $ ls -dl /etc drwxr-xr-x 105 root root 12288 Jan 15 14:24 /etc $ ls -l /usr/bin/emacs-21.4-x -rwxr-xr-x 2 root root 6649776 Apr 28 2011 /usr/bin/emacs-21.4-x $ ls -l /usr/bin/emacs lrwxrwxrwx 1 root root 19 Feb 8 2012 /usr/bin/emacs -> /usr/bin/emacs-21.4 The first component tells us about the item in the filesystem; an unadorned "-" indicates a regular file; "d" indicates a directory; "l" indicates a soft link; "s" indicates a socket; "c" is a character device file; "b" is a block device file; "p" is a named pipe.

02/11/2013 11:17 AM $ ls -l /etc/hosts -rw-r--r-- 1 root root 905 Jun 16 2010 /etc/hosts $ ls -dl /etc drwxr-xr-x 105 root root 12288 Jan 15 14:24 /etc $ ls -l /usr/bin/emacs-21.4-x -rwxr-xr-x 2 root root 6649776 Apr 28 2011 /usr/bin/emacs-21.4-x $ ls -l /usr/bin/emacs lrwxrwxrwx 1 root root 19 Feb 8 2012 /usr/bin/emacs -> /usr/bin/emacs-21.4 The next 3 characters indicate whether the owner of a file has (1) read (2) write or (3) execute permission (execute in the case of a directory means being able to cd into the directory). The second set of three characters indicate whether users in the same group as this item have read/write/execute permission; the last group of three indicates if all users (the "world") have read/write/execute permission.

02/11/2013 11:17 AM Command Reference

02/11/2013 11:17 AM ls [-a][-l][-p][-r][-r][-x] [pathname] Description: Lists the files in a directory. Options: [-a] Display all files [-l] Displays all information [-r] Reverses order [-R] Includes sub-directories Examples: ls ls -al ls -al *.exe

02/11/2013 11:18 AM touch filename Description: Immediately creates an empty file, or updates the time stamp on an existing file.

02/11/2013 11:18 AM cp [-i][-r][-r] source destination Description: Copies the contents of a file or directory to another file or directory. Options: [-a] Archive mode; preserve ownership, permissions, and any special attributes [-i] Ask before you replace [-r] Recursive copy Parameters: source - What you want to copy target - New location Example: cp.plan.plan.backup cp -r ~/public_html/* /tmp cp -a /home/carol /home/carol-backup

02/11/2013 11:18 AM mv [-i] source target Description: Renames or moves a file from one directory to another, either with the same name or a different one. Note the original file (and name) will no longer exist. This is not a copy. Options: [-i] Prompt you before replacing a file Parameters: source - what you want to copy target - where to put it Examples: mv x y mv x dir/ mv -i /etc/passwd-old /etc/passwd

02/11/2013 11:18 AM rm [-i][-r][-f] NAMES Description: Delete files. Options: [-i] Prompt you before replacing a file [-r] Recursive, deletes an entire directory and all contents and subdirectories. [-f] Forcible removal. Don't give any error messages or ask questions even if files don't exist or permissions are awkward. Parameters: NAMES - the names of what to remove Example: rm -rf / rm -i this.* rm -r /home/carol

02/11/2013 11:18 AM less [filename] Description: paginates a file or stdin.

02/11/2013 11:19 AM wc [-c][-l][-w] [NAMES] Description: Counts characters, lines, and/or words in files or stdin. Options: [-c] Number of characters [-l] Number of lines [-w] Number of words

02/11/2013 11:19 AM pwd Description: Displays the current working directory.

02/11/2013 11:19 AM cd [directory] Description: Changes current working directory. Examples: cd / cd cd /etc cd../public_html/classes

02/11/2013 11:19 AM mkdir DIRECTORIES Description: Creates new directories. Examples: mkdir classes mkdir../classes/new

02/11/2013 11:19 AM rmdir DIRECTORIES Description: Removes the specified empty directories. Will not remove a directory that has any contents. Examples: rmdir classes/ rmdir /home/carol/

02/11/2013 11:19 AM man command Description: Displays the fine manual page for a command.