skip to Main Content

I want to list all the files having e as the nth character in their name in the current directory.

I tried this, but it’s not working:

find -regextype posix-egrep -regex '^./[e]{5}.txt$'

2

Answers


  1. want to list all the files having e as the nth character in their name in the current directory.

    You may use:

    find . -maxdepth 1 -regextype posix-egrep -regex '^./.{4}e.*'
    

    Regex breakdown:

    • ^: Start
    • ./: Match ./
    • .{4}: Match any 4 characters
    • e: Match letter e
    • .*: Match any text
    • -maxdepth 1 finds entries in current directory only

    Or using print and glob:

    printf '%sn' ????e*
    

    Here:

    • ????: Match any 4 characters
    • e: Match e
    • *: Match any text
    Login or Signup to reply.
  2. Why don’t you just use the standard wildcard stuff from bash? As in an example where you want e as the fourth character:

    pax.diablo@ubuntu:/home/pax.diablo/test_dir> ls -1d ???e*
    ragemix
    Makefile
    

    That’ll expand to any file (in the widest sense of the word) in the current directory starting with three characters followed by an e.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search