June 1, 1999Manipulating Files1 Introduction to UNIX E. Manipulating Files.

Slides:



Advertisements
Similar presentations
การใช้ระบบปฏิบัติการ UNIX พื้นฐาน บทที่ 4 File Manipulation วิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ ม. สงขลานครินทร์ เวอร์ชั่น 1 วันที่
Advertisements

©Colin Jamison 2004 Introduction to Linux Colin Jamison.
Lab6 CPCS361 I.Mona Alshehri. Working with Files and Directories Creating files Create a file with the cat command type the command cat > name_of_file.
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.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 27 th, 2009 Essential Unix Commands.
File Security. Viewing Permissions ls –l Permission Values.
CS 497C – Introduction to UNIX Lecture 15: - File Attributes Chin-Chih Chang
Guide To UNIX Using Linux Third Edition
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Shell Script Examples.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
BILKENT UNIVERSITY DEPARTMENT OF COMPUTER TECHNOLOGY AND INFORMATION SYSTEMS CTIS156 INFORMATION TECHNOLOGIES II CHAPTER 10: ADVANCED FILE PROCESSING.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Va-scanCopyright 2002, Marchany Unit 6 – Solaris File Security Randy Marchany VA Tech Computing Center.
Brief introduction to UNIX A. Emerson CINECA, High Performance Systems.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
CHAPTER 1 UNIX FOR NONPROGRAMMERS By U ğ ur Halıcı.
2 Manual & Filestore. Introduction Using the manual The UNIX filestore File permissions.
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.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
Lesson 11-Locating, Printing, and Archiving User Files.
June 1, 1999Using The C-Shell1 Introduction to UNIX F. Using C Shell Features.
Guide To UNIX Using Linux Fourth Edition
Title Slide CSS 404/504 The UNIX Operating System (2) By Ralph B. Bisland, Jr.
Dedan Githae, BecA-ILRI Hub Introduction to Linux / UNIX OS MARI eBioKit Workshop; Nov , 2014.
LIN Unix Lecture 3 Hana Filip. LIN UNIX Resources UNIX Tutorials UNIX help for.
Jozef Goetz, expanded by Jozef Goetz, 2009 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert.
Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,
Linux overview. Architecture Kernel File system Shell: Korn, Bourne, C, Bash X Windows: Motif, Open Look, X.OrgX.Org Desktop: Gnome, KDE,etc.
CS 6560 Operating System Design Lecture 3:Tour of GNU/Linux.
June 1, 1999UNIX File System1 Introduction to UNIX D. UNIX File Structure.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
File Permission and Access. Module 6 File Permission and Access ♦ Introduction Linux is a multi-user system where users can assign different access permission.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Chapter Five Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Managing Files. Module 5 Managing Files ♦ Introduction “On a Linux system, everything is a file; if something is not a file, it is a process.” ♦ Topics.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands cal – will print a calendar.
File Security and Permissions. File Permissions (1) u With respect to a particular file, Unix divides the set of all users on a system into three categories:
UNIX An Introduction. Brief History UNIX UNIX Created at Bell Labs, 1969 Created at Bell Labs, 1969 BSD during mid 70s BSD during mid 70s AT&T began offering.
Chapter 4: File Security & Permissions Also: Hard and Soft Links, see p77-80 &
BASIC FILE ATTRIBUTES. CONTENTS ls –l to display file attributes (properties) Listing of a specific directory Ownership and group ownership Different.
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]
Linux Commands C151 Multi-User Operating Systems.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
CSCI 330 The UNIX System Unit V Permissions. all access to directories and files is controlled UNIX uses discretionary access control (DAC) model each.
A gentle introduction to LINUX at the command prompt.
CSN08101 Digital Forensics Lecture 2: Essential Linux for Forensics Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
CSCI 330 UNIX and Network Programming Unit II Basic UNIX Usage: File System.
CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT File Processing.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
+ Introduction to Unix Joey Azofeifa Dowell Lab Short Read Class Day 2 (Slides inspired by David Knox)
Learning Unix/Linux Based on slides from: Eric Bishop.
Laboratory 1.2a1 First steps with Unix - Lab Boris Steipe Department of Biochemistry Department.
Tutorial of Unix Command & shell scriptS 5027
File permissions Operating systems I800
Lecture 2 Working with Files and Directories
Some Linux Commands.
Chapter 6 Filters.
INTRODUCTION TO UNIX: The Shell Command Interface
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Security and File Permission
In the last class, The concept of file system
Presentation transcript:

June 1, 1999Manipulating Files1 Introduction to UNIX E. Manipulating Files

June 1, 1999Manipulating Files2 Basic File Manipulation Performance Objectives 1. View a selected file (cat, more) 2. View leading or trailing segments of a file (head, tail) 3. Copy and move files (cp, mv) 4. Use Wild Card Characters (*, ?, []) 5. Identify file permission attributes (rwx) 6. Set file permissions (chmod, umask) 7. Print Files (lpr, lpq, cancel, pr) 8. Record the Screen Image (script) 9. Locate a file (find)

June 1, 1999Manipulating Files3 Basic File Manipulation Performance Objectives- continued 10. Archive files (tar) 11. Check spelling (ispell, look) 12. Search for specified string in a file (grep) 13. Order a file by a specified column (sort)

June 1, 1999Manipulating Files4 Viewing a File - cat Three forms: n Read each file in sequence and display it on standard output. è host% cat file1 file2 n Combine files and place result in another. è host % cat file1 file2 > file3 n Make a file from standard input (until ^d) è host% cat >file

June 1, 1999Manipulating Files5 Viewing a File - more View a file in a controlled manner. è more [options] filename è host% more passwd Note more --- xx% in the lower left corner. moves one line at a time. SPACEBAR moves one screen at a time. Use /keyword to advance to desired information.

June 1, 1999Manipulating Files6 Viewing the Head or Tail View the first 10 lines of a file: host% head passwd Use -20 to see 20 lines host% head -20 passwd View the last 10 lines of a file: host% tail passwd Use -f to continuously monitor a file host% tail -f /var/log/syslog

June 1, 1999Manipulating Files7 Wild Cards - * Wildcards permit selection criteria Note the following list: host% ls Aprmbox Junmbox bin misc_memos Augmbox Marmbox calendar newjunk Decmbox Maymbox doc_memo newsrc Febmbox Novmbox junk out Janmbox Octmbox login test.f Julmbox Sepmbox mbox test.out

June 1, 1999Manipulating Files8 Wild Cards - * (Con’t) Use an asterisk * to list filenames containing certain patterns. host% ls *junk junk newjunk host% ls *mb No match

June 1, 1999Manipulating Files9 Wild Cards - * (Con’t) Carefully observe the placement of asterisks n host% ls *mb* Aprmbox Janmbox Maymbox mbox Augmbox Julmbox Novmbox Decmbox Junmbox Octmbox Febmbox Marmbox Sepmbox

June 1, 1999Manipulating Files10 Wildcards - [ ] Use Brackets to define a range: host% ls doc/memo.[1-5] doc/memo.1 doc/memo.3 doc/memo.5

June 1, 1999Manipulating Files11 Wildcards - ? Use the question mark to define a specific number of character positions: host% ls test.??? test.out Note that this ls did not display the file test.f

June 1, 1999Manipulating Files12 File Commands - cp The copy command copies a file to a new location: host% cp passwd docs/newfile host% cp -i ~dhk/file2 docs/newfile overwrite newfile? host% cp ~dhk/passwd.

June 1, 1999Manipulating Files13 File Commands - mv Command syntax: host% mv oldfile newfile host% mv -i ~dhk/file2 calendar remove calendar? host% mv calendar docs Note possible use of set noclobber in.cshrc.

June 1, 1999Manipulating Files14 File Commands - rm Command syntax: host% rm oldfile host% rm -i newfile rm: remove newfile? host% rm -r * Removes ALL files and directories - BE CAREFUL

June 1, 1999Manipulating Files15 File Commands - rm To remove filenames with certain patterns: host% rm *junk host% rm *mb*

June 1, 1999Manipulating Files16 Protecting Your Files Use the -l option to reveal the permissions: host% ls -l drwxr-xr-x 2 ths 512 Oct bin -rw-r--r-- 1 ths 129 Nov complex.f -rw ths 129 Jul 2 10:05 mbox File Permissions è r = read è w = write è x = execute/search

June 1, 1999Manipulating Files17 Protecting Your Files Who has permission? d rwx r-x r-x 2 ths 512 Oct bin  u g o user (owner) group other (world)

June 1, 1999Manipulating Files18 Protecting Your Files chmod changes permissions after a file has been created. umask in your.cshrc sets the file creation mask for all files.

June 1, 1999Manipulating Files19 Protecting Your Files - umask Command syntax: host% umask value Octal values deny access privileges 1 x 4 r 7 rwx 2 w 5 rx 3 wx 6 rw n default value 22 Group and Others have no write permission. n most restrictive 77 Group and Others have no permissions.

June 1, 1999Manipulating Files20 Migrating Privileges The cp command uses the umask privileges. The mv command transfers existing privileges for a file.

June 1, 1999Manipulating Files21 Protecting Your Files - chmod Command syntax è host% chmod mode file... The option "mode" n defines all permissions or n changes existing permissions

June 1, 1999Manipulating Files22 Protecting Your Files - chmod chmod uses the following syntax: chmod ug+w filename who op permission u = r g + w o - x a

June 1, 1999Manipulating Files23 Protecting Your Files - chmod Consider the following examples: -rw-r--r-- 1 ths 129 Nov memos drwxr-xr-x 2 ths 512 Oct pri.dir -rw ths 129 Jul 2 10:05 mbox Give write permission to group and others. host% chmod go+w memos Remove read/search from group. host% chmod g-rx pri.dir Read permission for all. host% chmod a=r mbox

June 1, 1999Manipulating Files24 Printing Files Local print commands n lpr, lp n lpq, lpc status n lprm, cancel n pr Contact consult for output from mode

June 1, 1999Manipulating Files25 Capturing screen input-script To capture everything that shows up on the screen, use script host.21% script errors Script started, file is errors host.1% CC program.c -o program.x... host.2% exit Script done, file is errors host.22%

June 1, 1999Manipulating Files26 Finding Files with find find will search a directory tree You need to have search privileges for tree find. -name a.out -print Searches can take a long time, background them find / -name crack -print > crack.found & See man page for other options

June 1, 1999Manipulating Files27 Archiving files with tar Tape Archive (tar) Used to create one file from a directory tree Create a tar file tar cvf /tmp/newfile.tar. Expand a tar file tar xvf product.tar May have to uncompress it first uncompress tex.tar.Z ; tar xvf tex.tar

June 1, 1999Manipulating Files28 Check spelling - spell and look Most Unix systems have both Not as good as word processors Dumps words that are not in its spelling list spell project.report Now how do you spell seperate? look sep

June 1, 1999Manipulating Files29 Use of Filters A filter takes its input from a file, performs some operation on that input, and writes the result to standard output. Common UNIX filters are n grep n more n sort n wc

June 1, 1999Manipulating Files30 Global Regular Expression Parser grep - Global Regular Expression Parser Searches a file for a specified string: host% grep ths passwd ths:6q3y/n8TQp2WU:1059:8010:Ted Spitzmiller, ,8010x33d:/home/sunclass1/ths:/bin/csh wc - Word Count, shows the number of lines, words, and characters host% wc project.report

June 1, 1999Manipulating Files31 Use of Filters - sort Performs an alphanumeric sort of a file. host% sort [options] [file(s)] Example of use: host% ls -l > x Routes the result to file "x" host% sort x Sorts on first field (blank delimiter) 0 -rw ths 0 Jun 4 09:30 dead.letter 0 -rw-r--r-- 1 ths 0 Apr 30 14:34 x 1 -rwx ths 31 Dec startAR* 1 -rwx-----x 1 ths 115 Nov cfs.size* 1 drwx ths 512 Feb News/ 1 drwx--x--x 2 ths 512 Aug cfs.dir/ 1 drwxr-xr-x 2 ths 512 Apr 22 14:52 complit/ 2 -rw ths 1117 Apr travel 2 -rw-r--r-- 1 ths 1609 Feb 13 09:32 team.mmet 2 -rwx--x--x 1 ths 1690 Apr openwin-init* 2 drwx ths 1536 Nov html/ 2 drwxr-xr-x 2 ths 1536 Apr 7 12:01 bits2/

June 1, 1999Manipulating Files32 Use of Sort: Note what happens with some options: host ls -l | sort + 4 total rw ths 2238 Jan login.matrix 4 -rw ths 3156 Mar file.mat 4 -rw ths 3187 Mar mail.mat 7 -rw ths 6280 Nov login.bak 7 -rw ths 6497 Jan logmatrix.bak

June 1, 1999Manipulating Files33 End of Module Complete Manipulating Files Exercises