Find command and Stat command

Source: Internet
Author: User

A. Find command

1.find command Options

-name finds files by file name.

-perm to find files according to file permissions.

-prune Use this option to have the Find command not be found in the currently specified directory, and if you use the-depth option at the same time,-prune will be ignored by the Find command.

-user Search for files according to the owner of the file.

-group finds files according to the group to which the files belong.

-mtime-n +n The file changes time to find the file,-n means that the file change time is now less than n days, + n means that the file change time is now N days ago. The Find command also has the-atime and-ctime options, but they both and the-m time option.

-nogroup finds a file that does not have a valid owning group, that is, the group to which the file belongs does not exist in/etc/groups.

-nouser finds a file without a valid owner, that is, the owner of the file does not exist in the/etc/passwd.

-newer file1! File2 look for a file that changes time than the file File1 new but older than the file file2.

-type find files of a certain type, such as: B-block device files. D-Directory. C-character device file. P-Pipeline file. L-Symbolic link file. F-Normal file.

-size N:[c] finds files with a file length of n blocks, with C indicating the length of the file in bytes.

-depth: When looking for a file, first find the file in the current directory, and then look in its subdirectories.

-fstype: Find files located in a file system of a certain type, these file system types can usually be found in the configuration file/etc/fstab, which contains information about the file system in this system.

-mount: Does not cross the file system mount point when locating files.

-follow: If the find command encounters a symbolic link file, it tracks to the file that the link points to.

-cpio: Use the cpio command for matching files to back up these files to the tape device.

In addition, the following three differences:

-amin N Find the last n minutes of files accessed in the system

-atime N Find the last n*24 hour Access file in the system

-cmin n Find files in the last n minutes of the system changed file status

-ctime n Find files that have changed file status in the last n*24 hours of the system

-mmin n Find files that have changed file data in the last N minutes of the system

-mtime n Find files that have changed file data for the last n*24 hours in the system

Ii. examples of the Find command;

1. Find all files under the current user's home directory: The following two methods are available

$ find $HOME-print

$ find ~-print

2, let the current directory of the file owner has read, write permissions, and the file belongs to the group of users and other users have Read permission files;

$ find. -type f-perm 644-exec ls-l {} \;

3, in order to find all the files in the system file length of 0 ordinary files, and list their full path;

$ find/-type f-size 0-exec ls-l {} \;

4. Look for common files in the/var/logs directory that were changed before 7th, and ask them before deleting them;

$ find/var/logs-type f-mtime +7-ok rm {} \;

5, in order to find all the files belonging to the root group in the system;

$find. -group root-exec ls-l {} \;

-rw-r--r--1 root root 595 October 01:09./fie1

6. The Find command will delete the Admin.log file that contains the digital suffix since the access time in the directory was 7th.

This command checks only three digits, so the suffix of the corresponding file should not exceed 999. Build several admin.log* files before using this command

$ find. -name "admin.log[0-9][0-9][0-9]"-atime-7-ok

RM {} \;

< RM .... /admin.log001 >? N

< RM .... /admin.log002 >? N

< RM .... /admin.log042 >? N

< RM .... /admin.log942 >? N

7, in order to find all the directories in the current file system and sorting;

$ find. -type D | Sort

8, in order to find all the RMT tape devices in the system;

$ find/dev/rmt-print


Two. 3 time-point resolution when viewing files with stat command in Liunx

Okay, we'll use the Stat command to view the file details, as follows:

[Email protected] ~]$ stat Text.1

File: ' Text.1 '

size:0 blocks:0 IO block:4096 Regular empty file

device:802h/2050dinode:658326 links:1

Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)

Access: 2016-05-16 04:03:55.110083994-0700

Modify: 2016-05-09 06:23:19.741054978-0700

Change: 2016-05-09 06:23:19.741054978-0700

There will be 3 types of time, namely Access,modify,change. We will explain these 3 times in detail below.

Access time: Indicates when we last visited (only access, no changes) files

Modify Time: Indicates when we last modified the file

Change Time: Indicates the date when we last changed the properties of a file, including permissions, size, attributes, and so on.


What is the difference between 3 people?

1, when we just read the file, access time changes, and Modify,change does not change

2, Access,modify,change time will change when the file is modified

3, when the file attributes are modified, change time changes, while access,modify is unchanged.



This article is from the "10755228" blog, please be sure to keep this source http://superguo.blog.51cto.com/10755228/1782047

Find command and Stat command

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.