Locating files using the find command(linux find命令)
2012-08-24 09:32
351 查看
Locating files using the find command
The find command is a powerful *nix utility that allows the user to find files located in the file system via criteria such as the file name, when file was last accessed, when the file status was last changed, the file's permissions, owner,group, size, or even number of inodes.
Examples
Find a file "foo.bar" that exists somewhere in the filesystem
$ find / -name foo.bar -print |
find searches recursively through all directories.
Find a file without searching network or mounted filesystems
$ find / -name foo.bar -print -xdev |
other versions of find.
Find a file without showing "Permission Denied" messages
$ find / -name foo.bar -print 2>/dev/null |
viewed.
Find a file, who's name ends with .bar, within the current directory and only search 2 directories deep
$ find . -name *.bar -maxdepth 2 -print |
Search directories "./dir1" and "./dir2" for a file "foo.bar"
$ find ./dir1 ./dir2 -name foo.bar -print |
Search for files that are owned by the user "joebob"
$ find /some/directory -user joebob -print |
Find a file that is a certain type. "-type l" searches for symbolic links
$ find /some/directory -type l -print |
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link
s socket
D door (Solaris)
Search for directories that contain the phrase "foo" but do not end in ".bar"
$ find . -name '*foo*' ! -name '*.bar' -type d -print |
The power of find
find becomes extremely useful when combined with other commands. One such combination would be usingfind and grep together.
$ find ~/documents -type f -name '*.txt' \ -exec grep -s DOGS {} \; -print |
grep command via the -exec option and grep searches the file found for any occurrences of the word "DOG". If the file is found it will be output to the screen and if the word "DOG" is found, within one of the found
files, the line that "DOG" occurs in will also be output to the screen.
The ordering of find's options are important for getting the expected results as well as for performance reason.
Visit
POWER TOOLS:A Very Valuable Find, by Jerry Peek, for creative ways to use
find and important tips about constructing the command's options.
转自:http://www.hypexr.org/linux_find_help.php
相关文章推荐
- rsync - find - perl - Which is the fastest method to delete files in Linux
- linux find命令使用 「25 simple examples of Linux find command」
- Centos下_MysqL5.7在使用mysqldump命令备份数据库报错:mysqldump: [Warning] Using a password on the command line interface can be insecure.
- Linux Command To Find the System Configuration And Hardware Information
- 10+ commonly using find command switches with example Unix/Linux
- Task could not find "AxImp.exe" using the SdkToolsPath "C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\"
- linux下运行telnet命令出现command not find解决办法
- linux终端错误:Unable to find the ncurses libraries or the required header files
- Using the command line to manage files on HDFS--转载
- 《The Linux Command Line》中的命令
- Linux / Unix Command: find命令
- 《The Linux Command Line》 读书笔记03 ls命令与长格式输出解释 文件权限
- [Linux] Search the contents of files using grep
- 《The Linux Command Line》 读书笔记04 Linux用户以及权限相关命令
- How to download files from the Linux command line
- ubuntu编译linux内核出现 Unable to find the ncurses libraries or the required header files.
- linux之Unable to find the ncurses libraries or the required header files.错误解决办法
- The Linux Command Line 读书笔记(二)之文件系统The file system操作的命令
- Find The Largest Top 10 Files and Directories on Linux
- Get and display the size of file and directory in Linux system using du command 获取和现实linux文件大小(三)