RH033 Unit13 Finding and Processing Files

Ojectives
Upon completion of this unit, you should be able to:
  • Use locate
  • Use find
  • Use the Gnome Search tool
locate
1) Queries a pre-built database of paths to files on the system
  • Database must be updated by administrator
  • Full path is searched, not just filename
2) May only search directories where the user has read and execute permission
locate Examples
1) locate foo
  • Search for file with “foo” in the name of path
2) locate �Cr ‘\.foo$’
  • Regex search for files ending in “.foo”
3) Useful options
  • -i performs a case-insensitive search
  • -n x lists only the first x matches
find
1) find [directory…][criteria]
2) Searches directory trees in real-time
  • Slower but more accurate than locate
  • CWD is used if no starting directory given
  • All files are matched if no criteria given
3) Can execute commands on found files
4) May only search directories where the user has read and execute permission
Basic find Examples
1) find �Cname snow.png
  • Search for files named snow.png
2) find �Ciname snow.png
  • Case-insensitive search for files named snow.png.
3)  find �Cuser joe �Cgroup joe
  • Search for files owned by the user joe and the group joe
find and Logical Operators
1) Criteria are ANDed together by default
2) Can be OR’d negated with �Co and �Cnot
3) Parentheses can be used to determine logic order, but must be escaped in bash.
  • find �Cuser joe �Cnot �Cgroup joe
  • find �Cuser joe �Co �Cuser jane
  • find �Cnot \(-user joe �Co �Cuser jane \)
find and Permissions
1) Can match ownership by name or id
  • find / �Cuser joe �Co �Cuid 500
2) Can match octal or symbolic permissions
  • find �Cperm 755 matches if mode is exactly 755
  • find �Cperm +222 matches if anyone can write
  • find �Cperm �C222 matches if everyone can write
  • find �Cperm �C002 matches if other can write
A numeric permission preceded by + will match files that have at least one bit (user, group or other) for that permssion set. A �C sign before a permission means that all three instance of that bit must be on. 0 mean a permission of at least nothing.
find and Numeric Criteria
1) Many find criteria take numeric values
2) find �Csize 1024k (Files with a size of exactly 1 megabyte)
3) find �Csize +1024k (Files with a size over 1 megabyte)
4) find �Csize �C1024k (Files with a size less than 1 megabyte)
find and Access Times
1) find can match by inode timestamps
  • -atime when file was last read
  • -mtime when file data last changed
  • -ctime when files data or metadata last changed
2) Value give is in days
  • find �Cctime 10 (Files modified less than 10 days ago)
Executing commands with find
1) Commands can be executed on found files
  • Command must be preceded with �Cexec or �Cok (-ok prompts before acting on each file)
2) Command must end with space\;
3) Can use {} as a filename placeholder
4) find �Csize +1024k �Cok gzip {} \;
find Execution Examples
1) find �Cname “*.conf” �Cexec cp {} {}.orig \;
  • Backup configuration files, adding a .orig extension
2) find /tmp �Cctime +3 �Cuser joe �Cok rm {} \;
  • Prompt to remove Joe’s tmp files that are over 3 days old
3) find ~ �Cperm +o+w �Cexec chmod o-w {} \;
  • Fix other-writable files in your home directory
The Gnome Search Tool
1) Places �C> Search for Files
2) Graphical tool for searching by
  • name
  • content
  • owner/group
  • size
  • modification time
End of Unit13
1) Questions and Answers
2) Summary:
  • Use locate to quickly find files that are not new
  • Use find to search based on very specific criteria and optionally run commands on matching files
  • Use the Gnome Search Tool for an intuitive, but powerful GUI search tool

你可能感兴趣的:(processing,Files,休闲,rhce,Finding)