

Similarly, here is an example to search for pdf and. For the name option, you can specify the file extension name formats using wildcard characters. If you want to find specific types of files such as pdf files, you can use -name option in your find command as shown below. If you use only -print option, it will not work with files with spaces & special characters. We use -print0 option to display all filenames even if it includes spaces and other special characters. In the following code, you can fill the part between do…done with code to work with files. We use the output of above command in a for loop to iterate through these files and work with them. The above command will display a list of all relative file paths. We also use -type f to specify that we want to search for only files and not folders. You can specify another directory if you want to search in another folder. In the above command we use dot(.) to specify that we want to find files in our present working directory. Here is the command to find all files in your present working directory. You can use these steps on almost every shell in Linux.īash Loop Through Files in Directory Recursivelyįind is one of the best commands to find files that satisfy specific criteria.
#Linux find file recursive how to
In this article, we will learn how to loop through files in directory recursively in Linux. Often you may need to loop through files in directory recursively, in terminal or shell script.
