CLIL-3-PHP-3. Files - part 1. Once you master the art of working with files, a wider world of PHP web
|
|
- Amanda Chapman
- 6 years ago
- Views:
Transcription
1 Files - part 1 Introduction Once you master the art of working with files, a wider world of PHP web development opens up to you. Files aren't as flexible as databases by any means, but they do offer the chance to easily and permanently store information across scripts, which makes them popular amongst programmers. Files, as you can imagine, can store all sorts of information. However, most file formats (e.g. picture formats such as PNG and JPEG) are binary, and very difficult and/or impossible to write using normal text techniques - in these situations you should use the library designed to cope with each format. One reminder: if you are using an operating system that uses backslash \ as the path separator (e.g. Windows), you need to escape the backslash with another backslash, making \\. Alternatively, just use /, because Windows understands that just fine too. Topics covered in this chapter are: Reading and writing files Temporary files How to make a counter Handling file uploads File permissions 1
2 Note: CPUs work in billions of operations per second - a 3GHz CPU is capable of performing three billion operations every second. RAM access time is measured in nanoseconds (billionths of a second) - you can usually access some data in RAM in about 40 nanoseconds. Hard drive access time, however, is measured in milliseconds (thousandths of a second) - most hard drive have about a 7ms access time. What this means is that hard drives are much, much slower than RAM, so working with files from your hard drive is the slowest part of your computer, excluding your CD ROM. Databases are able to store their data in RAM for much faster access time, whereas storing hard drive data in RAM is tricky. Files are good for storing small bits of information, but it is not recommended that you use them too much for anything other than your PHP scripts themselves - counters are fine in files, as are other little things, but anything larger would almost certainly benefit from using a database. Having said that, please try to avoid the newbie mistake of putting everything into your database - if you find yourself trying to figure out what field type is right to store picture data, please have a rethink! 2
3 readfile() int readfile (string filename [, bool use_include_path [, resource context]]) If you want to output a file to the screen without doing any form of text processing on it whatsoever, readfile() is the easiest function to use. When passed a filename as its only parameter, readfile() will attempt to open it, read it all into memory, then output it without further question. If successful, readfile() will return an integer equal to the number of bytes read from the file. If unsuccessful, readfile() will return false, and there are quite a few reasons why it may file. For example, the file might not exist, or it might exist with the wrong permissions. Here is an example script: readfile("/home/paul/test.txt"); readfile("c:\\boot.ini"); The first example will work on most Unix-like systems, and will attempt to open the file test.txt in /home/paul/ directory - you will almost certainly want to change this to point to somewhere that exists and you have access to. The second example is for Windows systems, and should work in any Windows NT-descended OS, including Windows XP, Vista, 7 and 8. The advantages to using readfile() are clear: there is no fuss, and there is little way for it to go wrong. However, the disadvantage is equally clear: you have got absolutely no control over the text that comes out. You should use readfile() when you just want to print a file out without any further action on your behalf - it is a powerful little one-liner. 3
4 Note that from here on in I will be using the variable $filename to signify a filename you have chosen. This is to avoid having to keep printing separate examples for Windows and Unix. 4
5 file_get_contents() file() string file_get_contents (string filename [, bool use_include_path [, resource context]]) array file (string filename [, bool use_include_path [, resource context]]) The next evolutionary step up from readfile() is just called file_get_contents(), and also takes one parameter for the filename to open. This time, however, it does not output any data - instead, it will return the contents of the file as string, replete with new line characters \n where appropriate Here is file_get_contents() in use: $filestring = file_get_contents($filename); print $filestring; $filename, as mentioned already, is a variable used to represent a file you have chosen already, whether that be on Unix or Windows, which means that file_get_contents() opens that file and places its contents into $filestring. Effectively that piece of code is the same as our call to readfile(), but only because we're not doing anything with $filestring once we have it. Consider this script: $filestring = file_get_contents($filename); $filearray = explode("\n", $filestring); while (list($var, $val) = each($filearray)) { ++$var; $val = trim($val); print "Line $var: $val<br />"; } 5
6 This time we use explode() to turn $filestring into an array, which is then iterated through, outputting one line at a time with line numbers. Remember that array indices start at 0, so we need ++$var to make sure that it starts at line 1 rather than line 0. Also, note that we call trim() on $val - this is because each element in the array still has its new line character \n at the end, and trim() will take that off. File_get_contents() is an excellent general-purpose file-handling function that you will likely find yourself using extensively. As an alternative, if you find yourself always wanting your files inside arrays, you can use the file() function - it works in the same manner as file_get_contents(), with the exception that it returns an array, which each line in the file returned as an element. 6
7 fopen() fread() resource fopen ( string filename, string mode [, bool use_include_path [, resource context]]) string fread ( resource handle, int length) fopen() is, for many, a fiendishly complex function to use. The reason for this is because it is another one of those functions lifted straight from C, and so is not as user-friendly as most PHP functions. On the flip-side, as per usual, is the fact that fopen() is an incredibly versatile function that some people come to love for its ability to manipulate files just as you want it to. fopen() has two key parameters: the file to open, and how you would like it opened. Parameter one is easy - it is just $filename, as with the other examples. Parameter two is what makes fopen() so special: you specify letters in a string that define whether you want to read from ("r"), write to ("w"), or append to ("a") the file specified in parameter one. There is also a fourth option, "b", which opens the file in binary mode. This is not necessary on Unix-based systems, but it is on Windows, so it is best to use it everywhere - it is not detrimental on Unix-based systems at all. Take a look at the following usages: fopen($filename, "r"); fopen($filename, "w"); fopen() returns a file handle resource, which is basically the contents of the file. You cannot output it directly, e.g. "print fopen(...)", but fopen() -related functions all accept file handles as the file to work with, so you should store the return value 7
8 of fopen() in a variable for later use. Therefore, here's a full usage of fopen() : $handle = fopen($filename, "a"); If the file cannot be opened, fopen() returns false. If the file is successfully opened, a file handle is returned and you can proceed. Once the file handle is ready, we can call other functions on the opened file, depending on how the file was opened (the second parameter to fopen() ). To read from a file, the function fread() is used, and to write to a file fwrite() is used. For now we're interested in reading, so you should use "rb" for the second parameter to fopen(). fread() takes two parameters: a file handle to read from (this is the return value from fopen(), remember) and the number of bytes to read. The second parameter might not make sense at first, after all you generally want to read in all of a file, right? Note: Do not worry about specifying a number in parameter two that is larger than the file - PHP will stop reading when it hits the end of the file or the number of bytes in parameter two, whichever comes first. Well, while the chances are that you will indeed want to read in all of a file, doing so requires you have enough memory to be able to read in the entire file at once - if you are working with files of several megabytes or indeed hundreds of megabytes, PHP's resource consumption would balloon. In circumstances such as these you have but two choices: buy more RAM, or parse your data sequentially! 8
9 Luckily, most people will not have to make that choice - most people work with text files under a megabyte in size, and PHP can load a megabyte file all at once in a tiny fraction of a second. To instruct PHP to use fread() to read in the entire contents of a file, you simply need to specify the exact file size in bytes of that file as parameter two to fread(). Sound difficult? PHP comes to the rescue again with the filesize() function, which takes the name of a file to check, and returns its filesize in bytes - precisely what we're looking for. When reading in a file, PHP uses a file pointer to determine which byte it is currently up to - kind of like the array cursor. Each time you read in a byte, PHP advances the array cursor by one place - reading in the entire file at once advances the array cursor to the end of the file. So, to use fread() to read in an entire file, we can use the following line: $contents = fread($handle, filesize($filename)); Notice that fread() 's return value is the text it read in, and in above situation that is the entire file. To finish off using fread() it is simply necessary to close the file as soon as you are done with it. Note: Although PHP automatically closes all files you left open in your script, it is not smart to rely on it to do so - it is a poor use of resources, and it might affect other processes trying to read the file. Always, always, always close your files the minute you are finished with them. To close a file you have opened with fopen(), use fclose() - it takes the file handle we got from fopen(), and returns true if it was able to close the file successfully. 9
10 We have now got enough to use fopen() to fully open and read in a file, then close it. Here is the script: $handle = fopen($filename, "rb"); $contents = fread($handle, filesize($filename)); fclose($handle); print $contents; Firstly, remember that you will need to set $filename to be the location of a file on your system that you have access to. Secondly, notice that fopen() is called with "fb" as the second parameter - read-only, binary-safe. Always use "b" to ensure compatibility with Windows servers. Thirdly, notice that filesize() is being used to fread() in all of $filename's contents. Finally, notice that fclose() is called before $contents is printed - it is closed as soon as $handle is no longer needed. Get into - and stay in - this habit. 10
11 Creating and changing files Like reading files, creating and changing files can also be done in more than one way. Luckily for you, there are just two options this time: file_put_contents() and fwrite(). Both of these functions complement functions we just looked at, which are file_get_contents() and fread() respectively, and they work in mostly the same way. file_put_contents() int file_put_contents ( string filename, string data [, int flags [, resource context]]) This function writes to a file with the equivalent of fopen(), fwrite() (the opposite of fread() ), and fclose() - all in one function, just like file_get_contents. It takes two parameters, the filename to write to and the content to write respectively, with a third optional parameter specifying extra flags which we will get to in a moment. If file_put_contents() is successful it returns the number of bytes written to the file, otherwise it will return false. Using the file_put_contents() function is easy - here's an example: $myarray[] = "This is line one"; $myarray[] = "This is line two"; $myarray[] = "This is line three"; $mystring = implode("\n", $myarray); $numbytes = file_put_contents($filename, $mystring); print "$numbytes bytes written\n"; Remember you will need to set $filename first - other than that the script is straightforward, and should output "52 bytes written", which is the sum total of 11
12 the three lines of text plus the two new line characters used to implode() the array. Remember that the new line character is in fact just one character inside files, whereas PHP represents it using two, \ and n. You can pass in a third parameter to file_put_contents(), which, if set to FILE_APPEND, will act to append the text in your second parameter to the existing text in the file. If you do not use FILE_APPEND the existing text will be wiped and replaced, which is not always the desired behaviour. 12
13 fwrite() int fwrite ( resource handle, string string [, int length]) The opposite to fread() is fwrite() and also works with the file handle returned by fopen(). Fwrite() takes a string to write as a second parameter, and an optional third parameter where you can specify how many bytes to write. If you do not specify the third parameter, all of the second parameter is written out to the file, which is often what you want. Note: as with fread(), PHP will stop writing when it reaches the end of the string or when it has reached the number of bytes specified in this length parameter, whichever comes first - you don't need to worry about specifying more bytes than you have in the string. Here is an example using the variable $mystring from the previous example to save space: $handle = fopen($filename, "wb"); $numbytes = fwrite($handle, $mystring); fclose($handle); print "$numbytes bytes written\n"; If I had added 10 as the third parameter to the fwrite() call, only the first ten bytes of $mystring would have been written out. Note again that fclose() is called immediately after it was finished with, which is always best practice. Fwrite() uses a file pointer in the same way as fread() - as you write bytes out, PHP advances the file pointer appropriately, meaning that, unless you specifically 13
14 move the file pointer yourself, you always write to the end of a file. 14
15 Moving, copying, and deleting files bool rename ( string old_name, string new_name [, resource context]) bool copy ( string source, string dest) bool unlink ( string filename, resource context) PHP has simple functions to handle all moving, copying, and deleting files, and quite rightly - they are all very popular things to do, so there is no point making them difficult. If you are using Unix you will know that there is no command for "rename", because renaming a file is essentially the same as moving it, so you use the move (mv) command - it is the same in PHP. Files are moved using rename(), copied using copy(), and deleted using unlink(). Unlink() might seem like an odd choice of word at first, but Unix systems consider filenames to be "hard links" to the actual files themselves, so to unlink a file is to delete it. Note: all three functions will operate without further input from you. If you choose to pass an existing file to the second parameter of rename(), it will rename the file in parameter one to the file in parameter two, overwriting the original file. The same applies to copy() - you will overwrite all files without question as long as you have the correct permissions. 15
16 Moving files with rename() Use for both renaming and moving files, rename() takes two parameters: the original filename and the new filename you wish to use. Rename() can rename/move files across directories and drives, and will return true on success or false otherwise. Here is an example: $filename2 = $filename. '.old'; rename($filename, $filename2); If you had $filename set to c:\\windows\\myfile.txt, the above script would move that file to c:\\windows\\myfile.txt.old. Note: rename() should be used to move ordinary files, and not files uploaded through a form. The reason for this is because there is a special function, called move_uploaded_file(), which checks to make sure the file has indeed been uploaded before moving it - this stops people trying to hack your server into making private files visible. You can perform this check yourself if you like by calling the is_uploaded_file() function. 16
17 Copying files with copy() Like rename(), copy() also takes two parameters - the filename you wish to copy from, and the filename you wish to copy to. The difference between rename() and copy() is that calling rename() results in the file being in only one place, the destination, whereas copy() leaves the file in the source location as well as placing a new copy of the file into the destination. $filename2 = $filename. '.old'; copy($filename, $filename2); The result of that script is that there will be a file $filename and also a $filename.old, e.g. c:\\windows\\myfile.txt and c:\\windows\\myfile.txt.old. Note: this function will not copy empty (zero-length) files - to do that, you need to use the function touch(). 17
18 Deleting files with unlink() To delete files, simply pass a filename string as the only parameter to unlink(). Note that unlink deals only with files - to delete directories you need rmdir(). if (unlink($filename)) { print "Deleted $filename!\n"; } else { print "Delete of $filename failed!\n"; } Note: if you have a file opened with fopen(), you need to fclose() it before you call unlink() 18
19 Temporary files resource tmpfile ( void ) Very often you will find you want to work with a file as if it were a "scratchpad" - a holding area where you can write out temporary data for later use. To make this as easy as possible, PHP has a function called tmpfile() which takes no parameters, but will create a temporary file on the system, fopen() it for you, and send back the file handle as its return value. That file is then yours to read from and write to all you wish, and is deleted as soon as you fclose() the file handle or the script ends. Here is an example of tmpfile() in use: $handle = tmpfile(); $numbytes = fwrite($handle, $mystring); fclose($handle); print "$numbytes bytes written\n"; As you can see, tmpfile() is a drop-in replacement for fopen()ing a known file, so it is easy to make use of. If you want to know where these temp files are being saved, use the sys_get_temp_dir() function - it's new in PHP 5.2.1, but returns a string containing the directory used for creating temporary files. 19
CLIL-4-PHP-4. Files - part 2. There are three functions that allow you to work more intimately with the contents
Files - part 2 Other file functions bool rewind ( resource handle) int fseek ( resource handle, int offset [, int from_where]) There are three functions that allow you to work more intimately with the
More informationFILE TYPES 1/2/12 CHAPTER 5 WORKING WITH FILES AND DIRECTORIES OBJECTIVES. Binary. Text PHP PROGRAMMING WITH MYSQL, 2ND EDITION
CHAPTER 5 WORKING WITH FILES AND DIRECTORIES PHP PROGRAMMING WITH MYSQL 2 ND EDITION MODIFIED BY ANITA PHILIPP SPRING 2012 2 OBJECTIVES In this chapter, you will: Understand file type and permissions Work
More informationCOMS 469: Interactive Media II
COMS 469: Interactive Media II Agenda Review Files and Directories Review User Defined Functions Cookies File Includes CMS Admin Login Review User Defined Functions Input arguments Output Return values
More informationCOPYRIGHTED MATERIAL. An Introduction to Computers That Will Actually Help You in Life. Chapter 1. Memory: Not Exactly 0s and 1s. Memory Organization
Chapter 1 An Introduction to Computers That Will Actually Help You in Life Memory: Not Exactly 0s and 1s Memory Organization A Very Simple Computer COPYRIGHTED MATERIAL 2 Chapter 1 An Introduction to Computers
More informationCLIL-5-PHP-5. Files - part 3. At some point in time, you are almost certainly going to come into contact with file
Files - part 3 Permissions At some point in time, you are almost certainly going to come into contact with file permissions: either you will not have the necessary permissions, or you want to set your
More informationFile handling is an important part of any web application. You often need to open and process a file for different tasks.
PHP PHP File Handling Introduction [1] File handling is an important part of any web application. You often need to open and process a file for different tasks. PHP Manipulating Files PHP has several functions
More informationChapter 7 PHP Files & MySQL Databases
Chapter 7 PHP Files & MySQL Databases At the end of the previous chapter, a simple calendar was displayed with an appointment. This demonstrated again how forms can be used to pass data from one page to
More informationXP: Backup Your Important Files for Safety
XP: Backup Your Important Files for Safety X 380 / 1 Protect Your Personal Files Against Accidental Loss with XP s Backup Wizard Your computer contains a great many important files, but when it comes to
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 INPUT/OUTPUT INPUT AND OUTPUT Programs must be able to write data to files or to physical output devices such as displays or printers, and to read in data from files or
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationClean & Speed Up Windows with AWO
Clean & Speed Up Windows with AWO C 400 / 1 Manage Windows with this Powerful Collection of System Tools Every version of Windows comes with at least a few programs for managing different aspects of your
More informationBurning CDs in Windows XP
B 770 / 1 Make CD Burning a Breeze with Windows XP's Built-in Tools If your PC is equipped with a rewritable CD drive you ve almost certainly got some specialised software for copying files to CDs. If
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #47. File Handling
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #47 File Handling In this video, we will look at a few basic things about file handling in C. This is a vast
More informationSo, coming back to this picture where three levels of memory are shown namely cache, primary memory or main memory and back up memory.
Computer Architecture Prof. Anshul Kumar Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture - 31 Memory Hierarchy: Virtual Memory In the memory hierarchy, after
More informationFile Handling with PHP
File Handling with PHP File Handling: Files and PHP refers to working with files that are stored on a hard disk Rationale: Data Storage Can store data in flat files. e.g. logs, dist_lists, xml Note: flat
More informationKeep Track of Your Passwords Easily
Keep Track of Your Passwords Easily K 100 / 1 The Useful Free Program that Means You ll Never Forget a Password Again These days, everything you do seems to involve a username, a password or a reference
More informationWord: Print Address Labels Using Mail Merge
Word: Print Address Labels Using Mail Merge No Typing! The Quick and Easy Way to Print Sheets of Address Labels Here at PC Knowledge for Seniors we re often asked how to print sticky address labels in
More informationCLIL-6-PHP-6. Arrays - part 1. So far we've looked at the basic variables types such as strings and integers, as
Arrays - part 1 Introduction So far we've looked at the basic variables types such as strings and integers, as well as a variety of functions you can use to manipulate these data types. Beyond the basic
More informationMIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.
MIPS Programming This is your crash course in assembler programming; you will teach yourself how to program in assembler for the MIPS processor. You will learn how to use the instruction set summary to
More informationA Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers
A Big Step Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Copyright 2006 2009 Stewart Weiss What a shell really does Here is the scoop on shells. A shell is a program
More informationMemory Addressing, Binary, and Hexadecimal Review
C++ By A EXAMPLE Memory Addressing, Binary, and Hexadecimal Review You do not have to understand the concepts in this appendix to become well-versed in C++. You can master C++, however, only if you spend
More informationWeek Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages
ULI101 Week 02 Week Overview Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages Text editing Common file utilities: cat,more,less,touch,file,find
More informationPre Lab (Lab-1) Scrutinize Different Computer Components
Pre Lab (Lab-1) Scrutinize Different Computer Components Central Processing Unit (CPU) All computer programs have functions, purposes, and goals. For example, spreadsheet software helps users store data
More informationCopyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP
Chapter 11 Introduction to PHP 11.1 Origin and Uses of PHP Developed by Rasmus Lerdorf in 1994 PHP is a server-side scripting language, embedded in XHTML pages PHP has good support for form processing
More informationScripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers
Scripting Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Adapted from Practical Unix and Programming Hunter College Copyright 2006 2009 Stewart Weiss What a shell
More informationLecture 9: File Processing. Quazi Rahman
60-141 Lecture 9: File Processing Quazi Rahman 1 Outlines Files Data Hierarchy File Operations Types of File Accessing Files 2 FILES Storage of data in variables, arrays or in any other data structures,
More informationUNIX File Hierarchy: Structure and Commands
UNIX File Hierarchy: Structure and Commands The UNIX operating system organizes files into a tree structure with a root named by the character /. An example of the directory tree is shown below. / bin
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday
More informationRequirements Management tool makes traceability easy. See how!
http://www.softwareprojects.org/php-files-15.htm 1 of 7 Projects In A Global, Mobile, Virtual And Multi-Cultural World File Handling PHP Requirements Management tool makes traceability easy. See how! www.technosolutions.com
More informationUnix File System. Learning command-line navigation of the file system is essential for efficient system usage
ULI101 Week 02 Week Overview Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages Text editing Common file utilities: cat,more,less,touch,file,find
More informationC mini reference. 5 Binary numbers 12
C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char
More informationThe type of all data used in a C++ program must be specified
The type of all data used in a C++ program must be specified A data type is a description of the data being represented That is, a set of possible values and a set of operations on those values There are
More informationIntroduction to Linux
Introduction to Linux The command-line interface A command-line interface (CLI) is a type of interface, that is, a way to interact with a computer. Window systems, punched cards or a bunch of dials, buttons
More informationWeek - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program.
Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 03 Euclid's Algorithm
More informationDATA STRUCTURE AND ALGORITHM USING PYTHON
DATA STRUCTURE AND ALGORITHM USING PYTHON Advanced Data Structure and File Manipulation Peter Lo Linear Structure Queue, Stack, Linked List and Tree 2 Queue A queue is a line of people or things waiting
More informationLecture 10: Working with Files. CS 383 Web Development II Monday, March 12, 2018
Lecture 10: Working with Files CS 383 Web Development II Monday, March 12, 2018 Working with Files Last week, we began to do some work with files through uploads, and we talked a little bit about headers
More informationSome Basic Terminology
Some Basic Terminology A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Here are a few terms you'll run into: A Application Files Program files environment where you can create and edit the kind of
More informationServer-side Web Development (I3302) Semester: 1 Academic Year: 2017/2018 Credits: 5 (50 hours) Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Server-side Web Development (I3302) Semester: 1 Academic Year: 2017/2018 Credits: 5 (50 hours) Dr Antoun Yaacoub 2 PHP forms This lecture
More informationTHE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering
THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering ENG224 Information Technology Part I: Computers and the Internet Laboratory 2 Linux Shell Commands and vi Editor
More informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.
C How to Program, 6/e Storage of data in variables and arrays is temporary such data is lost when a program terminates. Files are used for permanent retention of data. Computers store files on secondary
More informationImplementation should be efficient. Provide an abstraction to the user. Abstraction should be useful. Ownership and permissions.
File Systems Ch 4. File Systems Manage and organize disk space. Create and manage files. Create and manage directories. Manage free space. Recover from errors. File Systems Complex data structure. Provide
More informationFile Systems Ch 4. 1 CS 422 T W Bennet Mississippi College
File Systems Ch 4. Ë ¾¾ Ì Ï ÒÒ Ø Å ÔÔ ÓÐÐ 1 File Systems Manage and organize disk space. Create and manage files. Create and manage directories. Manage free space. Recover from errors. Ë ¾¾ Ì Ï ÒÒ Ø Å
More informationCS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays
CS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays C Arrays This handout was written by Nick Parlante and Julie Zelenski. As you recall, a C array is formed by laying out all the elements
More informationSahalsoftware college. Welcome To understanding Basic Computer Concept
Welcome To understanding Basic Computer Concept 1 Chapter1: Understanding Computer Concepts What is a computer? A computer is a machine that takes in data, processes if following a set of instructions
More informationFile System Definition: file. File management: File attributes: Name: Type: Location: Size: Protection: Time, date and user identification:
File System Definition: Computer can store the information on different storage media such as magnetic disk, tapes, etc. and for convenience to use the operating system provides the uniform logical view
More informationMaster Syndication Gateway V2. User's Manual. Copyright Bontrager Connection LLC
Master Syndication Gateway V2 User's Manual Copyright 2005-2006 Bontrager Connection LLC 1 Introduction This document is formatted for A4 printer paper. A version formatted for letter size printer paper
More informationChapter 5. Algorithms. Introduction. Chapter 5 Algorithms. Search algorithms. Linear search. Worked example
Chapter 5 Introduction Algorithms Algorithms are sets of instructions that can be followed to perform a task. They are at the very heart of what computer science is about. When we want a computer to carry
More informationITST Searching, Extracting & Archiving Data
ITST 1136 - Searching, Extracting & Archiving Data Name: Step 1 Sign into a Pi UN = pi PW = raspberry Step 2 - Grep - One of the most useful and versatile commands in a Linux terminal environment is the
More informationIn a Linux/Unix operating system, it is expressed as:
Lecture #10 Introduction Handing File I/O File I/O (input/output) refers to the transfer of data either to or from a file in a storage medium (such as a hard drive). Almost every programming language provides
More informationC/C++ Text File Functions
1 2 3 C/C++ Text File Functions fopen opens a text file. fclose closes a text file. feof detects end-of-file marker in a file. fscanf reads formatted input from a file. fprintf prints formatted output
More informationCSCI S-Q Lecture #12 7/29/98 Data Structures and I/O
CSCI S-Q Lecture #12 7/29/98 Data Structures and I/O Introduction The WRITE and READ ADT Operations Case Studies: Arrays Strings Binary Trees Binary Search Trees Unordered Search Trees Page 1 Introduction
More informationCRM CUSTOMER RELATIONSHIP MANAGEMENT
CRM CUSTOMER RELATIONSHIP MANAGEMENT Customer Relationship Management is identifying, developing and retaining profitable customers to build lasting relationships and long-term financial success. The agrē
More informationCRM CUSTOMER RELATIONSHIP MANAGEMENT
CRM CUSTOMER RELATIONSHIP MANAGEMENT Customer Relationship Management is identifying, developing and retaining profitable customers to build lasting relationships and long-term financial success. The agrē
More informationM.CS201 Programming language
Power Engineering School M.CS201 Programming language Lecture 16 Lecturer: Prof. Dr. T.Uranchimeg Agenda Opening a File Errors with open files Writing and Reading File Data Formatted File Input Direct
More informationIntroduction to Windows XP
1 Introduction to Windows XP 1.1 INTRODUCTION The windows operating system started with the introduction of Windows OS and Windows for work group for networking. Since then it has come a long way and Windows
More informationA comparison of the file systems used in RTLinux and Windows CE
A comparison of the file systems used in RTLinux and Windows CE Authors : Thomas Österholm, thoos207@student.liu.se Thomas Sundmark, thosu588@student.liu.se This report contains a comparison between some
More informationCSE 410 Final Exam 6/09/09. Suppose we have a memory and a direct-mapped cache with the following characteristics.
Question 1. (10 points) (Caches) Suppose we have a memory and a direct-mapped cache with the following characteristics. Memory is byte addressable Memory addresses are 16 bits (i.e., the total memory size
More informationArtDMX DMX control software V1.4
User manual ArtDMX DMX control software V1.4 1 2 Table of contents : 1. How to start a new Project...6 1.1. Introduction...6 1.2. System Requirements...6 1.3. Installing software and drivers...7 1.4. Software
More informationRescuing Lost Files from CDs and DVDs
Rescuing Lost Files from CDs and DVDs R 200 / 1 Damaged CD? No Problem Let this Clever Software Recover Your Files! CDs and DVDs are among the most reliable types of computer disk to use for storing your
More informationWeek 9 Lecture 3. Binary Files. Week 9
Lecture 3 Binary Files 1 Reading and Writing Binary Files 2 Binary Files It is possible to write the contents of memory directly to a file. The bits need to be interpreted on input Possible to write out
More informationBits and Bytes. Here is a sort of glossary of computer buzzwords you will encounter in computer use:
Bits and Bytes Here is a sort of glossary of computer buzzwords you will encounter in computer use: Bit Computer processors can only tell if a wire is on or off. Luckily, they can look at lots of wires
More informationExcel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller
Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing
More informationAt the end of this module, the student should be able to:
INTRODUCTION One feature of the C language which can t be found in some other languages is the ability to manipulate pointers. Simply stated, pointers are variables that store memory addresses. This is
More informationThe Big Python Guide
The Big Python Guide Big Python Guide - Page 1 Contents Input, Output and Variables........ 3 Selection (if...then)......... 4 Iteration (for loops)......... 5 Iteration (while loops)........ 6 String
More informationRenameMan User Guide. ExtraBit Software
RenameMan User Guide ExtraBit Software http://www.extrabit.com Version 3.1 August, 2005 Contents Introduction... 5 What does RenameMan do?... 5 Features... 5 Quick tour of RenameMan... 5 Getting started...
More informationUsing UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program
Using UNIX. UNIX is mainly a command line interface. This means that you write the commands you want executed. In the beginning that will seem inferior to windows point-and-click, but in the long run the
More informationCISC 110 Day 1. Hardware, Algorithms, and Programming
CISC 110 Day 1 Hardware, Algorithms, and Programming Outline Structure of Digital Computers Programming Concepts Output Statements Variables and Assignment Statements Data Types String and Numeric Operations
More informationDuring the first 2 weeks of class, all students in the course will take an in-lab programming exam. This is the Exam in Programming Proficiency.
Description of CPSC 301: This is a 2-unit credit/no credit course. It is a course taught entirely in lab, and has two required 2-hour 50-minute lab sessions per week. It will review, reinforce, and expand
More informationBIL 104E Introduction to Scientific and Engineering Computing. Lecture 12
BIL 104E Introduction to Scientific and Engineering Computing Lecture 12 Files v.s. Streams In C, a file can refer to a disk file, a terminal, a printer, or a tape drive. In other words, a file represents
More informationLab 4. Out: Friday, February 25th, 2005
CS034 Intro to Systems Programming Doeppner & Van Hentenryck Lab 4 Out: Friday, February 25th, 2005 What you ll learn. In this lab, you ll learn to use function pointers in a variety of applications. You
More informationSo computers can't think in the same way that people do. But what they do, they do excellently well and very, very fast.
Input What is Processing? Processing Output Processing is the thinking that the computer does - the calculations, comparisons, and decisions. Storage People also process data. What you see and hear and
More informationA Brief Introduction to the Linux Shell for Data Science
A Brief Introduction to the Linux Shell for Data Science Aris Anagnostopoulos 1 Introduction Here we will see a brief introduction of the Linux command line or shell as it is called. Linux is a Unix-like
More information(Refer Slide Time: 01:25)
Computer Architecture Prof. Anshul Kumar Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture - 32 Memory Hierarchy: Virtual Memory (contd.) We have discussed virtual
More informationTaskbar: Working with Several Windows at Once
Taskbar: Working with Several Windows at Once Your Best Friend at the Bottom of the Screen How to Make the Most of Your Taskbar The taskbar is the wide bar that stretches across the bottom of your screen,
More informationNEW -- NEW -- NEW - READ THE 'Q-DB SECTION
NEW -- NEW -- NEW - READ THE 'Q-DB SECTION QUICK LIST - NEW FEATURE as of v.6.0006 The basic Quick List functions are really easy to use. You may well find them one of the most useful 'extras' the program
More informationFiles and Streams Opening and Closing a File Reading/Writing Text Reading/Writing Raw Data Random Access Files. C File Processing CS 2060
CS 2060 Files and Streams Files are used for long-term storage of data (on a hard drive rather than in memory). Files and Streams Files are used for long-term storage of data (on a hard drive rather than
More informationCDs & DVDs: Different Types of Disk Explained
CDs & DVDs: Different Types of Disk Explained C 200 / 1 Don t Waste Money Buying the Wrong Type Find Out Which Disks Your PC Can Use! Your PC almost certainly has at least one CD/DVD drive. In its most
More informationSisulizer Three simple steps to localize
About this manual Sisulizer Three simple steps to localize Copyright 2006 Sisulizer Ltd. & Co KG Content changes reserved. All rights reserved, especially the permission to copy, distribute and translate
More informationBash command shell language interpreter
Principles of Programming Languages Bash command shell language interpreter Advanced seminar topic Louis Sugy & Baptiste Thémine Presentation on December 8th, 2017 Table of contents I. General information
More informationLong-term Information Storage Must store large amounts of data Information stored must survive the termination of the process using it Multiple proces
File systems 1 Long-term Information Storage Must store large amounts of data Information stored must survive the termination of the process using it Multiple processes must be able to access the information
More informationWYSE Academic Challenge Computer Science Test (State) 2013 Solution Set
WYSE Academic Challenge Computer Science Test (State) 2013 Solution Set 1. Correct Answer: E 2's complement systems are often used in computing because negating a number involves simple operations in the
More informationHow to Rescue a Deleted File Using the Free Undelete 360 Program
R 095/1 How to Rescue a Deleted File Using the Free Program This article shows you how to: Maximise your chances of recovering the lost file View a list of all your deleted files in the free Restore a
More informationSpeed Up Windows by Disabling Startup Programs
Speed Up Windows by Disabling Startup Programs Increase Your PC s Speed by Preventing Unnecessary Programs from Running Windows All S 630 / 1 When you look at the tray area beside the clock, do you see
More informationMain Parts of Personal Computer
Main Parts of Personal Computer System Unit The System Unit: This is simply the box like case called the tower, which houses the motherboard, which houses the CPU. It also houses all the drives, such as
More informationCOMP2100/2500 Lecture 17: Shell Programming II
[ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help] COMP2100/2500 Lecture 17: Shell Programming II Summary
More informationHere's how you declare a function that returns a pointer to a character:
23 of 40 3/28/2013 10:35 PM Violets are blue Roses are red C has been around, But it is new to you! ANALYSIS: Lines 32 and 33 in main() prompt the user for the desired sort order. The value entered is
More informationCST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1
Student Name: Lab Section: Linux File System Permissions (modes) - Part 1 Due Date - Upload to Blackboard by 8:30am Monday March 12, 2012 Submit the completed lab to Blackboard following the Rules for
More informationMicrosoft Expression Web is usually obtained as a program within Microsoft Expression Studio. This tutorial deals specifically with Versions 3 and 4,
Microsoft Expression Web is usually obtained as a program within Microsoft Expression Studio. This tutorial deals specifically with Versions 3 and 4, which are very similar in most respects and the important
More informationChapter-3. Introduction to Unix: Fundamental Commands
Chapter-3 Introduction to Unix: Fundamental Commands What You Will Learn The fundamental commands of the Unix operating system. Everything told for Unix here is applicable to the Linux operating system
More informationChapter 3 - Memory Management
Chapter 3 - Memory Management Luis Tarrataca luis.tarrataca@gmail.com CEFET-RJ L. Tarrataca Chapter 3 - Memory Management 1 / 222 1 A Memory Abstraction: Address Spaces The Notion of an Address Space Swapping
More informationText File I/O. #include <iostream> #include <fstream> using namespace std; int main() {
Text File I/O We can use essentially the same techniques we ve been using to input from the keyboard and output to the screen and just apply them to files instead. If you want to prepare input data ahead,
More informationChapter 11 Input/Output (I/O) Functions
EGR115 Introduction to Computing for Engineers Input/Output (I/O) Functions from: S.J. Chapman, MATLAB Programming for Engineers, 5 th Ed. 2016 Cengage Learning Topics Introduction: MATLAB I/O 11.1 The
More informationHexadecimal Numbers. Journal: If you were to extend our numbering system to more digits, what digits would you use? Why those?
9/10/18 1 Binary and Journal: If you were to extend our numbering system to more digits, what digits would you use? Why those? Hexadecimal Numbers Check Homework 3 Binary Numbers A binary (base-two) number
More information4.1 Ordered Lists Revisited
Chapter 4 Linked-lists 4.1 Ordered Lists Revisited Let us revisit our ordered-list. Let us assume that we use it for storing roll numbers of students in a class in ascending order. We can make the assumption
More informationProgramming Languages ML Programming Project Due 9/28/2001, 5:00 p.m.
Programming Languages ML Programming Project Due 9/28/2001, 5:00 p.m. Functional Suite Instead of writing a single ML program, you are going to write a suite of ML functions to complete various tasks.
More informationGet JAVA. I will just tell you what I did (on January 10, 2017). I went to:
Get JAVA To compile programs you need the JDK (Java Development Kit). To RUN programs you need the JRE (Java Runtime Environment). This download will get BOTH of them, so that you will be able to both
More informationCOMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts
COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool
More informationArm Assembly Language programming. 2. Inside the ARM
2. Inside the ARM In the previous chapter, we started by considering instructions executed by a mythical processor with mnemonics like ON and OFF. Then we went on to describe some of the features of an
More informationA Linear-Time Heuristic for Improving Network Partitions
A Linear-Time Heuristic for Improving Network Partitions ECE 556 Project Report Josh Brauer Introduction The Fiduccia-Matteyses min-cut heuristic provides an efficient solution to the problem of separating
More information12-Reading Data text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie
12-Reading Data text: Chapter 4.4-4.5 ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie Overview Reading Data from.txt Reading Data from.xls and.csv Reading Data from.mat User Interface
More information