How to ls files that start with numbers
Hello All,
I want wondering if I can ls files that start with numbers only in a folder. Suppose: 001.txt 302.txt dsadf.txt defa.txt 648.txt wqre.txt I want to execuste: ls "something" and get... 001.txt 302.txt 648.txt Thanks! |
ls [0-9]*
|
ls | grep '^[0-9]'
This and catkin's both screen for 1 digit at the beginning of the line. You can modify them to specify other patterns / criteria |
Okay I've got to say/ask something here. The OP said files that start with numbers only. So I'm wondering if he got the right answer. Let's assume I want to list files with only numbers, none with letters too. How would I do that? Pixellany, I can't get your command to work with Fedora.
|
ls | grep -E '^[0-9]+\.' # find files starting with at least 1 digit and have only digits before the first decimal point (.)
ls | grep -E '^[0-9]+' # find files starting with at least 1 digit |
Pixellany, I apologize. I had forgotten to negate the alias I have set for ls - ls --color=always - with the backslash.
\ls | grep '^[0-9]' works. Thanks. I have been researching the same sort of information so I want to say thanks also to the OP for starting this thread. |
A list of files with names comprising only numbers may be generated by bash itself using bash' Filename Expansion, Pattern Matching if extended globbing is enabled. The list can be used as arguments to any command including echo and ls:
Code:
shopt -s extglob |
Thank you all. To continue the conversation, I have a list:
pbs_1 pbs_2 pbs_3 . . . pbs_20 pbs_21 pbs_23 . . . pbs_51 . . . How do I ls (probably using globbing) only those files that start at pbs_job_20 and go all the way to pbs_job_29 ? If I do ls pbs_job_2* then I'll also get pbs_job_2.XX which is not needed. Thanks in advance, Rodrigo |
lol...I will reply to myself (for future readers)...
The answer should be: ls pbs_[2-9*]*[2-9]* (so two [] [] in the ls argument) |
Firstly, reopening such an old thread is not really the right way to go about this, you should simply open a new question.
As to your solution, you might want to check it again, currently it will also find the following file: Code:
pbs_222555888 |
All times are GMT -5. The time now is 01:53 AM. |