Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux command find     - Port Telnet command to detect the remote host is turned on (Linux)

- To install and deploy Apache under the CentOS (Server)

- User rights management system under Linux (Linux)

- Getting Started with Linux system to learn: how to check in a package is installed on Ubuntu (Linux)

- How to install Bugzilla 4.4 on Ubuntu / CentOS 6.x (Linux)

- Ubuntu 14.04 install AMD graphics driver is fully dual monitor solution (Linux)

- Java interface (Programming)

- Go powerful development server simple example (Server)

- How to become a better Node.js developers in 2016 (Programming)

- Installation and configuration of Hadoop under Linux (Server)

- Ubuntu 14.10 PPA installed Android Studio (Linux)

- awk pattern matching (Programming)

- ORA-28000 the account is locked fault simulation (Database)

- Java reflection mechanism explained in detail and Method.invoke explanation (Programming)

- Visual Studio Code experience (Linux)

- How to configure Ceph stored on CentOS 7.0 (Server)

- HTTPS Encryption Algorithm (Linux)

- Four Methods of Self - Learning Linux (Linux)

- Linux operating system set up to effectively prevent ARP attacks (Linux)

- Repair after installing Ubuntu no boot device error (Linux)

 
         
  Linux command find
     
  Add Date : 2018-11-21      
         
       
         
  Overview: When using a file system in Linux, there is often a need to find this file. So how in accordance with our needs to find the appropriate file. Here I recommend two commands, locate and find commands command. Cipian Bowen mainly to introduce the find command usage.

So why do not talk about the find and locate commands? Here, I need to explain the working mechanism of these two commands.

A, locate command mechanism

In linux system in advance to build a good database for file index to locate the query to meet the user needs to find files. This database is automatically maintained and updated by a Linux system. So this is not a real-time look, for example, when you use the process created a new document, and worked for a while you forget that this document specifically where lying, you want to find this file, then you need to find, if locate to find it, when the database is not updated in real time. Of course, you can also use the updatedb command to manually update the database system, but the cost of updating the database is relatively large, the system will increase consumption. At this point, we recommend to find another command --find command.

Two, find the command mechanism

find command is a Linux system in a real-time tool to find the file, which is specified by the user to traverse the path starting at the file system hierarchy to find the complete file, which you specify to find all files and subdirectories under the directory files.

Three operating characteristics, find command

1. Find a slightly slower.

2, precise search.

3, real-time search.

Four, find command usage

Using the format: find [OPTIONS] [Find Start Path] [search condition] [processing operation]

Find start path: Specify the starting destination specific search path; defaults to the current directory.

Search Terms: user-specified search criteria (expression), such as the file name of the file, size, type, slave

Relations, authority, etc; if not specified, to find all the files in the current directory.

Actions: to meet the search criteria to make operations such as delete and other processing operations; if not specified, the default is lost

Out to the standard output.

Search Terms specification:

Expression: options and test

1, the test: The result is Boolean ( "true", "false")

(1) based on the file name to find:

Options:

-name "pattern": pattern matching is based on the file name to find out.

-iname "pattern": pattern matching is based on the file name to find out. Ignore character large

lower case.

Note: This pattern (pattern) is based on the globbing style bash to find.

-regex "pattern": based on regular expression pattern to find the file, matching the entire path

Instead of a file name.

(2) to find files based on affiliation

Options:

-user USERNAME: Find files belonging to the specified user

-group GROUPNAME: Find files belonging to the specified user group

-uid UID: find the owner of all files specified UID

-gid GID: Find the specified GID is a group of all files

-nouser: Finding no owner files

-nogroup: Finding no document is set

Note: After being deleted for a particular user, the user's files belonging to the genus will become free

Lord, no is a group of files, the file belonging to the previous user ID and group ID for this user.

(3) according to the type of file to find.

Options:

-type TYPE:

f: regular file

d: directory file

l: symbolic link file

b: block device file

c: character device file

p: pipe file

s: socket file

(4) According to locate the file size

Options:

-size [+ | -] NUMBER default unit in bytes

[+ | -] NUMBER K

[+ | -] NUMBER M

[+ | -] NUMBER G

Note: + means greater than - less than represented, said no precise

Note: 1, precise means (NUMER-1, NUMBER] range, than it can not be too small, not larger than it.

2 - greater than the range [0, # - 1], ie, it is smaller than the size of 1 or less.

3, the range is greater than .

(5) based on timestamp Find:

Options:

In "day" as a unit, rewind to the last time.

-atime [+ | -] NUMBER: access time

NUMBER (exact time): [NUMBER, NUMBER-1]

-NUMBER (Recently NUMBER days): (NUMBER, 0)

+ NUMBER (more than NUMBER days): (oo, NUMBER-1)

-mtime [+ | -] NUMBER: Modified (file contents)

-ctime [+ | -] NUMBER: change the time (metadata)

In "minutes" for the unit: (and the similar)

-amin [+ | -] NUMBER

-mmin [+ | -] NUMBER

-cmin [+ | -] NUMBER

For example: Find / etc directory within the last week its contents modified files

~] # Find / etc / -mtime -7

(6) under the authority of Find

Options:

-perm [/ | -] mode

mode: Exact Match permissions:

-mode: All users (u, g, o) the permission of each and every (r, w,

x) that is qualified to meet the search criteria, the "and" between 9 permissions.

/ Mode: any of a class of users (u, g, o) the authority in any one of (r, w,

x) compliance with the conditions is met (9 have to comply with a) 9 authority is "or" relationship.

For example: 1, Find / etc / directory, for at least one class of user has permission to execute the file.

~] # Find / etc / -perm / 111

2. Find /etc/init.d directory, all users have execute permissions and other users

Write access to common files.

~] # Find /etc/init.d/ -perm -113 -type f

~] # Find /etc/init.d/ -perm -222 -a -perm 002 -type f

2. The composition test:

And (and): - a, default logical combination of a plurality of conditions

Or (or): - o

Non-: -not

For example: 1, Find / etc directory more than a week of its contents have been modified, and the file size does not exceed 5M.

~] # Find / etc / -mtime -7 -a -not -size -5M

2. Find / etc directory of all users do not have write access to common files.

Ideas: reverse lookup problem means there is at least one type of user has write access;

~] # Find / etc / -not -perm / 222 -type f

3, Find / etc directory there is at least one class of users do not have write access to common files.

Ideas: Reverse resolve problems means that all users have write access

~] # Find / etc / -not -perm -222 -type f

Actions:

-print: to standard output, the default action

-ls: details "ls -l" command, the output file is similar to the implementation of the lookup file

-delete: Delete files found

-file file path: Save the long form information to find all the files to the specified file;

-ok COMMAND {} \;: Run by the COMMAND represented on to find every file; each operation had

Confirmation by the user;

-exec COMMAND {} \;: to find every file Run by the COMMAND represented.

Note: find the file path passed to find the back of the commands transmitted to achieve find all the matching files path

Diameter, and a pass to the back of the command; but some commands can not accept long arguments, then the command will be executed

Failure; Another way to avoid this problem:

~] # Find | xargs COMMAND

Summary: Find a combination of numerous options and conditions find command can better serve the needs of users to find the file services, but depending on the size and scope of the time stamp component requires a deep understanding of file size, in order to find you meet you document demand. Also understand the permissions section is also very important, it is easy for beginners around the halo, it is recommended to view the file permissions related to the underlying content. Let you use the Linux find command to become a weapon.
     
         
       
         
  More:      
 
- IOS interview questions Summary (Programming)
- JITwatch installation under Linux (Linux)
- Redis Design and Implementation study notes (Database)
- MySQL monitoring tool -Innotop (Database)
- Ubuntu install Tonido private cloud services (Server)
- Detailed PHP code optimization [section] (explain reasons) (Programming)
- Linux systems for entry-learning: Install closed-source packages in Debian (Linux)
- Install and configure GO 1.2.1 under CentOS 6.5 (Linux)
- CUDA (including GPU card driver) installation process under Ubuntu (Linux)
- How to enhance the security of Linux systems (Linux)
- Linux Network Statistics Tools / Command (Linux)
- Fedora 22 install Adobe Flash Player (Linux)
- These days have been tossing in the Linux under the ASP.NET 5, on the next in the other operating systems in the ASP.NET 5 or. NET applications, in order to complete the MS VM (CoreCLR) run is not far Reach, the effect of the application.

Cur
(Server)
- JBPM6 Tutorial - taught you how to install JBPM (Linux)
- Linux automatically install service components and optimize the kernel parameters (Linux)
- Learning C language pointer essays (Programming)
- Android project and coding specifications (Programming)
- C ++ Object Model Comments (Programming)
- MYSQL root password for the database user passwords are weak attack analysis (Linux)
- Ubuntu under VirtualBox virtual machine serial port settings (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.