I know **/*.ext
expands to all files in all subdirectories matching *.ext
, but what is a similar expansion that includes all such files in the current directory as well?
相关问题
- How to get the return code of a shell script in lu
- JQ: Select when attribute value exists in a bash a
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- bash print whole line after splitting line with if
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- Check if directory exists on remote machine with s
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- Can NOT List directory including space using Perl
You can use:
**/*.*
to include all files recursively (enable by:shopt -s globstar
).Please find below testing of other variations and how they behave.
Testing folder with 3472 files in the sample VLC repository folder:
(Total files of 3472 counted as per:
find . -type f | wc -l
)ls -1 **/*.*
- returns 3338ls -1 {,**/}*.*
- returns 3341 (as proposed by Dennis)ls -1 {,**/}*
- returns 8265ls -1 **/*
- returns 7817, except hidden files (as proposed by Dennis)ls -1 **/{.[^.],}*
- returns 7869 (as proposed by Dennis)ls -1 {,**/}.?*
- returns 15855ls -1 {,**/}.*
- returns 20321So I think the most closest method to list all files recursively is the first example (
**/*.*
) as per gniourf-gniourf comment (assuming the files have the proper extensions, or use the specific one), as the second example gives few more duplicates like below:and the other generate even further duplicates.
To include hidden files, use:
shopt -s dotglob
(disable byshopt -u dotglob
). It's not recommended, because it can affect commands such asmv
orrm
and you can remove accidentally the wrong files.That will list all of the files in the current directory. You can then do some other command on the output using -exec
That will grep each file from the find for the string "foo".
This wil print all files in the current directory and its subdirectories which end in '.ext'.
This will work in Bash 4:
In order for the double-asterisk glob to work, the
globstar
option needs to be set (default: on):From
man bash
:Why not just use brace expansion to include the current directory as well?
Brace expansion happens before glob expansion, so you can effectively do what you want with older versions of bash, and can forego monkeying with globstar in newer versions.
Also, it's considered good practice in bash to include the leading
./
in your glob patterns.