06_linux Directory File Operations Command 3 Find commands _ my Linux path

Source: Internet
Author: User
Tags svn

The last few sections have been roughly told about some of the commands on the Linux side file directory operation

This essay, we continue to learn the operation of the file directory command

A command to find a file or directory

Find files in the find specified directory
Find (options) (parameters)

The find command can be used to find a file in a specific directory, by default it needs to be followed by a lookup path, and if no path is added, the Find command finds subdirectories and files in the current directory

Then display the file or directory you are looking for.

His options are as follows

-amin< minutes;: Finds files or directories that have been accessed at a specified time, in minutes;-anewer< reference files or directories;: Finds access times closer to the current file or directory than the specified file or directory;-atime< 24 hours number;: Finds files or directories that have been accessed at a specified time, and the unit calculates;-cmin< minutes in 24 hours;: Find files or directories that have been changed at the specified time;-cnewer< reference files or directories > Find the change time of the specified file or directory is closer to the current file or directory;-ctime<24: finds the file or directory that was changed at the specified time, measured in 24 hours;-daystart: Calculates the time from the current day -depth: Starting from the deepest subdirectory of the specified directory;-expty: Looking for a file size of 0 byte, or an empty directory without any subdirectories or files in the directory;-exec< execution instruction;: Assuming the return value of the Find command is true, execute the instruction -false: Sets the callback value of the Find command to the false;-fls< list file; the effect of this parameter is similar to specifying the "-ls" parameter, but saves the result as a specified list file;-follow: Exclude Symbolic Connection;-fprint< list file The effect of this parameter is similar to specifying the "-print" parameter, but will save the result to the specified list file;-fprint0< list file;: The effect of this parameter is similar to specifying the "-print0" parameter, but saves the result to the specified list file ;-fprintf< list file >< output format: The effect of this parameter is similar to specifying the "-printf" parameter, but saves the result to the specified list file;-fstype< file system type > : only search for files or directories under the file system type;-gid< group identification code;: Find a file or directory that matches the specified group ID;-group< group name;: Find a file or directory that matches the name of the specified group;-help or--help: Online Help ;-ilname< template style;: The effect of this parameter is similar to specifying the "-lname" parameter, but ignores the difference in the case of the character;-iname< template style; the effect of this parameter is similar to specifying the "-name" parameter, but ignores the difference in case of the character -inum<inode;: Find a file or directory that conforms to the specified inode number;-ipath< template style;:The effect of this parameter is similar to specifying the "-path" parameter, but ignores the difference in the case of the character;-iregex< the template style; the effect of this parameter is similar to specifying the "-regexe" parameter, but ignores the difference in the case of characters;-links< number of connections > : Finds files or directories that match the specified number of hard connections;-iname< template style;: Specifies a string as a template style for finding symbolic joins;-ls: If the return value of the Find directive is ture, the file or directory name is listed to the standard output;-maxdepth< Directory level: Set the maximum directory level;-mindepth< directory hierarchy;: Set the minimum directory level;-mmin< minutes;: Finds files or directories that have been changed at a specified time, measured in minutes;-mount: Effect of this parameter and specify "- Xdev "Same,-mtime<24 hours;: Finds files or directories that have been changed at a specified time, the unit calculates the;-name< template style in 24 hours;: Specifies a string as a template style for finding a file or directory;-newer< Refer to a file or directory;: Find its change time more closely to the current file or directory than the specified file or directory;-nogroup: Find the file or directory that does not belong to the local landlord cluster identification code;-NOLEAF: Do not consider the directory must have at least two hard connections exist -nouser: Find a file or directory that does not belong to the local host user identification code;-ok< execution instructions; the effect of this parameter is similar to specifying "-exec", but the user is asked before the instruction is executed, and if "Y" or "Y" is answered, the execution of the command is discarded;-path< Template style;: Specifies a string as the template style for the search directory;-perm< permission value;: Finds a file or directory that matches the specified number of permissions;-print: If the return value of the Find directive is ture, the file or directory name is listed to standard output. The format is a name for each column, with a "./" string before each name;-print0: If the return value of the Find directive is ture, the file or directory name is listed to standard output. All names are in the same line;-printf< output format;: Assuming the return value of the Find directive is ture, the file or directory name is listed to standard output. The format can be specified by itself;-prune: Do not look for a string as a template to find a file or directory style;-regex< template style;: Specify a string as the template style for finding a file or directory;-size< file size;: Find files that match the specified file size ;-true: Will findThe return value of the instruction is set to true;-typ< file type;: Only find files that match the specified file type;-uid< user identification code;: Find files or directories that match the specified user ID;-used< number of days > : Finds files or directories that have been accessed at a specified time after a file or directory has been changed, and the unit calculates the;-user< owner name by day;: A file or directory with the specified owner name;-version or--version: Display version information -xdev: Confine the scope to the first file system;-xtype< file type;: The effect of this parameter is similar to specifying the "-type" parameter, except that it checks for symbolic connections.

For reference or search only

We're going to do this later.

First we match the file based on the filename name or regular expression

List all files and folders under the current directory for all subdirectories

Find.

/homefind filenames ending in. txt under directory

Find/home-name "*.txt"

Ditto, but ignores case

Find/home-iname "*.txt"

Find all files ending in. txt and. pdf under the current directory and subdirectories

Match file path or file

find/usr/-path "*local*"

Matching file paths based on regular expressions

Find. -regex ". *\ (\.txt\|\.pdf\) $"

Ditto, but ignores case

Find. -iregex ". *\ (\.txt\|\.pdf\) $"

Of course we can also use the Deny parameter

Find files that are not ending with. txt under/home

Find/home! -name "*.txt"

We can also find files in depth based on file type

Types have the following kinds of

    • F Common Files
    • l Symbolic connection
    • Catalog D
    • C -character device
    • b -block equipment
    • s socket
    • P Fifo

The command is as follows

Find. -type type parameter

We can also search based on directory depth

Down maximum depth limit is 3

Find. -maxdepth 3-type F

Search for all files with a depth distance of at least 2 subdirectories in the current directory

Find. -mindepth 2-type F

Of course there are other types of options that I don't explain here.

If you are interested, try it.

Locate finding a file or directory
Locate/slocate (option) (parameter)

The ocate command is actually  -name another form of find, but much faster than the latter because it does not search for a specific directory, but instead searches for a database /var/lib/locatedb that contains all the local file information. The Linux system automatically creates this database and updates it automatically every day, so you can't find the latest changed files using the Locate command.

You can solve this problem by manually updating the database

UpdateDB

The options for the Locate command are as follows

-d< directory > or--database=< directory;: Specify the directory where the database resides;-u: Update slocate database;--help: Display Help;--version: Displays version information.

Familiarity with commands through several examples

Search all files in the ETC directory that begin with SH:

Locate/etc/sh

Searches all files that begin with M in the user's home directory, and ignores the case:

Locate-i ~/m

Whereis Locating paths
Whereis (option) (parameter)

the path of the whereis command used to locate instructions for the binaries, source code files, and man manual pages, and other related files

Options are as follows

-B: Find only binary files;-b< directory;: Find binaries only in the directory you set;-F: The path name before the file name is not displayed;-M: Only find the description file;-m< directory;: Find the description file only in the directory of the settings;-S: Find only the original code file ;-s< directory > Find the original code file only in the directory under Settings;-U: Finds files that do not contain the specified type.

The Whereis lookup is very fast compared to the Find command, because the Linux system records all the files in the system in a database file, and when you use Whereis and the locate described below, the data is looked up from the database, not like the Find command. By traversing the hard drive to find, the efficiency will naturally be very high

Let's do the actual combat command.

[[email protected] ~]# whereis tomcattomcat:[[email protected] ~]# whereis SVNSVN:/usr/bin/svn/usr/local/svn/usr/share /man/man1/svn.1.gz

At the beginning we looked for Tomcat, because I did not install it, so here does not show

And svn I installed, so I found a lot of related files

Of course, we can just show the binary files.

[Email protected] ~]# whereis-b SVNSVN:/usr/bin/svn/usr/local/svn[[email protected] ~]# whereis-m SVNSVN:/usr/share/ Man/man1/svn.1.gz[[email protected] ~]# whereis-s SVNSVN:

Other options are not a demonstration, Linux is to real combat in order to really learn

which the absolute path of the Find command
which (option) (parameter)

The which command is used to find and display the absolute path of a given command, and the environment variable path holds the directory that needs to be traversed when the find command is saved. The which directive looks for eligible files in the directory where the environment variable $path is set. That is, using the which command, you can see whether a system command exists, and which command is executed at which location.

The options are as follows

-n< filename Length: The length of the file name, the length specified must be greater than or equal to the longest file name in all files;-p< filename length;: The same as the-n parameter, but here the < filename length > contains the path to the file ;-W: Specifies the width of the field at the output;-V: Displays version information.

Here are some examples to familiarize yourself with this command

[email protected] ~]# which pwd/bin/pwd[[email protected] ~]#  which adduser/usr/sbin/adduser

My blog site www.susmote.com

06_linux Directory File Operations Command 3 Find commands _ my Linux path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.