In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how linux through the find command to find things, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Select the starting point
With find, you can choose a starting point or start from where you are. To select the starting point of the search, enter it after the word find. For example, find / usr or find. / bin will start the search in the / usr directory or the bin directory in the current location, while find ~ will start the search in your home directory, even if you are currently in another location in the current file system.
Choose what you are looking for
One of the most common search strategies is to search for files by name. This requires the use of the-name option.
By default, find displays the full path to the found file. If you add-print to the command, you will see the same result. If you want to see details related to the file-such as the length of the file, permissions, etc., you need to add the-ls parameter to the end of your find command.
$find ~ / bin-name tryme/home/shs/bin/tryme$ find ~ / bin-name tryme-print/home/shs/bin/tryme$ find ~ / bin-name tryme-ls 917528 4-rwx- 1 shs shs 139 Apr 8 2019 / home/shs/bin/tryme
You can also use substrings to find files. For example, if you replace tryme in the above example with try*, you will find all files whose names begin with try. (LCTT translation note: if you want to use the wildcard *, please enclose the search string in single or double quotation marks to prevent the wildcard from being interpreted by shell.)
Finding files by name is probably the most typical use of the find command, but there are many other ways to find files, and there is a need to do so. The following sections show how to use other available ways.
In addition, when searching for files by file size, group, Inode, etc., you need to make sure that the file you find matches the file you are looking for. It is useful to use the-ls option to display details.
Find files by size
Finding files by size requires the-size option and a little trickery with the appropriate specification. For example, if you specify-size 189b, you will find 189 block-sized files instead of 189 bytes. (LCTT translation note: if you do not follow the unit, the default unit is b. A block is 512 bytes in size, less than or exactly 512 bytes will occupy a block. For bytes, you need to use-- size 189c (characters). And, if you specify-- size 200w, you will find 200 "word word" files-words in "double-byte increments" instead of "things we talk about each other". You can also find files by providing sizes in kilobytes (k), megabytes (M), and gigabytes (G). (LCTT translation note: even T, P)
In most cases, Linux users search for files that are larger than the selected size. For example, to find files greater than 1 gigabyte, you can use this command, where + 1G means "greater than 1 gigabyte":
$find-size + 1G-ls 2 > / dev/null 787715 1053976-rw-rw-r-- 1 shs shs 1079263432 Dec 21 2018. / backup.zip 801834 1052556-rw-rw-r-- 1 shs shs 1077809525 Dec 21 2018. / 2019/hold.zip finds files by index node number
You can find files through the index nodes that maintain file metadata (that is, everything except file contents and file names).
$find-inum 919674-ls 2 > / dev/null 919674 4-rw-rw-r-- 1 shs shs 512 Dec 27 15:25. / bin/my.log finds files with specific file owners or groups
Finding files by owner or group is also very simple. Here we use sudo to solve the permission problem.
$sudo find / home-user nemo-name "* .png"-ls 1705219 4 drwxr-xr-x 2 nemo nemo 4096 Jan 28 08:50 / home/nemo/Pictures/me.png
In the following command, we look for a file owned by a multi-user group called admins.
# find / tmp-group admins-ls 262199 4-rwxr-x--- 1 dory admins 27 Feb 16 18:57 / tmp/testscript find files without owners or groups
You can use the-nouser option shown in the following command to find files that do not belong to any user on the current system.
# find / tmp-nouser-ls262204 4-rwx- 1 1016 1016 17 Feb 17 16:42 / tmp/hello
Notice that the list shows the UID and GID of the old user, which clearly indicates that the user is not defined on the system. This command looks for files created outside the home directory by a user whose account has been deleted from the system, or files created in a home directory that has not been deleted after the user account has been deleted. Similarly, the-nogroup option will find such files, especially if these users are the only members of the related group.
Find files by last update
In this command, we look for files that have been updated in the past 24 hours in the home directory of a specific user. Sudo is used to search the home directory of another user.
$sudo find / home/nemo-mtime-1/home/nemo/home/nemo/snap/cheat/home/nemo/tryme finds the file according to the time when the permission was last changed
The-ctime option can help you find files whose status (such as permissions) has changed within a certain reference time range. The following is an example of finding files whose permissions changed on the last day:
$find. -ctime-1-ls 787987 4-rwxr-xr-x 1 shs shs 189 Feb 11 07:31. / tryme
Keep in mind that the date and time displayed only reflect the last update to the contents of the file. You need to use commands like stat to view the three states associated with the file (file creation, modification, and state change).
Find the file by the time it was last visited
In this command, we use the-atime option to find the local pdf files that have been accessed in the past two days.
$find-name "* .pdf"-atime-2./Wingding_Invites.pdf finds a file based on its time relative to another file
You can use the-newer option to find files that are newer than other files.
$find. -newer dig1-ls 786434 68 drwxr-xr-x 67 shs shs 69632 Feb 16 19:05. 1064442 4 drwxr-xr-x 5 shs shs 4096 Feb 16 11:06. / snap/cheat 791846 4-rw-rw-r-- 1 shs shs 649 Feb 13 14:26. / dig
There is no corresponding-older option, but you can use!-newer (that is, older) to get similar results, they are basically the same.
Find files by type
To find a file by file type, you have many options-regular files, directories, block and character files, and so on. The following is a list of file type options:
B block special file (buffered) c character special file (unbuffered) d directory p named pipe (FIFO) f regular file l symbolic link s socket
Here is an example of looking for symbolic links:
$find. -type l-ls 805717 0 lrwxrwxrwx 1 shs shs 11 Apr 10 2019. / volcano-> volcano.pdf 918552 0 lrwxrwxrwx 1 shs shs 1 Jun 16 2018. / letter-> pers/letter2mom limits the depth of search
The-mindepth and-maxdepth options control the depth of the search in the file system (starting from the current location or starting point).
$find-maxdepth 3-name "* loop". / bin/save/oldloop./bin/long-loop./private/loop to find an empty file
In this command, we look for empty files, but do not enter the directory and its subdirectories.
$find. -maxdepth 2-empty-type f-ls 917517 0-rw-rw-r-- 1 shs shs 0 Sep 23 11:00. / complaints/newfile 792050 0-rw-rw-r-- 1 shs shs 0 Oct 4 19:02. / junk finds files by permission
You can use the-perm option to find files with a specific permission set. In the following example, we only look for regular files (- type f) to avoid seeing symbolic links, which are granted this permission by default, even if the files they reference are restricted.
Find-perm 777-type f-lsfind:'. / .dbus': Permission denied 798748 4-rwxrwxrwx 1 shs shs 15 Mar 28 2019. / runme use search to help you delete files
You can use the find command to locate and delete files if you use the following command:
$find. -name runme-exec rm {}\
{} represents the name of each file found according to the search criteria.
A very useful option is to replace-exec with-ok. When you do this, find will ask for confirmation before deleting any files.
$find. -name runme-ok rm-rf {}\
< rm ... ./bin/runme >?
Deleting files is not the only thing-ok and-exec can do for you. For example, you can copy, rename, or move files.
The above is all the contents of the article "how to find things through the find command by linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.