In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use the find command in Linux system. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Everything in the Linux system is a file, so you can find a file quickly by using the find file command find
How to use the Linux system command find:
Find command format:
Find path-option [- print] [- exec-ok | xargs | grep] [command {}\;]
The parameters of the find command:
1) path: the directory path to find.
~ represents the $HOME directory. Indicates the current directory / represents the root directory 2) print: means to output the result to standard output.
3) exec: execute the shell command given by this parameter on the matching file. The form is command {}\;, notice that there is a space between {} and\;
4) ok: it works the same as exec, except that a prompt is given to the user to confirm whether to execute the command before executing the command.
5) | xargs plays the same role as exec, so it plays an important role.
The difference is that | xargs is mainly used to undertake deletion operations, while-exec can be used such as copy, move, rename, etc.
6) options: indicates the search method
The following options are commonly used in options:
-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 # look up files by file access time,-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
-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]
-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
-prune # ignore a directory
Here are some simple examples to introduce the general use of find:
1. Look up by name
In the current directory and subdirectories, look for the uppercase txt file $find. -name'[Amurz] * .txt'- print in / etc and its subdirectories, look for files at the beginning of host $find / etc-name 'host*'-print in the $HOME directory and its subdirectories, look for all files $find ~-name' *'- print in the current directory and subdirectories, look for txt files that do not start with out $find. -name "out*"-prune-o-name "* .txt"-print2, search by directory
Search for the txt file $find in the current directory except aa. -path ". / aa"-prune-o-name "* .txt"-print looks for the txt file $find in the current directory and subdirectories other than aa and bb. − path'./dir0' − o − path'./dir1' − path'./dir0' − o − path'./dir1'-a-prune-o-name'* .txt'- print Note: you need to add spaces at places 1 and 2, otherwise an error will appear as shown in the figure.
You can find the txt file $find in the current directory, no longer in the subdirectory, with or without adding-an in 3 places. !-name "."-type d-prune-o-type f-name "* .txt"-print or find. -name * .txt-type f-print links: find command in Linux-path-prune usage details
3. Search by permission
In the current directory and subdirectories, look for the file $find that the owner has read-write execution and other read-execute permissions. -perm 755-print looks for files or directories for which the user has write permission or the group user has write permission find. /-perm / 220 find. /-perm / upriwjournal gendarmerw find. /-perm / uwrigsigw4, search by type (b/d/c/p/l/f)
In the current directory and subdirectories, look for the symbolic link file $find. -type l-print5, by owner and group
Find the file whose owner is www $find /-user www-type f-print find the file deleted by the owner $find /-nouser-type f-print find the file in the group mysql $find /-group mysql-type f-print find the deleted file in the user group $find /-nogroup-type f-print6, search by time
Find the file $find that has been changed in 2 days. -mtime-2-type f-print look for the file $find that was changed 2 days ago. -mtime + 2-type f-print to find the file that was accessed within a day $find. -atime-1-type f-print finds the file $find that was accessed a day ago. -atime + 1-type f-print to find files whose status has been changed within a day $find. -ctime-1-type f-print finds the file $find whose status was changed a day ago. -ctime + 1-type f-print looks for files whose state was changed 10 minutes ago $find. -cmin + 10-type f-print7, old and new by file
Find the file $find newer than aa.txt. -newer "aa.txt"-type f-print looks for a file older than aa.txt $find. !-newer "aa.txt"-type f-print looks for files that are newer than aa.txt and older than bb.txt $find. -newer 'aa.txt'!-newer' bb.txt'-type f-print8, search by size
Find files over 1m $find /-size + 1m-type f-print find files equal to 6 bytes $find. -size 6c-print looks for files less than 32k $find. -size-32k-print9, execute command
1) find del.txt and delete it, and prompt to confirm $find before deletion. -name 'del.txt'-ok rm {}\; 2) find aa.txt and back it up as aa.txt.bak $find. -name 'aa.txt'-exec cp {} {}. Bak\; 3) check all the ordinary files in the current directory # find. -type f-exec ls-l {}\;-rw-r 1 root root 34928 2003-02-25. / conf/httpd.conf
-rw-r 1 root root 12959 2003-02-25. / conf/magic
-rw-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-exec option to list them
4) look for files with a change time before 5 days in the / logs directory and delete them $find logs-type f-mtime + 5-exec-ok rm {}\
5) query the files modified on the same day
Find. /-mtime-1-type f-exec ls-l {}\; 6) query the file and ask if you want to display
# find. /-mtime-1-type f-ok ls-l {}\;? Y-rw-r-r- 1 cnscn cnscn 13709 January 12 12:22. / classDB.inc.php # find. /-mtime-1-type f-ok ls-l {}\;? N about whether there is a difference between-print
Add-print
Find the directory and list the files under the directory (execute the ls command separately for each directory found, and the directory name will not be displayed on the first line of the file list without the option-print) find / home-type d-print-exec ls {}\
No-print
On the Linux system what is the use of find commands to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.