CUNY CSCI 132 - Displaying Information about Files

Unformatted text preview:

Displaying Information about FilesViewing File PropertiesUsing ls to View File PropertiesOptions for lsLong ListingsInterpreting a Long ListingMeasuring Storage CapacityFile SizeFile ModePermissionsTypes of File AccessExampleCreating Empty FilesChecking Disk Capacity and Free SpaceThe df CommandThe df Command's OutputAbout Mount PointsIllustrationIllustration (continued)Illustration continuedThings to tryCopyright 2006 Stewart WeissCopyright 2006 Stewart WeissDisplaying Information about FilesDisplaying Information about FilesCommands for Viewing File Properties2 CSci 132 Practical UNIX with PerlViewing file propertiesA file has two components: Contents PropertiesContents are the data contained in the file. Properties are characteristics of the file such as its size, ownership, security tags, and type.Here we concentrate on how to display the properties of files.3 CSci 132 Practical UNIX with Perl ls revisitedThe ls command lists the files in a given directory.(If ls is given a non-directory file as an argument, it just lists or displays information about that file.)ls has several flags that control what information is displayed, or that change the format or order in which the information is presented. You already know, for example, that –a lists hidden files. There are other useful flags. I will cover –F, -R, -d, and –l.4 CSci 132 Practical UNIX with PerlOptions for ls-F appends a trailing character to the file name to indicate its type ("/" for directory, "*" for executable, or "@" for symbolic link.)-R lists the entire hierarchy rooted at the given directory, recursively. This means, informally, that if any file is a directory, its contents are also listed, and if any of its files is a directory, its contents are also listed, and so on. A specific order is used; try it and see what the order is.-d displays information about the directory itself instead of its contents.5 CSci 132 Practical UNIX with PerlLong listingsThe most important and most frequently used flag is –l, which generates a long listing of the directory. For example:$ ls –l homeworks-rw------- 1 sweiss faculty 3170 Apr 21 17:29 hwk4For each file, 7 fields are displayed; each of these is a specific property. They are defined in the next slide.6 CSci 132 Practical UNIX with PerlInterpreting a long listingSome of these fields are self-explanatory: user is the username of the owner; filesize is the number of bytes in the file; time last modified is the time that the file was last changed in some way, not just read or opened, but changed. I'll discuss links and groups another time. First a word about filesize.file mode-rw-------# of linksuser(owner)group filesize (bytes)time last modifiednamesweiss faculty 31701 Apr 21 17:29hwk47 CSci 132 Practical UNIX with PerlMeasuring storage capacityJust in case you did not know, a bit is the smallest unit of information content. It is either 1 or 0 (on or off, true or false, etc). Building on bits:1 byte = 8 bits1 kilobyte (KB) = 1024 bytes1 megabyte (MB) = 1024 kilobytes ~ 106 bytes1 gigabyte (GB) = 1024 megabytes ~ 109 bytes1 terabyte (TB) = 1024 gigabytes ~ 1012 bytes8 CSci 132 Practical UNIX with PerlFile sizeEven though a bit is the smallest unit of information, files are measured in bytes because bytes are the smallest unit of storage. A single character such as a letter or digit or punctuation mark currently requires a byte of storage on older computer systems (and will someday require two bytes on all systems.)9 CSci 132 Practical UNIX with PerlFile modeThe file mode is a string of 10 letters that describes what kind of file it is, and who has permission to do what to the file. The first letter identifies the type of file: "d" for directory, "-" for regular file, "c" or "b" for device files, "l" for symbolic link, and so on. (There are some other types not worth mentioning now.)file moderw------- sweiss faculty 31701 Apr 21 17:29 hwk4-type permission10 CSci 132 Practical UNIX with PerlPermissionsThe file mode lets you see the permissions on a file. In UNIX, the universe is divided into three sets of users:user the owner of the filegroup the UNIX group that "owns" the fileothers everyone not in either of the first two setsThe permission string has 3 bits for each set, a read-bit, a write bit, and an execute-bit:_ _ _ _ _ _ _ _ _ r w x r w x r w xuser group others11 CSci 132 Practical UNIX with PerlTypes of file access A user can access a file to do one of three things:read it (view its contents)write it (change or modify it)execute it (run it if it is a program)If the user has permission to read, the 'r' bit is set; if to write, the 'w' bit is set, and if to execute, the 'x' bit is set. If a bit is not set, a dash '-' appears instead of r, w or x in the permission string.12 CSci 132 Practical UNIX with PerlExampleGiven file mode -rwxrw-r--break it up into the type and 3 groups of user bits:- rwx rw- r--The leading dash '-' indicates that this is a regular file. The owner (user) has read, write, and execute permission (rwx); the group has read and write permission but not execute permission (rw-), and everyone else can only read the file (r--).13 CSci 132 Practical UNIX with PerlCreating empty filesThe touch command was designed to update the time of last modification of a file; if you touch a file, it is like you have made it current. (You made it dirty by touching it, and so it is marked dirty, as if you wrote in it.) (The usefulness of this will be apparent later.)If you touch a file that does not exist, UNIX creates it.$ touch museumpiececreates museumpiece if it did not exist, or it makes it dirty if it did.14 CSci 132 Practical UNIX with PerlChecking Disk Capacity and Free SpaceThe df command, intended to report on the status of mounted file systems, provides an easy way to check the amount of free space and the capacity of all the storage available on the UNIX system.A file system is like an apartment building. It is an organized collection of units available for occupancy (by data), with a means of identifying them, finding them, determining which are occupied and which are not, and retrieving or placing the occupants.A file system is mounted if it is connected to the single file hierarchy rooted at /.15 CSci 132 Practical UNIX with PerlThe df CommandWhen you type the df command, it outputs lines containing 6 fields, including the name of the (mounted) file system, its total capacity in kilobytes,


View Full Document

CUNY CSCI 132 - Displaying Information about Files

Download Displaying Information about Files
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Displaying Information about Files and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Displaying Information about Files 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?