1 / 20

CS 497C – Introduction to UNIX Lecture 16: - File Attributes

CS 497C – Introduction to UNIX Lecture 16: - File Attributes. Chin-Chih Chang chang@cs.twsu.edu. File Modification and Access Times. A UNIX file has three time stamps associated with it. Time of last file modification Time of last access Time of last inode modification

gaurav
Download Presentation

CS 497C – Introduction to UNIX Lecture 16: - File Attributes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 497C – Introduction to UNIXLecture 16: - File Attributes Chin-Chih Changchang@cs.twsu.edu

  2. File Modification and Access Times • A UNIX file has three time stamps associated with it. • Time of last file modification • Time of last access • Time of last inode modification • When a file’s contents are changed, its last modification time is updated by the kernel. • The –t option of ls present files in order of their modification time instead of the ASCII collating sequence.

  3. File Modification and Access Times • The –u option of ls displays a file’s access time. • If you view the contents of the file with the cat command, you’ll update its access time but not the modification time. • The –r (reverse) option of ls lists files in a reverse order. • If a file is incorrectly stamped when extracting it, you can use touch to rest the times.

  4. Touch: Changing the Time Stamps • The touch command changes these times and is used in the following manner: touch options expression filename(s) • When touch is used without options or an expression, both times are set to the current time. • When touch is used without options but with an expression, it changes both time.

  5. Touch: Changing the Time Stamps • The expression consists of an eight-digit number – using the format MMDDhhmm (month, day, hour, and minute). • Here is an example: $ ls -l chap3 -rw-r--r-- 1 cs497c grader 306 Sep 26 11:55 chap3 $ ls -lu chap3 -rw-r--r-- 1 cs497c grader 306 Sep 27 23:39 chap3 • The first one shows the modification time. The second one shows the access time.

  6. Touch: Changing the Time Stamps • touch changes both modification and access time: $ date Sun Sep 30 20:57:56 CDT 2001 $ touch 09302057 chap3; ls -l chap3 -rw-r--r-- 1 cs497c grader 306 Sep 30 20:57 chap3 $ ls -lu chap3 -rw-r--r-- 1 cs497c grader 306 Sep 30 20:57 chap3 • With the –m (modification) option, you can alter the modification time alone:

  7. Touch: Changing the Time Stamps • With the –a (access) option, you can alter the modification time alone. • The system administrator often uses touch to touch up these times so that a file may be included in or excluded from an incremental backup.

  8. File Systems and Inodes • All the attributes that we have discussed are stored in a table called the inode. • Every file has one inode and is accessed by a number called the inode number. • The inode number for a file is unique in a single file system. • Every file system has a separate area earmarked for holding inodes. ls fetches the attributes of files from their inodes.

  9. ln: Links • UNIX allows a file to have more than one name and yet maintain a single copy in the disk. This file is then said to have more than one link. • A file can have as many names as you want to give it, but they all have the same inode number.

  10. ln: Links • A file is linked with the ln (link) command which takes two filenames as arguments. The first one is the existing file. The second one is the alias we provide. • The following command links the existing file display.sh with print.sh: ln display.sh print.sh • The –i option of ls displays the inode number of a file.

  11. ln: Links • When we use rm to remove files, rm actually removes a link from the file. It bring the link count down to one. • These are three applications when we need to link a file: • Use a link to “notionally place” a file in a specific directory where many programs expect to find it.

  12. ln: Links • C and the shell programming language support a feature which lets a program know the name by which it is called. • Link useful files in a common directory. • The ordinary links have two serious drawbacks: • You can’t link a file across two file systems. • You can’t line a directory even within the same file system.

  13. Symbolic Links • A symbolic link overcomes both these problems. • Unlike the other link, a symbolic link is a directory entry that points to the file or directory that actually has the contents. • A symbolic link is also known as a soft link. The ordinary link is called a hard link.

  14. Symbolic Links • You can identify the symbolic links by the ls –l command. • Use the –i (node) option of ls shows the inode number of the symbolic link. $ ln -s chap3 chap4 $ ls -li chap3 chap4 612393 -rw-r--r-- 1 cs497c grader 306 Sep 30 20:57 chap3 612388 lrwxrwxrwx 1 cs497c grader 5 Sep 30 22:14 chap4 -> chap3 • Use the –F (classiFy) option of ls shows the symbolic link with a trailing @ symbol.

  15. find: Locating Files • find is one the power tools of the system. It recursively examines a directory tree to look for files either by name or by matching one or more file attributes. • find can be broken up into three components: find path_list selection_criteria action • Let’s check the following example: find /home –name index.html –print

  16. find: Locating Files • It recursively examines all files in the /home directory, selects the file with the name index.html, and takes the action –print to display the found files. find . –name “*.lst” –print find . –name ‘[A-Z]*’ -print • The –type operator followed by the letter f, d, or l selects files of the ordinary, directory, and symbolic link type.

  17. find: Locating Files $ find /home/henry –type d –print • You can also use the –perm operator to locate files having a specified set of permission. find . –perm 666 -print • If a file is symbolic link pointing to a directory, then find by default won’t into that directory. We can use –follow operator, find locates the file.

  18. find: Locating Files $ find . –name night.gif –follow -print • You can use the –mtime operator to match a file’s modification time. (-atime matches the access time.) • If you want to check the files that have been modified in less than two days, use: $ find . –mtime –2 print

  19. find: Locating Files • find uses the –ls action component to display a special listing of those files that were found. • find uses the operators –a and –o to signify the AND and OR conditions. • You can take action on selected files with -exec and –ok operator. • The command is executed and terminated with sequence {} \; where {} represents filename.

  20. find: Locating Files $ find /var/preserve –mtime +30 –exec rm –rf {} \; • You can use the –ok operator instead of -exec for interactive deletion. $ find /home –size +2000 –atime +180 –ok rm {} \; • GNU find doesn’t need –print option; it prints by default. $ find –name “*.java”

More Related