Back to Blog
Linux find file by name6/23/2023 ![]() If you want to find a file or directory named NEWS.txt inside the /usr directory, use the -name switch like so: find /usr -name NEWS.txt In this section, we will learn how to filter items by their name. and simply use: find Finding items by their nameĪs we mentioned previously, you can filter the results of the find command using expressions. When there are no paths, the find command assumes that it should work with the current directory. If you want to list the contents of the current working directory, use a period(. If you want to list the contents of multiple directories, you can do this like so: find /usr/share /bin /usr/lib Depending upon the contents of the directory, this list can be very large! This will give you a list of files and directories, as shown in the screenshot below. For example, if you want to list the contents of the /usr/share directory, run: find /usr/share Imagine that you want to list all the directories and files for a given path. These concepts will become clearer as we go through various examples mentioned later in this article. However, you can also specify a custom action that the find command can take on the results. The default action is to print all the results. If you want to filter some of them out based on certain criteria, you can specify an expression to do so. This process continues till it has searched for all items inside the path you specified.īy default, the find command finds everything inside a directory. Again, if there are other directories inside, the find command will look inside them as well. Thus, when the find command encounters a directory inside the given path, it looks for other files and directories inside it. The find command takes a number of paths, and searches for files and directories in each path “recursively”. The basic structure of the find command is like so: find We will also illustrate its usage through various examples throughout this article. In this article, we will understand how to work with the find command. Optionally, it also allows you to take different types of actions on the results. It is highly flexible, allowing you to look for files and directories based on a variety of conditions. It is part of the “findutils” package and comes bundled with all distributions. The find command allows users to search for files and take actions on them.
0 Comments
Read More
Leave a Reply. |