KandZ – Tuts

We like to help…!

Linux CLI HowTo 5 🐧 How to Guides for Wildcards

5 – How-to Guides for Wildcards

1. How to List all text files in current directory

ls *.txt
  • Matches any filename ending with .txt
  • Lists all files with txt extension

2. How to Find files with pattern “a” in second position

ls ?a?.txt
  • Matches any filename with exactly 3 characters, second being ‘a’, ending with .txt
  • Shows 3-character filenames where middle character is ‘a’

3. How to Find files starting with a, b, or c

ls [abc]*
  • Matches any filename starting with a, b, or c
  • Lists all files beginning with either a, b, or c

4. How to Match specific numbered files

ls file{1,2,3}.txt
  • Matches file1.txt, file2.txt, or file3.txt exactly
  • Shows only three specific numbered files

5. How to Find files with numbers 1 or 2

ls file{1,2}.txt
  • Matches file1.txt or file2.txt exactly
  • Lists two specific numbered files

6. How to Find alphanumeric filenames

ls [[:alnum:]]*
  • Matches any filename starting with alphanumeric character
  • Shows all files beginning with letters or numbers

7. How to Find non-letter filenames

ls [![:alpha:]]*
  • Matches any filename NOT starting with letter
  • Lists files beginning with numbers, symbols, etc.

8. How to How to Find lowercase or ending with 2

ls *[[:lower:]2]
  • Matches any filename ending with lowercase letter OR digit 2
  • Shows files ending with lowercase letters or the number 2

9. How to Find files ending with 2 or 3

ls *[23].txt
  • Matches any filename ending with 2 or 3 followed by .txt
  • Lists files ending with either 2 or 3 and txt extension

10. How to List all files with single character name

ls ?.*
  • Matches any filename with exactly one character followed by dot
  • Shows all hidden files with single-character names

11. How to Find files with specific pattern

ls [a-z]*
  • Matches any filename starting with lowercase letter
  • Lists all files beginning with a through z

12. How to Match uppercase letter files

ls [[:upper:]]*
  • Matches any filename starting with uppercase letter
  • Shows all files beginning with capital letters

13. How to Find files with digits at start

ls [[:digit:]]*
  • Matches any filename starting with digit
  • Lists all files beginning with numbers

14. How to Create backup files pattern

ls *~.*
  • Matches any filename ending with tilde followed by dot and extension
  • Shows temporary/backup files

15. How to Find files with specific character set

ls [a-zA-Z0-9]*
  • Matches any filename starting with alphanumeric character
  • Lists all files beginning with letters or numbers

16. How to Show files with special characters

ls [![:alnum:]]*
  • Matches any filename NOT starting with letter or number
  • Shows files beginning with symbols, spaces, etc.

17. How to Find files with specific ending pattern

ls *[^0-9]*
  • Matches any filename NOT ending with digit
  • Lists files that don’t end with numbers

18. How to Match multiple extensions

ls *.{txt,doc,pdf}
  • Matches files with txt, doc, or pdf extension
  • Shows files with three specific extensions

19. How to Find all hidden files

ls .*[^.]*
  • Matches any filename starting with dot (hidden files)
  • Lists all hidden files in directory

20. How to Show files with exact pattern

ls [[:alpha:]][[:digit:]]*
  • Matches filename starting with letter followed by digit
  • Shows files beginning with letter then number

21. How to Find files with specific extensions

ls *.{jpg,png,gif}
  • Matches jpg, png, or gif files
  • Lists image files with three extensions

22. How to Match specific range of letters

ls [a-c]*
  • Matches any filename starting with a, b, or c
  • Shows all files beginning with those three letters

23. How to Find files with multiple character classes

ls [[:upper:][:digit:]]*
  • Matches any filename starting with uppercase letter OR digit
  • Lists files beginning with capital letters or numbers

24. How to Show files with special characters at end

ls *[![:alnum:]]
  • Matches any filename ending with non-alphanumeric character
  • Shows files that end with symbols or punctuation

25. How to Find files in specific pattern range

ls [A-Z][a-z]*
  • Matches any filename starting with capital letter followed by lowercase
  • Lists files beginning with uppercase letter then lowercase letters

26. How to Match files with hex digits

ls [[:xdigit:]]*
  • Matches any filename starting with hexadecimal digit
  • Shows files beginning with 0-9, a-f, or A-F characters

27. How to Find files with space or tab

ls [[:blank:]]*
  • Matches any filename starting with space or tab character
  • Lists files beginning with whitespace characters

28. How to Show files ending with specific pattern

ls *[0-9][a-z]
  • Matches any filename ending with digit followed by lowercase letter
  • Shows files that end with a number then letters

29. How to Find files with exact character sequence

ls f[[:lower:]]*[[:upper:]]
  • Matches any filename starting with ‘f’ followed by lowercase letters and ending with uppercase letter
  • Lists files beginning with ‘f’ and ending with capital letters

30. How to Match files with multiple criteria

ls [[:digit:]]*[[:alpha:]]*[[:digit:]]
  • Matches any filename starting with digit, containing letters, ending with digit
  • Shows files that begin and end with numbers with letters in between

Leave a Reply