Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to use find in Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

What are the ways to use find in Linux? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Find path-option [- print] [- exec-ok command] {}\

Parameters of the find command

Pathname: the directory path that the find command looks for. For example, with. To represent the current directory and / to represent the system root directory.

The-print: find command outputs matching files to standard output.

The-exec: find command executes the shell command given by this parameter on the matching file. The corresponding command is in the form 'command' {}\;, notice the space between {} and\;.

-ok: the function is the same as-exec, except that the shell command given by this parameter is executed in a more secure mode, and before each command is executed, a prompt is given to the user to determine whether to execute it.

#-print outputs the found files to standard output

#-exec command {}\;-perform a command operation on the found file, with a space between {} and\;

#-ok and-exec are the same, except that the user should be asked before the operation

Example: find. -name .svn | xargs rm-rf

=

-name filename # find a file named filename

-perm # search by execute permission

-user username # search by file owner

-group groupname # find by group

-mtime-n + n # find files according to the time when the files are changed.-n refers to within n days, + n refers to n days ago.

-atime-n + n # check GIN: 0px "> by file access time

-ctime-n + n # find the file by the time it was created.-n refers to within n days, and + n refers to n days ago.

-nogroup # check that there is no valid group file, that is, the file group does not exist in / etc/groups

-nouser # check the file for which there is no valid owner, that is, the owner of the file is not saved in / etc/passwd

-newer F1! f2 look for files.-n refers to within n days, + n refers to n days ago.

-ctime-n + n # find the file by the time it was created.-n refers to within n days, and + n refers to n days ago.

-nogroup # check that there is no valid group file, that is, the file group does not exist in / etc/groups

-nouser # check the file for which there is no valid owner, that is, the owner of the file is not saved in / etc/passwd

-newer F1! f2 # check for files whose change time is newer than F1 but older than f2

-type b/d/c/p/l/f # check for block devices, directories, character devices, pipes, symbolic links, ordinary files

-size n [c] # look up files of length n blocks [or n bytes]

-depth # causes the lookup to find the local directory before entering the subdirectory

-fstype # check for files whose change time is newer than F1 but older than f2

-type b/d/c/p/l/f # check for block devices, directories, character devices, pipes, symbolic links, ordinary files

-size n [c] # look up files of length n blocks [or n bytes]

-depth # causes the lookup to find the local directory before entering the subdirectory

-fstype # look for files located in a certain type of file system, which can usually be found in / etc/fstab

-mount # do not cross the file system mount point when looking up files

-follow # if you encounter a symbolic link file, track the file that the link refers to

-cpio%; # look for files located in a certain type of file system, which can usually be found in / etc/fstab

-mount # do not cross the file system mount point when looking up files

-follow # if you encounter a symbolic link file, track the file that the link refers to

-cpio # uses the cpio command on matching files to back them up to the tape device

-prune # ignore a directory

=

$find ~-name "* .txt"-print # look up the .txt file in $HOME and display

$find. -name "* .txt"-print

$find. -name "[Amurz] *"-print # look for files that begin with uppercase letters

$find / etc-name "host*"-print # look for files that start with host

$find. -name "[a murz] [a Mel z] [0Mel 9] [0 Mel 9] .txt"-print # look for txt files that begin with two lowercase letters and two numbers

$find. -perm 755-print

$find. -perm-007-exec ls-l {}\; # check that all users can read and write the same files as-perm 777

$find. -type d-print

$find. !-type d-print

$find. -type l-print

$find. -size + 1000000c-print # look for files whose length is greater than 1Mb

$find. -size 100c-print # look up files with length 100c

$find. -size + 10-print # check for overexpired files with 10 blocks of invalid length (1 block = 512 bytes)

$cd /

$find etc home apps-depth-print | cpio-ivcdC65536-o / dev/rmt0

$find / etc-name "passwd*"-exec grep "cnscn" {}\; # to see if there is a cnscn user

$find. -name "yao*" | xargs file

$find. -name "yao*" | xargs echo "" > / tmp/core.log

$find. -name "yao*" | xargs chmod Omurw

=

Find-name april* looks for files starting with april in the current directory

Find-name april* fprint file looks for files starting with april in the current directory and outputs the results to file

Find-name ap*-o-name may* finds files that start with ap or may

Find / mnt-name tom.txt-ftype vfat looks for files with the name tom.txt and file system type vfat under / mnt

Find / mnt-name t.txt!-ftype vfat looks for files with the name tom.txt and file system type not vfat under / mnt

Find / tmp-name wa*-type l looks under / tmp for files whose name begins with wa and whose type is symbolic link

Find / home-mtime-2 check files that have been changed in the last two days under / home

Find / home-atime-1 check files that have been accessed within 1 day

Find / home-mmin + 60 check files that were changed 60 minutes ago under / home

Find / home-amin + 30 check files that have been accessed in the last 30 minutes

Find / home-newer tmp.txt looks under / home for files or directories that are updated more recently than tmp.txt

Find / home-anewer tmp.txt looks up files or directories with a shorter access time than tmp.txt under / home

Find / home-used-2 lists files or directories that have been accessed within 2 days after they have been changed

Find / home-user cnscn lists files or directories belonging to user cnscn in the / home directory

Find / home-uid + 501 lists the files or directories in the / home directory where the user's identification number is greater than 501

Find / home-group cnscn lists files or directories with group cnscn in / home

Find / home-gid 501lists files or directories with group id 501in / home

Find / home-nouser lists files or directories in / home that do not belong to local users

Find / home-nogroup lists files or directories within / home that do not belong to the local group

Find / home-name tmp.txt-maxdepth 4 list / home tmp.txt time check depth is up to 3 layers

Find / home-name tmp.txt-mindepth 3 starts from level 2.

Find / home-empty looks for files or empty directories of size 0

Find / home-size + 512k to check files larger than 512k

Find / home-size-512k check files less than 512k

Find / home-links + 2 check files or directories with more than 2 hard connections

Find / home-perm 0700 check files or directories with permissions of 700

Find / tmp-name tmp.txt-exec cat {}\

Find / tmp-name tmp.txt-ok rm {}\

Find /-amin-10 # finds the files accessed in the last 10 minutes of the system

Find /-atime-2 # finds the files accessed in the last 48 hours of the system

Find /-empty # looks for files or folders that are empty in the system

Find /-groupcat # finds files that belong to groupcat in the system

Find /-mmin-5 # finds files that have been modified in the last 5 minutes of the system

Find /-mtime-1 # finds files that have been modified in the last 24 hours of the system

Find /-nouser # finds files that belong to invalid users in the system

Find /-user fred # finds files that belong to the user FRED in the system

Check all the ordinary files in the current directory

# find. -type f-exec ls-l {}\

-rw-r-r- 1 root root 34928 2003-02-25. / conf/httpd.conf

-rw-r-r- 1 root root 12959 2003-02-25. / conf/magic

-rw-r-r- 1 root root 180 2003-02-25. / conf.d/README

Check all the ordinary files in the current directory and use the ls-l command in the-e x e c option to list them

1) look for all * .h in / tmp, look for "SYSCALL_VECTOR" in these files, and finally print out all the file names that contain "SYSCALL_VECTOR"

Linux-all, Linux | No Comments »

Find instance

To find all the * .h in / usr/linux, look for "SYSCALL_VECTOR" in these files, and finally print out all the file names that contain "SYSCALL_VECTOR", there are several ways to do this

Find / usr/linux-name "* .h" | xargs-n50 grep SYSCALL_VECTOR

Grep SYSCALL_VECTOR / usr/linux/*.h | cut-dazzlement'- F1 | uniq > filename

Find / usr/linux-name "* .h"-exec grep "SYSCALL_VECTOR" {}\;-print

I use find /-name filename | rm-rf. It is not successful. Why is it not successful?

Find /-name filename-exec rm-rf {}\

Find. -name filename | rm-rf try {} to indicate the result you found.

It is equivalent to the Constitution, without saying much, it is stipulated that a symbol indicating the end of the order is needed after-exec. The answer can be found in man find.

To get rm to recognize the result of find, it is as follows:

Find /-name filename | xargs rm-rf

The reason why find. -name filename | rm-rf failed because the rm command does not accept instructions from standard input

Find a file with a specific string

For example, find that the current directory contains "the string you want find..." File for string:

$find. -type f-exec grep "the string you want find..." {};-print

Check tmpfile from the root directory and delete it as soon as you find it.

Find /-name "tmpfile"-exec rm {}\

Perm problem of find

Excuse me, what does the following order mean? The key is that before that number-- everything else knows.

Find-name ". *"-perm-007

I know

Find-name ". *"-perm 755

This is used to find hidden files with permission bit 755.

Oh, by the way, my above command omitted the pathname parameter of find. Does find look up the current working directory by default?

If I use-ok instead of-exec, do I need to add {}\;?

This is clear and still needed, because-ok is just a prompt mode of-exec. It's just an extra step to confirm the operation. I didn't understand the meaning of those E sentences just now. I'm sorry.

-007 refers to finding files that all users can read, write and execute. Be careful.

Explain?

Is there any difference between find-name ". *"-perm-007 and find-name ". *"-perm 777?

-how did 007 come from?

But there's one problem.

I use find. -perm-100will list the current directory. Well, why is that?

Here is a quote from what explover published on 06:15am on 2002-10-01:

-007 refers to finding files that all users can read, write and execute. Be careful.

-007 is to find files that other users (different groups, non-owners) can read, write, and execute. You don't have to be able to read and write in the same group.-it means a minimum permission of 007.

Here is a quote from a Chinese cabbage published by 10:16am on 2002-10-01:

OK, hehe.

But there's one problem.

I use find. -perm-100will list the current directory. Well, why is that?

This method will not accurately find the directory. -100 means that permissions are at least runnable by the owner.

In unix system, you can have the right to execute directory files before you can enter a directory. This is why the catalog files are listed.

Find. -perm-001-print often finds catalog files.

Of course, I don't mean to use this method to find the catalog, but I just don't understand the meaning of-100.

And so on, does-010 mean that permissions are at least executable in the same group of owner? That is to say, in fact, 010 and-are separate,-which means at least one meaning, and 010 is really used to describe permission bits?

I see. Thank you. Oh.

Handcuff what find came out to another place?

Find * .c-exec cp'{}'/ tmp';'

If you have special files, you can use cpio, or you can use this syntax:

Find dir-name filename-print | cpio-pdv newdir

Find files within a certain size range on disk

For example, to find files larger than 3m on disk:

Find. -size + 3000k-exec ls-ld {}

How do I use find to find files that changed one day?

You can use this line of command to achieve:

A = `find ~-print` | ls-1-full-time $A2 > / dev/null | grep "Jun 27" | grep 1998

Use the find command to find out how to write shell for a certain period of time. For example from 11:00 to 12:00. Thanks

Create a script judgetime with the following contents:

Ls-l $* | awk'{split ($8 hour, ":"); if ((hour [1] > 23 | | hour [1] < 1) & & hour [1]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report