How can I recursively find all files in current and subfolders based on wildcard matching?
相关问题
- How to get the return code of a shell script in lu
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Invoking Mirth Connect CLI with Powershell script
- Error building gcc 4.8.3 from source: libstdc++.so
fd
In case,
find
is too slow, tryfd
utility - a simple and fast alternative tofind
written in Rust.Syntax:
Demo:
Homepage: https://github.com/sharkdp/fd
If your shell supports a new globbing option (can be enabled by:
shopt -s globstar
), you can use:to find any files or folders recursively. This is supported by Bash 4, zsh and similar shells.
Personally I've got this shell function defined:
Note: Above line can be pasted directly to shell or added into your user's
~/.bashrc
file.Then I can look for any files by typing:
Alternatively you can use a
fd
utility with a simple syntax, e.g.fd pattern
.In a few cases, I have needed the -L parameter to handle symbolic directory links. By default symbolic links are ignored. In those cases it was quite confusing as I would change directory to a sub-directory and see the file matching the pattern but find would not return the filename. Using -L solves that issue. The symbolic link options for find are -P -L -H
Default way to search for recursive file, and available in most cases is
It starts recursive traversing for filename or pattern from within current directory where you are positioned. With find command, you can use wildcards, and various switches, to see full list of options, type
or if man pages aren't available at your system
However, there are more modern and faster tools then find, which are traversing your whole filesystem and indexing your files, one such common tool is locate or slocate/mlocate, you should check manual of your OS on how to install it, and once it's installed it needs to initiate database, if install script don't do it for you, it can be done manually by typing
And, to use it to look for some particular file type
Or, to look for filename or patter from within current directory, you can type:
It will look through its database of files and quickly print out path names that match pattern that you have typed. To see full list of locate's options, type:
locate --help
orman locate
Additionally you can configure locate to update it's database on scheduled times via cron job, so sample cron which updates db at 1AM would look like:
These cron jobs need to be configured by root, since updatedb needs root privilege to traverse whole filesystem.
In the wildcard-match you can provide the string you wish to match e.g. *.c (for all c files)
You can use:
If you want use REGX use
-iname