![]() ![]() ![]() ) with to not expand search than the first subdirectory by mentioning there should be no slashes after the filename. Here the *\/ referees to the files that do not contain any back slashes which eliminates the possibility of finding files in the current directory.Īnd in the end, I've replaced period (. Seems too complex right? Let me break it down for you. So I'll be using the same naming pattern F to find files in the subdirectory: find. The above example only applied to the current directory and did not show some files that followed the same naming pattern. \/ was used to look for files in the current directory and F will show us file names starting from Fo and Fr.īut what if you want to execute some commands/programs over the given result? This can be done using the find command with exec: Here, the -type f was used to search for files. Search Files based on Initial Characters in the Current DirectoryĬurrently, my file system looks like this:Īnd I want to search for files that start with Fo or Fr so my command will be: find. I am going to start with the most common scenario where a user only knows the first few characters of a file and wants to know where it is. Practical Examples of find command with regex Now it's time for me to share some examples of how you can use find with regex. regular_expression is where you will be using tokens to express the file pattern you are looking for.Now, Let's have a look at the basic syntax of using find with regex: find -regex Means ad will get you aed, azd but not abd or acd. Generally, it is sued to specify the starting point of search but can also be used to negate the content when used inside the square brackets. This means ad will match abd or acd, but not the abcd. It will get a positive result of any character used in a string inside the square brackets. So the ca*t will find get you ct, cat, caat etc. This means the preceding character can be found 0 or more times. It eliminates the effect of special characters such as the (.) will indicate to period effect but when used a.b it will only search for strings as a.b So a.b will match strings such as acb, aeb and abb but won't match accb or ab It gets you a match for any character once (except a new line). So let's have a look at some of the most basic and widely used tokens which I'll be using with the find command: Token Tokens are nothing but special characters to search for specified patterns. You can enable the beast mode in the find command by using regular expression (regex) for searching.īut before jumping to the examples part, it is crucial to know some basic regex tokens and syntax. The find command is a powerhouse for searching files based on a number of criteria. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |