cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 153 Views

Listing Files

What command will allow me to list all flienames
that meet ONLY the following criteria:

-  The length of the filename is 6 characters
-  The 2nd character of each filename is a digit (i.e. number)
-  The last character of each filename is an uppercase or 
       lowercase vowel

 

 

Trevor "Red Hat Evangelist" Chandler
Labels (3)
4 Replies
Chetan_Tiwary_
Community Manager
Community Manager
  • 125 Views

@Trevor Let's see if this serves successfully at your service :

Chetan_Tiwary__0-1740598529286.png

posix-extended refers to POSIX Extended Regular Expressions (ERE). ERE provides a richer set of metacharacters and features compared to POSIX Basic Regular Expressions (BRE). https://en.wikibooks.org/wiki/Regular_Expressions/POSIX-Extended_Regular_Expressions

./  That's just to make sure we're looking in the current folder.
. Means any single character can be here.
[0-9] This spot has to be a number, from 0 to 9.
.... Followed by any four characters.
[aeiouAEIOU] And the filename has to end with a vowel, either uppercase or lowercase.
Then, -printf '%f\n' is just telling find to give us the filenames nice and clean, without all the extra path info. Just the names, one per line

TM
Flight Engineer Flight Engineer
Flight Engineer
  • 106 Views

I distinguish listing from finding.

So I go with ls command, instead of find.

ls ?[0-9]???[AaEeIiOoUuYy]

Trevor
Starfighter Starfighter
Starfighter
  • 47 Views

I like it TM!

 

Trevor "Red Hat Evangelist" Chandler
Trevor
Starfighter Starfighter
Starfighter
  • 47 Views

This is a RHCA (Red Hat Chetan Achievement) level
response!!!

And of course, it gets the job done!!!!

Trevor "Red Hat Evangelist" Chandler
Join the discussion
You must log in to join this conversation.