Let's say that I need to filter all my files' names that don't include special characters.
ASDA123fasf - would pass
asasdasd*dasd - wouldn't pass
Let's say that I need to filter all my files' names that don't include special characters.
ASDA123fasf - would pass
asasdasd*dasd - wouldn't pass
One of many alternatives would be find . -maxdepth 1 -iregex '.*/[a-z0-9.]*' -ls
If you think you may need to use this often, you could even create an alias to shorten the command:
Note: The below alias will only work in the current directory, although you could easily create a script that would parse a command line argument for the directory..
alias myls="find . -maxdepth 1 -iregex '.*/[a-z0-9.]*' -ls"
If you were to do that, every time you issued the command myls
you'd get the desired output without all the extra typing. Lazy or efficient, you decide.
Sources: Byte Commander comment here
https://stackoverflow.com/questions/4509624/how-to-limit-depth-for-recursive-file-list - specifically this answer
man find
find FOLDER/ -iregex '.*/[a-z0-9.]*'
. Note the beginning.*/
in the pattern, because-iregex
matches against the whole path, not just the file name, and also that I added a.
tot he allowed characters inside the square brackets, so that it still will match files with extensions. You might want to remove that one depending on your goals. The match is case-insensitive. – Byte Commander May 19 '18 at 18:49ls
and I want to get only names of the folders with letters and digits.ASAS23123fasf
would pass,123123fasf
would pass aswell butasdads&*!@213
shouldn't pass – Anthino Russo May 19 '18 at 19:01find
. The output ofls
is meant for human eyes and not to be parsed. While you could theoretically tape something together likels | grep -i '[a-z0-9.]*'
, that would be bad practice and not reliable for some cases. – Byte Commander May 19 '18 at 19:07shopt -s extglob
- although it should be enabled by default)ls *([[:alnum:]])
will list files whose names are alphanumeric – steeldriver May 19 '18 at 19:10