Find all files with a filename beginning with a specified string?

后端 未结 3 1161
忘了有多久
忘了有多久 2020-12-22 18:36

I have a directory with roughly 100000 files in it, and I want to perform some function on all files beginning with a specified string, which may match tens of thousands of

相关标签:
3条回答
  • 2020-12-22 19:12

    Use find with a wildcard:

    find . -name 'mystring*'
    
    0 讨论(0)
  • 2020-12-22 19:26

    If you want to restrict your search only to files you should consider to use -type f in your search

    try to use also -iname for case-insensitive search

    Example:

    find /path -iname 'yourstring*' -type f
    

    You could also perform some operations on results without pipe sign or xargs

    Example:

    Search for files and show their size in MB

    find /path -iname 'yourstring*' -type f -exec du -sm {} \;
    
    0 讨论(0)
  • 2020-12-22 19:27
    ls | grep "^abc"  
    

    will give you all files beginning (which is what the OP specifically required) with the substringabc.
    It operates only on the current directory whereas find operates recursively into sub folders.

    To use find for only files starting with your string try

    find . -name 'abc'*

    0 讨论(0)
提交回复
热议问题