9781111543709 _PPT_ch07

advertisement
Guide to Parallel Operating
Systems with
Windows 7 and Linux
Chapter 7
Files and File Attributes
Objectives
• Describe the contents of files and identify the
application that created a particular file
• Describe the use of file attributes
• Find files based on their name or content
Guide to Parallel Operating Systems with Windows 7 and Linux
2
Contents of Files
• File:
– Discrete set of information
• OS stores program modules in file systems
• Save documents under filenames for future use
• Section learning goals:
– Recognizing the contents of files
– Recognizing actions a given OS takes to open a file
Guide to Parallel Operating Systems with Windows 7 and Linux
3
Contents of Files in Windows 7
• Filename: name plus “.” plus extension
– Example: default.htm
• Two types of extensions:
– Short extension is three characters (older convention)
– Long extension exceeds three characters
• Extensions indicate type of data stored in a file
• Windows 7 appends extension to filename prefix
Guide to Parallel Operating Systems with Windows 7 and Linux
4
Viewing File Extensions in Windows 7
• Windows tracks the extensions your PC uses
• Viewing registered file extensions:
– Click Start-> Control Panel -> click Default
Programs, and then click “Associate a file type or
protocol with a program”
– Example: MS WordPad documents have an
extension of .rtf
• Administrative rights required to modify extensions
Guide to Parallel Operating Systems with Windows 7 and Linux
5
Figure 7-1 File extensions in Windows 7
Courtesy Course Technology/Cengage Learning
Guide to Parallel Operating Systems with Windows 7 and Linux
6
Viewing File Extensions in Windows 7
(continued)
• File associations
– Which icon appears for a file in Windows Explorer
– Which commands appear in a file’s shortcut menu
Which application opens if a user double-clicks a file
• Icon appearance in Windows Explorer
– Eliminated feature:
• Displaying different icons for files based on file type
Guide to Parallel Operating Systems with Windows 7 and Linux
7
Commands in a File’s Shortcut Menu
• Right-click a file icon to view a shortcut menu
• Choices appearing on all file shortcut menus:
–
–
–
–
Create a shortcut
Delete a file
Rename a file
View file properties
• Some shortcut menu items are object specific:
– Example: Open and Print are used in MS WordPad
• Bold items identify default response to double-click
Guide to Parallel Operating Systems with Windows 7 and Linux
8
Figure 7-2 Context menu
Courtesy Course Technology/Cengage Learning
Guide to Parallel Operating Systems with Windows 7 and Linux
9
Opening Applications
• Default response to double-clicking a file icon:
– Windows 7 opens file in associated application
• Example: response to double-clicking Homework.rtf
– OS opens the file In WordPad because:
• WordPad is associated with .rtf files
• Default action in Folder Options is defined as Open
• Changing the default program:
– Right-click the file icon, then click Open with
– From the dialog box that appears:
• Browse for program to use with the selected file type
Guide to Parallel Operating Systems with Windows 7 and Linux
10
Figure 7-3 Open with dialog box showing default program for .rtf files
Courtesy Course Technology/Cengage Learning
Guide to Parallel Operating Systems with Windows 7 and Linux
11
Applications in Windows 7
• Table 7-1:
– Lists common file extensions for business
applications
• Table 7-2:
– Identifies the programming language for a particular
source file
• Table 7-3:
– Lists some of the many Internet file extensions and
formats you may encounter
• Table 7-4:
– Lists the files you are most likely to encounter
Guide to Parallel Operating Systems with Windows 7 and Linux
12
Table 7-1 Common business applications and their file extensions
Guide to Parallel Operating Systems with Windows 7 and Linux
13
Table 7-2 Common programming source files
Guide to Parallel Operating Systems with Windows 7 and Linux
14
Table 7-3 Common Internet files
Guide to Parallel Operating Systems with Windows 7 and Linux
15
Table 7-4 Common Windows 7 files
Guide to Parallel Operating Systems with Windows 7 and Linux
16
Viewing the Contents of Text Files
• TYPE command:
– Displays contents of a text file line by line
– Example: TYPE Pgm1Data.txt
• MORE command:
– Displays text data files one screen at a time
– Example: TYPE Pgm1Data.txt | MORE
– Syntax: MORE [/E [/C] [/P] [/S] [/Tn]
[þn]] < drive:][path]filename
• MORE < Pgm1Data.txt:
– Displays contents of the Pgm1Data.txt file
Guide to Parallel Operating Systems with Windows 7 and Linux
17
Contents of Files in Fedora 13
• Fedora 13 and Windows 7 file similarities:
– Filenames may have extensions
– OS associations open files in usable formats
• Extension not required to open a file from the CLI
• Inode:
– Used to store applications files and directory attributes
– Does not contain file/directory name or actual data
• Filename does not require an extension
• When a file is created:
– It is assigned both a name and an inode number
Guide to Parallel Operating Systems with Windows 7 and Linux
18
Contents of Files in Fedora 13
(continued)
Table 7-5 Extensions for Fedora 13 compressed and archived files
Guide to Parallel Operating Systems with Windows 7 and Linux
19
Contents of Files in Fedora 13
(continued)
Table 7-6 Extensions for Fedora 13 multimedia files
Guide to Parallel Operating Systems with Windows 7 and Linux
20
Contents of Files in Fedora 13
(continued)
Table 7-7 Extensions for Fedora 13 system
configuration and installation packaging files
Guide to Parallel Operating Systems with Windows 7 and Linux
21
Contents of Files in Fedora 13
(continued)
Table 7-8 Extensions for Fedora 13 programming files
Guide to Parallel Operating Systems with Windows 7 and Linux
22
Contents of Files in Fedora 13
(continued)
• ls command with the –l option
– Determines file type
– ls –l /dev | more:
• Lists files in the devices folder
• Syntax for the file command:
– file[filename(s)]
• file Pgm1Data:
– Examines a plain text file named Pgm1Data
Guide to Parallel Operating Systems with Windows 7 and Linux
23
Figure 7-4 Listing Fedora 13 file types
Courtesy Course Technology/Cengage Learning
Guide to Parallel Operating Systems with Windows 7 and Linux
24
Contents of Files in Fedora 13
(continued)
Table 7-10 Fedora 13 file command types
Guide to Parallel Operating Systems with Windows 7 and Linux
25
Viewing Files in Fedora 13
• Use cat command to view or concatenate files:
– Example: cat –bsT Pgm1Data
• more command syntax: more [-dlfpcsu] [file
...]
• Some more command options:
-num: specifies screen size in lines (an integer value)
-d: displays “[Press ‘h’ for instructions]”
-f: causes more to count logical lines (not folded)
• To display the contents of myfile:
cat myfile
more –dfs red_canoe
Guide to Parallel Operating Systems with Windows 7 and Linux
26
Using File Attributes
• File attributes:
– Labels describing and regulating files
– Associated with every file in Windows 7
– Maintained by components in Windows 7
• Windows 7 handles file attributes most of the time
• Users can also manipulate file attributes:
– Learning the technique will prove useful
Guide to Parallel Operating Systems with Windows 7 and Linux
27
Using File Attributes in the
Windows 7 CLI
• File attributes have binary values of 1 (on) or 0 (off)
• The four DOS file attributes are:
–
–
–
–
Read-only: allows file viewing, but not modification
Archive: set to on when file is created or modified
System: marks a file as a system file (a warning)
Hidden: hides a file from other commands
Guide to Parallel Operating Systems with Windows 7 and Linux
28
Viewing DOS File Attributes
• View attributes and access methods with ATTRIB
• ATTRIB syntax: ATTRIB
[drive:][path][filename][/S]
– [drive:][path][filename]: specifies file(s) to
process
– /S: matches files in current folders and subfolders
– Similar to DIR command
• Wildcards must be used in ATTRIB command:
– Without wildcards, no files will match
Guide to Parallel Operating Systems with Windows 7 and Linux
29
Viewing DOS File Attributes
(continued)
Figure 7-8 Viewing DOS file attributes
Courtesy Course Technology/Cengage Learning
Guide to Parallel Operating Systems with Windows 7 and Linux
30
Setting DOS File Attributes
• ATTRIB: shows or changes DOS file attributes
– Syntax: ATTRIB [+R | -R] [+A | -A] [+S |
-S] [+H | -H] [drive:][path][filename]
[/S [/D]]
+: sets an attribute
-: clears an attribute
R: read-only file attribute
A: archive file attribute
S: system file attribute
H: hidden file attribute
• Example: ATTRIB +H Secret
– Hides the directory named Secret
Guide to Parallel Operating Systems with Windows 7 and Linux
31
Using the DIR Command with
File Attributes
• Use DIR to view filenames and specified attributes
• Syntax: DIR [drive:][path][filename]
[/A[[:]attributes]]
[drive:][path][filename]: specifies drive,
directory, files
/A: displays files with specified attributes
Attributes: “D”,“R”, “H”, “A”, “S”, “-” (logical not
prefix)
Guide to Parallel Operating Systems with Windows 7 and Linux
32
Using the XCOPY Command with File
Attributes
• XCOPY syntax: XCOPY source [destination]
[/A | /M] [/H] [/R] [/K]
• Attribute options:
/A: copies only files with the archive attribute set
• Used for differential backup as archive bit is not reset
/M: copies files with archive bit set; turns off archive
bit
• Used in incremental backup as archive bit is reset
/H: copies hidden and system files
/R: overwrites read-only files
/K: copies attributes; read-only is typically reset
Guide to Parallel Operating Systems with Windows 7 and Linux
33
Using the XCOPY Command with File
Attributes
Figure 7-11 XCOPY command used with file attributes
Courtesy Course Technology/Cengage Learning
Guide to Parallel Operating Systems with Windows 7 and Linux
34
Using File Attributes in the
Windows 7 GUI
• Additional attributes: Index, Compression, Encryption
– Applies to folders or files residing on an NTFS volume
• Index:
– File/Folder indexed by Indexing Service when bit is set
– Windows Indexing Service organizes files for search
– Index created by Windows 7 can be queried
• Compression:
– File or folder is compressed when bit is set
• Encryption:
– File or folder encrypted when bit is set
Guide to Parallel Operating Systems with Windows 7 and Linux
35
Figure 7-12 Windows 7 advanced file attributes
Courtesy Course Technology/Cengage Learning
Guide to Parallel Operating Systems with Windows 7 and Linux
36
Using Compression in Windows 7
• Compressing files:
– Decreases file size
– Reduces space that files use on your drives
• Compressing folders:
– Decreases space used by files stored in a folder
• Disadvantage of compression:
– Potential loss of performance
Guide to Parallel Operating Systems with Windows 7 and Linux
37
Using Encryption in Windows 7
• Encryption: restricts file viewing
• Users who may view (decrypt) encrypted files:
– Individual who encrypted the file
– Administrator (account has a global key)
• Encrypting File System (EFS) performs encryption:
– Installed automatically on Windows 7
Guide to Parallel Operating Systems with Windows 7 and Linux
38
Using File Attributes in Fedora 13
• lsattr: used to view attributes on extended file
system
• Some attributes:
a (“no Access time”): last access time not updated
A (“append only”)
• Set for file: only allows append operations
• Set for directory: files may only be added to directory
• lsattr command syntax:
lsattr [options] [file(s)]
• Some lsattr command options:
-d: lists directories like other files
-v: lists the file’s version/generation number
Guide to Parallel Operating Systems with Windows 7 and Linux
39
Using the ls Command to Find
Hidden Files
• ls command:
– Views filenames with specific file type attributes
– Syntax: ls [OPTION]... [FILE]...
– Some options:
-a, --all: does not hide entries starting with “.”
-l: uses a long listing format
-p, --file-type: appends an indicator of /, =,
@, or | to entries to indicate types of files
Guide to Parallel Operating Systems with Windows 7 and Linux
40
Figure 7-14 Using the Fedora 13 ls command to show hidden files and file types
Courtesy Course Technology/Cengage Learning
Guide to Parallel Operating Systems with Windows 7 and Linux
41
Using Compression in Fedora 13
• Compressing files:
– Decreases their size
– Reduces amount of space they use on drives
• Folder compression:
– Decreases amount of space used by all file
• gzip:
– Commonly used GNU compression utility
– By default: deletes ASCII file it compresses
– Command: basis for gunzip and zcat
Guide to Parallel Operating Systems with Windows 7 and Linux
42
Using Compression in Fedora 13
(continued)
• zcat utility:
– Identical to using the gunzip –c command
– Keeps the original filename and stamp
• Syntax:
gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [
filename ... ]
gunzip [ -acfhlLnNrtvV ] [-S suffix] [
filename ... ]
zcat [ -fhLV ] [ filename ... ]
Guide to Parallel Operating Systems with Windows 7 and Linux
43
Using Compression in Fedora 13
(continued)
• Some switches for gzip, gunzip, and zcat:
-a –ascii: converts end-of-line characters
-c --stdout --to-stdout: writes output to
standard output
-L –license: displays the license and quits
• Syntax to compress file:
– gzip myfile
• Syntax to decompress a file:
– gzip –d myfile
Guide to Parallel Operating Systems with Windows 7 and Linux
44
Using Compression in Fedora 13
(continued)
• gunzip myfile: decompresses a file
• zcat utility:
– Decompresses files created by gzip, zip
• zcat myfile: decompresses a file
• tar command:
– Works in conjunction with gzip
– Packages multiple files into one file
– Syntax: tar [flags] archive-file-name
files-to-archive
– Some options: -c, --create, --delete, -r,
--append, -t, --list, -u, --update
Guide to Parallel Operating Systems with Windows 7 and Linux
45
Using Encryption in Fedora 13
• Only user who encrypted file or an administrator
can decrypt encrypted files
• gpg:
– Most popular encryption utility
– Syntax: gpg [--homedir name] [--options
file] [options] command [args]
– Some options:
-c: encrypts with a symmetric cipher
--decrypt [file]: Decrypts file, writes it to
standard output
o, --output file: writes output to a file
Guide to Parallel Operating Systems with Windows 7 and Linux
46
Finding Files
• Finding files in the Windows 7 CLI
– Searches are based on filenames or file contents
– Pattern-matching methods used in content searches
– Three commands used to search for files:
• DIR
• FIND
• FINDSTR
Guide to Parallel Operating Systems with Windows 7 and Linux
47
Finding Files with the DIR Command
• DIR command supports wildcards
• Two wildcards used: question (?), asterisk (*)
• Use ? to substitute for single unknown:
– Example: DIR ? .cpp
• Command applies in current directory
• Lists all files beginning with any letter and ending in .cpp
• Use * to substitute for multiple unknown characters
– A period extends search to include all file extensions
– Example: DIR h*
• Lists all files beginning with “h” in the current directory
Guide to Parallel Operating Systems with Windows 7 and Linux
48
Finding Files with the DIR Command
(continued)
Table 7-11 Multiple-character substitutions for searches
Guide to Parallel Operating Systems with Windows 7 and Linux
49
Finding Files with the DIR Command
(continued)
Table 7-12 Single-character substitutions for searches
Guide to Parallel Operating Systems with Windows 7 and Linux
50
Finding Files with the FIND Command
• FIND syntax: FIND [/V] [/C] [/N] [/I]
string [[drive:][path]filename[ ...]]
/V: displays all lines without the specified string
/C: displays the count of lines that contain the string
/N: displays line numbers with the displayed lines
/I: ignores the case of characters when searching
• Example: FIND /I "Good" *.*
• Redirection operators: “<“ for input and “>” for output
– Example: FIND /I "Football"
<Winners.txt>FootballWinners.txt
• Finds all lines that contain Football in a file named
Winners.txt
Guide to Parallel Operating Systems with Windows 7 and Linux
51
Finding Files with the FINDSTR
Command
• Use FINDSTR for more refined searches
• FINDSTR command syntax: FINDSTR [/B] [/E]
[/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M]
[/O] [/P] [/C:string] strings
[[drive:][path]filename[ ...]]
• Some switches:
/B: matches the pattern at the beginning of a line
/I: specifies that the search is not case sensitive
• Example: FINDSTR /I "good fool" *.*
– Finds files containing “good” or “fool”
Guide to Parallel Operating Systems with Windows 7 and Linux
52
Finding Files with the FINDSTR
Command
Figure 7-22 Finding files using the FINDSTR command
Courtesy Course Technology/Cengage Learning
Book Title
53
Finding Files with the FINDSTR
Command (continued)
Table 7-13 FINDSTR examples
Guide to Parallel Operating Systems with Windows 7 and Linux
54
Using the FINDSTR Command with
Regular Expressions
• Regular expressions: specify patterns of text
• Notation uses metacharacters and literal characters
– Metacharacter: symbol with special meaning
• Examples: an operator or delimiter
– Literal character: characters with no special meaning
• Examples: letters and numbers
• Some examples of regular expressions:
w.*ing: strings starting with “w” and ending with “ing”
[ABX]: matches any occurrence of “A”, “B”, or “C”
Guide to Parallel Operating Systems with Windows 7 and Linux
55
Finding Files in Windows 7 with
Windows Search
• Windows Search: most direct way to locate a file
• All or partial name of file/folder can be used to search
• Using quotation marks with Windows Search
– To search on more than one word:
• Place the phrase in quotation marks
• Using wildcards with Windows Search
– Add asterisk (*) to a search term to:
• Represent an unknown string of letters or numbers
– Question mark (?): single character wildcard
Guide to Parallel Operating Systems with Windows 7 and Linux
56
Finding Files in Windows 7 with
Windows Search (continued)
• Using file sizes with Windows Search
– Keyword size: used when you know approximate
size of file
– Example: resume size:<100KB
• Finds a file that is less than 100 kilobytes (KB) and
contains the word resume
– Some operators:
• <: less than
• <=: less than or equal to
• >: greater than
• =>: greater than or equal to
Guide to Parallel Operating Systems with Windows 7 and Linux
57
Using Dates and Date Ranges with
Windows Search
• Relative dates can be used in a search:
– Example: today, tomorrow, or yesterday
• Word combinations can be used in a search:
– Example: this, last, past, and coming with week,
month, and year -> thisweek, nextmonth,
pastmonth, and comingyear
• To find a file created in 2010:
– Enter created:<1/1/2011
Guide to Parallel Operating Systems with Windows 7 and Linux
58
Searching by Kind
• kind: command
– Used to narrow search results
– Example: vacation kind:photo or vacation
kind: pictures
• Finds only pictures that include vacation in description
• kind:music
– Finds all mp3 files, wma files, wav files, etc.
Guide to Parallel Operating Systems with Windows 7 and Linux
59
Finding Files in Windows 7 with
Windows Search (continued)
• Searching by type
– type: command:
• Used to narrow search if result of kind command is
too broad
• Searching by file properties
– Windows Search:
• Indexes the filename and metadata for every file type
• Indexes the entire contents of many file types
– To find Word documents created by Bill Jones:
• Enter type:doc author:BillJones
Guide to Parallel Operating Systems with Windows 7 and Linux
60
Finding Files in Fedora 13
• Finding files with the ls command in Fedora 13
ls command:
• Supports same basic wildcards used in Windows
– Example: ls –l myfile*
• Finds files using ls command and wildcard
expression
Guide to Parallel Operating Systems with Windows 7 and Linux
61
Finding Files with the find Command
in Fedora 13
• How the find command works:
–
–
–
–
Searches a directory tree by evaluating an expression
Lists the files that match the expression
Returns 0 if all files are processed successfully
Returns greater than 0 if an errors occurs
• Three elements in the search expression:
– Options: affect overall operation; always return true
– Tests: these elements return a true or false value
– Actions: have side effects; return a true or false value
• Elements are separated by operators; e.g., -and
Guide to Parallel Operating Systems with Windows 7 and Linux
62
Table 7-16 Order of precedence for expressions in the Fedora 13 find command
Guide to Parallel Operating Systems with Windows 7 and Linux
63
Finding Files with the find Command
in Fedora 13 (continued)
• Some options used with the find command:
– -xdev: does not check directories on other file
systems
– -ctimen: file’s status last changed n hours ago
– -empty: file is empty (either regular file or directory)
– -links n: file has n links
• Example 1: find /etc –type d | more
– Locates directories
• Example 2: find /etc –type l | more
– Locates links
Guide to Parallel Operating Systems with Windows 7 and Linux
64
Finding Files with the find Command
in Fedora 13 (continued)
• xargs command:
– Often piped with the find command to construct an
argument list
– Syntax: xargs [options] [command]
• To locate files that include a certain string pattern:
find . -name ’myfile*’ -print | xargs n2 grep ’compression’
find . -name ’myfile*’ -print | xargs n2 grep ’compression6’
find . -name ’myfile*’ -print | xargs n2 grep ’compression[46]’
Guide to Parallel Operating Systems with Windows 7 and Linux
65
Finding Files with the find Command
in Fedora 13 (continued)
• grep command:
– Syntax: grep [options] [-e PATTERN | -f
FILE] [FILE...]
– Searches named input files for lines that contain a
match of the given PATTERN
– By default: prints matching lines
– Some options:
-c –count: suppresses normal output
-f FILE --file=FILE: obtains patterns from FILE
-H --with-filename: prints filename for each match
Guide to Parallel Operating Systems with Windows 7 and Linux
66
Summary
• Files can have different types of contents
• File attributes:
– Provide information about a file’s access privileges
• As directories are built, more files are added
• Using the Search feature in Windows 7:
– You can locate files by their contents, as you can with
the FINDSTR command
• File compression:
– Saves disk space by removing duplicated data in files
Guide to Parallel Operating Systems with Windows 7 and Linux
67
Download