How can I find all folders starting with a value in the number range 500 to 899? I just need to list them in a file.
- Maxdepth 2
- Examples of folder names:
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
try this (if your
find supports the
find parent_dir -maxdepth 2 -type d \( -name '[5-8][0-9][0-9][!0-9]*' -o -name '[5-8][0-9][0-9]' \) > my_file1.txt
zsh, assuming the numbers are always decimal integers (in the range supported natively by your processor):
setopt extended_glob dirs=(<500-899>([^0-9]*|)(/N) */<500-899>([^0-9]*|)(/DN))
However note that for the second pattern, if there are symlinks to directories in the current directory,
zsh will look for
<500-899>... directory in their target.
Shortened with brace expansion factorisation:
If the numbers are always followed by
_, you can simplify it to:
Note with versions of
zsh prior to 5.2, because of the way integers are represented by the processor, that will match numbers that are between 500 and 899 modulo 264, so for instance would match on
590295810358705652224_something as that's 269 + 512.