Home > Enterprise >  List all files that have letter e as nth character in their name - Linux
List all files that have letter e as nth character in their name - Linux

Time:10-13

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$'

CodePudding user response:

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 '%s\n' ????e*

Here:

  • ????: Match any 4 characters
  • e: Match e
  • *: Match any text

CodePudding user response:

Why don't you just use the standard wildcard stuff from bash? As in:

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.

  • Related