Manipulating files in UNIX. Common operations of files Common operations: We will learn to do these operations and more.... Create a file Print a file.

Slides:



Advertisements
Similar presentations
Tony Kombol.  A program that  receives commands from a text input device (e.g. keyboard)  passes them to the operating system to perform  In the.
Advertisements

Introduction to the gedit editor. gedit: the Gnome editor Gnome: Gnome is a freely available (i.e., no cost) desktop environment for the UNIX system The.
Working with Files How to create, view, copy, rename and print files.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Preparation for working in the CSIL Basic LINUX operations.
Git/Unix Lab March Version Control ●Keep track of changes to a project ●Serves as a backup ●Revert to previous version ●Work on the same files concurrently.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
The Internet. Telnet Telnet means using your computer as a terminal. All commands you type are sent to the host computer you are connected to and executed.
Chapter 7 Advanced Directory and File Management.
Guide To UNIX Using Linux Third Edition
UNIX Utilities Learning Objectives: 1. To understand the some basic utilities of UNIX File 2. To compare UNIX shell and popular shell 3. To learn Input/Output.
9-2 How do you copy/move/rename/remove files? How do you create a directory ? What is redirection and piping? Readings: See CCSO’s Unix pages andCCSO’s.
Chapter 8 Managing Files.
1 Some basic Unix commands u Understand the concept of loggin into and out of a Unix shell u Interact with the system in a basic way through keyboard and.
Editing Java programs with the BlueJ IDE. Working environments to develop (= write) programs There are 2 ways to develop (write) computer programs: 1.Using.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Learning basic Unix command IT 325 operating system.
MCB Lecture #3 Sept 2/14 Intro to UNIX terminal.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Notes Assignment #1 is due next Friday by 11:59 pm via Test #1 will be held Thursday February 18 at the start of class (one period long) Format:
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
CHAPTER 1 UNIX FOR NONPROGRAMMERS By U ğ ur Halıcı.
Working with Files Chapter 5. Display a Calendar Display a calendar for a specific month – cal Display a calendar for a specific year – cal 2000.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
Unix Basics Chapter 4.
Interacting with a UNIX computer: Navigating through the directory tree.
Microsoft Office 2008 for Mac – Illustrated Unit C: Understanding File Management.
CS240 Computer Science II Introduction the Unix File System and File Related Utilities Based on “UNIX for Programmers and Users” by G.Class and K. Ables.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Using Commands Unix/IP Preparation Course July 19, 2009 Eugene, Oregon, USA
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Some content in this lecture added.
Operating Systems and Using Linux CMSC 104, Lecture 3 John Y. Park 1.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands cal – will print a calendar.
Using Commands Unix / Linux Preparation Course May 6, 2012 Serrekunda, The Gambia.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Introduction to UNIX Geraint Vaughan. What is UNIX? Command-line operating system (not point- and click) Designed for ‘experts’ Lots of different variants.
Welcome to CS323 Operating System lab 1 TA: Nouf Al-Harbi NoufNaief.net.
Chapter 1 : The Linux System Part 2 Lecture 2 11/14/
Introduction to Programming Using C An Introduction to Operating Systems.
Manipulating Files Refresher. The touch Command touch is used to create a new, empty file. If the file already exists, touch updates the time and date.
Linux Lecture #02. File Related Commands cat --Concatenate and print (display) the content of files. --Also used to create a new file. Syntax cat [Options]
Using the “CLI” Unix / Linux Preparation Course June 9, 2013 Lusaka, Zambia.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
XP New Perspectives on Microsoft Windows XP Tutorial 2 1 Microsoft Windows XP Working with Files Tutorial 2.
Operating Systems and Using Linux Courtesy of John Y. Park 1.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
CMSC 104, Version 8/061L03OperatingSystems.ppt Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux.
Unix Lab Fall Shell Scripting ●Through the shell (LXTerminal) you can: ●Run programs. ●Interact with the file system. ●Change settings. ●Send/receive.
+ Introduction to Unix Joey Azofeifa Dowell Lab Short Read Class Day 2 (Slides inspired by David Knox)
Interacting with a UNIX computer in the MathCS Lab.
UNIX The Basics Source:
Tutorial of Unix Command & shell scriptS 5027
Operating Systems and Using Linux
Operating Systems and Using Linux
Operating Systems and Using Linux
Operating Systems and Using Linux
The Unix File System.
Chapter Four UNIX File Processing.
Introduction Paul Flynn
Operating Systems and Using Linux
Operating Systems and Using Linux
Operating Systems and Using Linux
Operating Systems and Using Linux
Yung-Hsiang Lu Purdue University
Operating Systems and Using Linux
Module 6 Working with Files and Directories
Lab 2: Terminal Basics.
Presentation transcript:

Manipulating files in UNIX

Common operations of files Common operations: We will learn to do these operations and more.... Create a file Print a file Delete a file Rename a file Move a file from one directory into another directory

Identifying a file We need to identify a file before we can perform an operation (like delete) on the file. A file can be identified using: An absolute (file) path, or An relative (file) path

Absolute file path Absolute file path: An absolute file path tells the computer how to find a file starting from the root directory An absolute file path of a particular file x consists of a list of directory names starting from the root directory "/" to the directory containing the file x and then followed by the name of the file (x) The list of names is separated by the "/" symbol

Absolute file path (cont.) The path for the indicated file (myFile2) is: /home/cheung/cs170/myFile2

Relative file path Relative file path: An relative file path tells the computer how to find a file starting from the current directory An relative file path of a particular file x consists of a list of directory names starting from the current directory to the directory containing the file x and then followed by the name of the file (x) The list of names is separated by the "/" symbol

Relative file path (cont.) Example 1: If the current directory is /home/cheung, then the path for the indicated file (myFile2) is: cs170/myFile2

Relative file path (cont.) If the current directory is /home/cheung/cs170, then the path for the indicated file (myFile2) is: myFile2

Relative file path (cont.) Advice: When working on files, always change the working directory to the one that contains the files. It will save you a lot of key strokes (typing)

Common operations on files Common operations on files: Create a file Print a file to the terminal Print a file to the printer Delete a file Rename a file Move a file from one directory (folder) to another directory (folder)

Create a file An electronic file is created using a computer application (program) called an editor (An editor in computer lingo is a program !!!) Some commonly used editors that you have used on a PC: We will learn to use gedit (GNU editor) in another webnote. Microsoft Word Notepad

Print the content of a file out to the terminal The command (= application) that is used to print the content of a file is: (cat is an abbreviation of the word catenate) cat FILE-PATH

Print the content of a file out to the terminal (cont.) Example:

Catenating multiple files The cat command can catenate an arbitrary number of files to the terminal Example: catenate myFile1 and myFile2 to the terminal:

Redirecting the input and output to a file In UNIX, the output that an application prints to the terminal, can be stored to a file Also, the input that an application reads from the keyboard, can be read from a file. This feature is called: Input/Output redirection (or IO redirection for short)

Redirecting the input and output to a file (cont.) Redirecting the output to a file: The output of any UNIX command can be sent to a file by adding " > FileName" to the command In other words: any UNIX command > FileName

Redirecting the input and output to a file (cont.) Example: redirecting the output of "ls" into a file:

Redirecting the input and output to a file (cont.) Example: redirecting the output of cat myFile1 myFile2 to a file (named myFile3)

Redirecting the input and output to a file (cont.) You can see that myFile3 contains the catenation of the files myFile1 and myFile2 So the cat command can be used to catenate multiple files together !!! (Hence the name cat) We will learn about input re-direction at a later lecture

Print a file to the printer Use this command to print a file to the default printer: When you print a file from a computer in the MathCS lab, the default printer is the printer located inside the area where the Lab assistant(s) sits lpr File-Path

Print a file to the printer (cont.) Example: will print the file named myFile1 in the current directory to the printer lpr myFile1

Delete a file The command (application) used to delete a file is: The word rm is an acronym for remove All files with names matching the File-Path will be removed rm File- Path

Delete a file (cont.) Example rm myFile1 (will delete the file named "myFile1" in the current directory) rm /home/cheung/cs170/myFile1 (will delete the file "myFile1" in the directory/home/cheung/cs170)

Delete a file (cont.) Important note: Make sure that your current directory is the correct one when you use a relative path with all UNIX commands !!!

Recovering deleted files in UNIX Very important: When you delete a file (with rm, the file is really deleted in UNIX What I mean is: the file is not moved into a trash directory (That's what happens in Microsoft Windows) In other words: your file is gone forever

Recovering deleted files in UNIX Restoring a file with a backup version: Every night, all files in a UNIX system is saved (backup) If you deleted a file, you can recover an older version of the file as of yesterday In other words: any work you do after the backup was made, will be lost.... Send an to: if you need to recover a file using a backup copy.

Rename a file The command (application) used to rename a file with name old-File-Path to the name new-File-Path is: mv old-File-Path new-File-Path

Rename a file (cont.) Important: The new-File-Path file must not exist; otherwise, 2 things can happen: 1.If the new-File-Path exists and it is the name of a file, then the mv will report an error (and will not rename the file) 2.If the new-File-Path exists and it is the name of a directory, then the mv will move the file old-File- Path into the directory new-File-Path

Rename a file (cont.) Example: will rename the file named myFile2 to the new name decl- of-indep mv myFile2 decl-of-indep

Rename a file (cont.) Illustrated: Notice that after the file is renamed, the content of the file remains unchanged !

Move a file from one directory (folder) to another directory (folder) The command (application) used to mv a file with name file-Path into the directory dir-Path is: mv file-Path dir- Path

Move a file from one directory (folder) to another directory (folder) (cont.) Important: This is in fact the same command for renaming a file The difference is: dir-Path must be the path of an existing directory. (If dir-Path, the command will perform a rename operation !!!)

Move a file from one directory (folder) to another directory (folder) (cont.) Illustrated: mv command with non- existing directory mv command with existing directory