CIT 383: Administrative Scripting

Slides:



Advertisements
Similar presentations
Chapter 8 Files and User Information Utilities. Logical Partitions referred to as file systems like a drive in windows world $ df (display filesystems)
Advertisements

Linux+ Guide to Linux Certification, Second Edition
Linux Linux File System.
Introduction to Unix – CS 21 Lecture 13. Lecture Overview Finding files and programs which whereis find xargs Putting it all together for some complex.
CS 497C – Introduction to UNIX Lecture 16: - File Attributes Chin-Chih Chang
Guide To UNIX Using Linux Third Edition
Scripting with Ruby What is a scripting language? What is Ruby?
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting RSS.
UNIX. find command ● The find command is used to locate files on a Unix or Linux system. find will search any set of directories you specify for files.
Using Unix Shell Scripts to Manage Large Data
Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers.
Overview of the grep Command Alex Dukhovny CS 265 Spring 2011.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting XML.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
CIT 383: Administrative Scripting
File Permissions. What are the three categories of users that apply to file permissions? Owner (or user) Group All others (public, world, others)
Linux+ Guide to Linux Certification, Second Edition
Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2011 by the Trustees of Indiana University except as noted.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Writing Methods.
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 10 Linux.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Methods and Hashes.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Introduction.
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.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Scripting with Ruby What is a scripting language? What is Ruby?
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
Managing Files CSCI N321 – System and Network Administration Copyright © 2000, 2007 by the Trustees of Indiana University except as noted.
Manage Directories and Files in Linux Part 2. 2 Identify File Types in the Linux System The file types in Linux referred to as normal files and directories.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting HTTP.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Numbers.
Scripting with Ruby What is a scripting language? What is Ruby?
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Directories.
Why UNIX? In the 1980s, UNIX became popular In the 1980s, UNIX became popular Customer demand for open systems: Customer demand for open systems: Application.
CIT 383: Administrative Scripting
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting DateTime.
Introduction to information systems RUBY dr inż. Tomasz Pieciukiewicz.
Essential Administrative Tools  Commonly used utilities Grep, Awk, Find, Xargs  Communication commands  Editor Vi 1.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Commands.
File System Security in Unix Annie Calpe. Overview Unix Basics File System Security: - Account Security: Passwords - File Permissions - Access Control.
1 The find and locate commands Kevin B. O'Brien Washtenaw Linux Users Group
Linux Filesystem Management
Linux 201 Training Module Linux Adv File Mgmt.
Arun Vishwanathan Nevis Networks Pvt. Ltd.
Linux file system "On a UNIX system, everything is a file;
Chapter 9 Periodic Processes
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
Shell Script Assignment 1.
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
CIT 383: Administrative Scripting
Chapter Four UNIX File Processing.
CIT 383: Administrative Scripting
CSE 303 Concepts and Tools for Software Development
CSE 303 Concepts and Tools for Software Development
Periodic Processes Chapter 9.
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
Internal Representation of Files
Review.
CMPSC 60: Week 5 Discussion
Presentation transcript:

CIT 383: Administrative Scripting Find CIT 383: Administrative Scripting

CIT 383: Administrative Scripting The find command Searches for files in a directory tree find path operators Can search for files based on -name -perm -size -type -user -group -atime, -mtime, -ctime CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Find times Numbers refer to 24-hour periods Find files modified during the 24-hour period that ended exactly 3 days ago, i.e. the time between 72 and 96 hours ago. find / -type f –mtime 3 - refers to times after the 24-hour period Find all files modified between now and 3 days ago. find / -type f –mtime -3 + refers to times before the 24-hour period Find all files not accessed in last 30 days find / -type f –atime +30 CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Fast find commands The locate command searches index for files locate filename Faster than find, but Can only search based on name. Will miss files not in index. Must update index regularly with updatedb. CIT 383: Administrative Scripting

Manipulating files with find Find can exec a command on each file find . –name “*.bak” –exec rm –f {} \; find /var/logs –mtime +7 –exec rm –f {} \; find / –user jsmith –exec chown root {} \; To operate on all at once, pipe to xargs find /var/logs –mtime +7 | xargs grep failure find / -user jsmith | xargs file CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Find.find Execute block for all files under path Find.find(topdir) do |path| ... process path ... end Use prune inside block to ignore directories. CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Finding Files by Name Match whole name if path == “core” Match using substrings. if path[-4,4] == “.xls” Match using regular expressions. if path =~ /\.(xls|doc|ppt)$/ CIT 383: Administrative Scripting

Finding Files by Other Criteria Obtain a File::Stat object Find.find(topdir) do |path| stat = File::Stat.new(path) ... process based on stat ... end Match by size if stat.size > 1_000_000 Match by owner if stat.uid == Process.uid CIT 383: Administrative Scripting

Storing found filenames in an Array matching_files = Array.new Find.find(topdir) do |path| if condition matching_files << path end CIT 383: Administrative Scripting

Storing file metadata in a Hash filedata = Hash.new Find.find(topdir) do |path| stat = File::Stat.new(path) if condition filedata[path] = stat.method end CIT 383: Administrative Scripting

Storing file data in a Hash filedata = Hash.new Find.find(topdir) do |path| File.open(path) do |fh| if condition filedata[path] = fh.read end CIT 383: Administrative Scripting

CIT 383: Administrative Scripting References Michael Fitzgerald, Learning Ruby, O’Reilly, 2008. David Flanagan and Yukihiro Matsumoto, The Ruby Programming Language, O’Reilly, 2008. Hal Fulton, The Ruby Way, 2nd edition, Addison-Wesley, 2007. Dave Thomas with Chad Fowler and Andy Hunt, Programming Ruby, 2nd edition, Pragmatic Programmers, 2005. CIT 383: Administrative Scripting