How can I list only specific files with 'ls' in bash?

I was wondering how can I list files with lsin bash that will list only a specific subset of files?

For example, I have a folder with 10,000 files, some of which are called: temp_cc1_covmatand temp_cc1_slurm, but the values ​​1 vary from 1 to 1000.

So, how would I list only the words temp_cc400_slurm- temp_cc_499_slurm?

I want to do this because I would like to queue files on a supercomputer that only ends with slurm. I could have done sbatch *_slurm, but there are also many other files ending up in the folder _slurm.

+4
source share
2 answers

Brace Expansion bash:

temp_cc{400..499}_slurm

, :

echo temp_cc{400..499}_slurm

printf "%s\n" temp_cc{400..499}_slurm

ls:

ls temp_cc{400..499}_slurm
+3

?:

$ ls temp_cc4??_slurm

man 7 glob:

Wildcard matching
   A  string  is  a  wildcard pattern if it contains one of the characters
   '?', '*' or '['.  Globbing is the operation  that  expands  a  wildcard
   pattern  into  the list of pathnames matching the pattern.  Matching is
   defined by:

   A '?' (not between brackets) matches any single character.

?. ls test?????, , ls test[12]????? . (, ls temp_cc4[0-9][0-9]_slurm.)

+1

Source: https://habr.com/ru/post/1681813/


All Articles