Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux command find     - Linux system network security tools sudo Introduction (Linux)

- Linux kernel programming parameter passing between modules and function calls (Programming)

- Thunderbird 24.4.2 has been released for use with PPA updates (Linux)

- Oracle View Object Information (Database)

- Under CentOS using yum command to install the Task Scheduler crontab (Linux)

- Simple Linux file system - df, du, ln (Linux)

- mysqldump issue a note (Database)

- Android development environment to build under Fedora 13 (Linux)

- Flow control message transmission between RAC (Database)

- CentOS7 method to upgrade the kernel to 3.18 (Linux)

- Ubuntu 12.04 installation NVIDIA GTX750 graphics driver (Linux)

- What is a logical partition management LVM, how to use in Ubuntu (Linux)

- Security: set limits on password (Linux)

- Linux start the process (Linux)

- Achieve camera preview by ffplay (Linux)

- PHP with FastCGI and mod_php Comments (Server)

- Linux kernel source code analysis (Linux)

- How to install and use the Snort in Ubuntu 15.04 (Linux)

- FFmpeg compiled with only H264 decoding library (Programming)

- ORA-00845: MEMORY_TARGET not supported on this system Problem (Database)

 
         
  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:      
 
- CentOS 6.5 installation and simple configuration Nginx (Server)
- Fedora 22 Server how to upgrade to Fedora 23 Beta Server (Linux)
- iSCSI + multipath achieve DM multipath storage (Server)
- ORA-00020: No more process state objects available (Database)
- Oracle 12C RAC optimizer_adaptive_features cause of data into overtime (Database)
- Using Python multithreaded mistakes summary (Programming)
- How to forcibly change the Linux system password on a regular basis (Linux)
- Build and verify MongoDB3.0.7 version (shard + replica) Cluster (Database)
- MongoDB 3.2 Cluster Setup (Database)
- MariaDB 10.1 and MySQL 5.7 in general performance on commodity hardware (Database)
- BGP routers want to play it by CentOS (Linux)
- Linux shell script to adjust the Task Scheduler (Linux)
- Linux hard drive failure Case Studies (Linux)
- 11 examples in Linux df command (Linux)
- C # using the HttpClient Note: Preheat the long connection (Programming)
- Red Flag Linux Desktop 6.0 hard disk installation guide (Programming)
- JavaScript file loader LABjs API Explanation (Programming)
- Nginx multi-domain certificate HTTPS (Server)
- Spring AOP custom annotation way to achieve log management (Programming)
- CentOS 6.x and CentOS7 installation RPMforge (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.