RH033 Unit13 Finding and Processing Files
2009-03-31 22:47
337 查看
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 –r ‘\.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 –name snow.png Search for files named snow.png
2) find –iname snow.png Case-insensitive search for files named snow.png.
3) find –user joe –group 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 –o and –not 3) Parentheses can be used to determine logic order, but must be escaped in bash. find –user joe –not –group joe
find –user joe –o –user jane
find –not \(-user joe –o –user jane \)
find and Permissions 1) Can match ownership by name or id find / –user joe –o –uid 500
2) Can match octal or symbolic permissions find –perm 755 matches if mode is exactly 755
find –perm +222 matches if anyone can write
find –perm –222 matches if everyone can write
find –perm –002 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 – 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 –size 1024k (Files with a size of exactly 1 megabyte) 3) find –size +1024k (Files with a size over 1 megabyte) 4) find –size –1024k (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 –ctime 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 –exec or –ok (-ok prompts before acting on each file)
2) Command must end with space\; 3) Can use {} as a filename placeholder 4) find –size +1024k –ok gzip {} \; find Execution Examples 1) find –name “*.conf” –exec cp {} {}.orig \; Backup configuration files, adding a .orig extension
2) find /tmp –ctime +3 –user joe –ok rm {} \; Prompt to remove Joe’s tmp files that are over 3 days old
3) find ~ –perm +o+w –exec chmod o-w {} \; Fix other-writable files in your home directory
The Gnome Search Tool 1) Places –> 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
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 –r ‘\.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 –name snow.png Search for files named snow.png
2) find –iname snow.png Case-insensitive search for files named snow.png.
3) find –user joe –group 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 –o and –not 3) Parentheses can be used to determine logic order, but must be escaped in bash. find –user joe –not –group joe
find –user joe –o –user jane
find –not \(-user joe –o –user jane \)
find and Permissions 1) Can match ownership by name or id find / –user joe –o –uid 500
2) Can match octal or symbolic permissions find –perm 755 matches if mode is exactly 755
find –perm +222 matches if anyone can write
find –perm –222 matches if everyone can write
find –perm –002 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 – 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 –size 1024k (Files with a size of exactly 1 megabyte) 3) find –size +1024k (Files with a size over 1 megabyte) 4) find –size –1024k (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 –ctime 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 –exec or –ok (-ok prompts before acting on each file)
2) Command must end with space\; 3) Can use {} as a filename placeholder 4) find –size +1024k –ok gzip {} \; find Execution Examples 1) find –name “*.conf” –exec cp {} {}.orig \; Backup configuration files, adding a .orig extension
2) find /tmp –ctime +3 –user joe –ok rm {} \; Prompt to remove Joe’s tmp files that are over 3 days old
3) find ~ –perm +o+w –exec chmod o-w {} \; Fix other-writable files in your home directory
The Gnome Search Tool 1) Places –> 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
相关文章推荐
- RH033 Unit13 Finding and Processing Files
- Finding and Processing Files
- RH033 Unit 13 Finding and Processing Files
- running 5 Finding and Processing Files
- RH033读书笔记(12)-Lab 13 Finding and Processing Files
- Scrapy学习笔记九--Downloading and processing files and images
- Finding files on a *nix/Linux and sorting by size
- video processing on Mac and iOS
- xilinx 网站应用笔记 7 _Audio Video and Image Processing
- Android: Loading files from the Assets and Raw folders
- Package that speeds up loading of JavaScript, CSS and image files
- Use ASP.NET and DotNetZip to Create and Extract ZIP Files
- How to create and extract zip, tar, tar.gz and tar.bz2 files in Linux
- 图像处理中的全局优化技术(Global optimization techniques in image processing and computer vision) (一)
- PNG button (按钮) files with transparency, for Visual C++ 6.0 and VS2005
- Upload files in ASP.NET MVC with JavaScript and C#
- Topographic Laser Ranging and Scanning Principles and Processing翻译
- Unity3D Navmesh and Pathfinding
- Tutorial: Using roslaunch to start Gazebo, world files and URDF models
- image and video processing听课笔记(四)