I have a list of files with numeric file names (e.g. #.php, ##.php or ###.php) that I'd like to copy/move in one fell swoop.
Does anyone know of an ls
or grep
combo command to accomplish this objective?
I do have this much:
ls -al | grep "[0-9].php"
Amend it like this:
ls -al | grep -E '^[0-9]+\.php$'
-E
activates the extended regular expressions.
+
requires that at least one occurrence of the preceding group must appear.
\.
escape dot otherwise it means "any character."
^
and $
to match the entire filename and not only a part.
Single quotes to prevent variable expansion (it would complain because of the $
).
In Bash, you can use extended pattern matching:
shopt -s extglob
ls -l +([0-9]).php
which will find files such as:
123.php
9.php
but not
a.php
2b.php
c3.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With